説明なし

popup.spec.ts 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import Popup from '../src/popup';
  2. let interval;
  3. let window;
  4. let popup;
  5. describe('Popup', () => {
  6. beforeEach(angular.mock.inject(($interval, $window, $q) => {
  7. interval = $interval;
  8. window = $window;
  9. popup = new Popup($interval, $window, $q);
  10. }));
  11. it('should be defined', () => {
  12. expect(popup).toBeDefined();
  13. });
  14. it('should stringify popup options', () => {
  15. const options = { width: 481, height: 269 };
  16. const stringOptions = popup.stringifyOptions(options);
  17. expect(stringOptions).toBe('width=481,height=269');
  18. });
  19. it('should open a new popup', () => {
  20. spyOn(window, 'open');
  21. popup.open('about:blank', 'test', { width: 500, height: 500 });
  22. interval.flush(300);
  23. expect(window.open).toHaveBeenCalled();
  24. });
  25. it('should poll popup', () => {
  26. const open = popup.polling();
  27. interval.flush(300);
  28. expect(angular.isObject(open)).toBe(true);
  29. });
  30. it('should handle the case when popup redirect has occured', () => {
  31. popup.popup = {
  32. location: {
  33. host: document.location.host,
  34. search: '?code=foo_query',
  35. hash: '#code=foo_hash'
  36. }
  37. };
  38. const open = popup.polling();
  39. interval.flush(300);
  40. expect(angular.isObject(open)).toBe(true);
  41. });
  42. it('should handle the case when popup redirect has occured but no parameters are set', () => {
  43. popup.popup = {
  44. location: {
  45. host: document.location.host
  46. }
  47. };
  48. const open = popup.polling();
  49. let error = null;
  50. open.catch((err) => {
  51. error = err;
  52. });
  53. interval.flush(300);
  54. expect(error).toBeDefined();
  55. });
  56. it('should handle the case when popup is closed', () => {
  57. const open = popup.polling();
  58. let error = null;
  59. open.catch((err) => {
  60. error = err;
  61. });
  62. interval.flush(300);
  63. expect(error).toBeDefined();
  64. });
  65. });