@atlassian/atlassian-connect-js 5.3.190

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/.depcheckrc.json +16 -0
  2. package/.editorconfig +9 -0
  3. package/.envrc +5 -0
  4. package/.eslintignore +12 -0
  5. package/.eslintrc +31 -0
  6. package/.husky/pre-commit +11 -0
  7. package/.lintstagedrc.js +6 -0
  8. package/.netrc +1 -0
  9. package/.npmrc-public +4 -0
  10. package/.nvmrc +1 -0
  11. package/LICENSE +3 -0
  12. package/README.md +281 -0
  13. package/bitbucket-pipelines.yml +33 -0
  14. package/build/bin/bin-helper.js +29 -0
  15. package/build/bin/npm-postinstall.js +9 -0
  16. package/build/configs/append-sourcemapping.js +13 -0
  17. package/build/configs/availabletasks.js +15 -0
  18. package/build/configs/clean.js +12 -0
  19. package/build/configs/concat.js +44 -0
  20. package/build/configs/copy.js +32 -0
  21. package/build/configs/index.js +19 -0
  22. package/build/configs/jshint.js +9 -0
  23. package/build/configs/karma.js +11 -0
  24. package/build/configs/replace.js +10 -0
  25. package/build/configs/requirejs.js +187 -0
  26. package/build/configs/saucelabs-launchers.js +30 -0
  27. package/build/configs/shell.js +24 -0
  28. package/build/configs/uglify.js +15 -0
  29. package/build/configs/watch.js +45 -0
  30. package/build/end.frag +13 -0
  31. package/build/start.frag +18 -0
  32. package/bundlesize.config.json +14 -0
  33. package/dist/connect-host.css +225 -0
  34. package/dist/connect-host.js +13908 -0
  35. package/dist/connect-host.min.css +1 -0
  36. package/dist/iframe-fedramp.js +13663 -0
  37. package/dist/iframe.js +13663 -0
  38. package/dist/legacy-text-colors.css +245 -0
  39. package/dist/surfaces.css +11 -0
  40. package/dist/themes/atlaskit-tokens_dark-future.css +6 -0
  41. package/dist/themes/atlaskit-tokens_dark.css +394 -0
  42. package/dist/themes/atlaskit-tokens_legacy-dark.css +394 -0
  43. package/dist/themes/atlaskit-tokens_legacy-light.css +394 -0
  44. package/dist/themes/atlaskit-tokens_light-future.css +6 -0
  45. package/dist/themes/atlaskit-tokens_light.css +394 -0
  46. package/dist/themes/atlaskit-tokens_shape.css +14 -0
  47. package/dist/themes/atlaskit-tokens_spacing.css +26 -0
  48. package/dist/themes/atlaskit-tokens_typography-adg3.css +25 -0
  49. package/dist/themes/atlaskit-tokens_typography-modernized.css +25 -0
  50. package/dist/themes/atlaskit-tokens_typography-refreshed.css +25 -0
  51. package/gulpfile.js +204 -0
  52. package/memleak-check/app.html +10 -0
  53. package/memleak-check/index.html +31 -0
  54. package/memleak-check/index.js +33 -0
  55. package/package.json +102 -0
  56. package/renovate.json +11 -0
  57. package/security-assistant.yml +2 -0
  58. package/spec/.eslintrc +10 -0
  59. package/spec/config/karma.base.conf.js +200 -0
  60. package/spec/config/karma.conf.js +20 -0
  61. package/spec/fixtures/base_dialog_component_tests.js +180 -0
  62. package/spec/mocks/mock_feature_flag.js +23 -0
  63. package/spec/tests/amd_spec.js +122 -0
  64. package/spec/tests/analytics_dispatcher_spec.js +429 -0
  65. package/spec/tests/analytics_performance_spec.js +41 -0
  66. package/spec/tests/button_spec.js +143 -0
  67. package/spec/tests/dialog_extension_spec.js +59 -0
  68. package/spec/tests/dialog_module_provider_spec.js +499 -0
  69. package/spec/tests/dialog_module_spec.js +395 -0
  70. package/spec/tests/dialog_spec.js +296 -0
  71. package/spec/tests/dialog_webitem_spec.js +183 -0
  72. package/spec/tests/dropdown_module_spec.js +77 -0
  73. package/spec/tests/env_module_spec.js +153 -0
  74. package/spec/tests/events_spec.js +77 -0
  75. package/spec/tests/extension_configuration_options_store_spec.js +25 -0
  76. package/spec/tests/flag_module_provider_spec.js +79 -0
  77. package/spec/tests/flag_module_spec.js +118 -0
  78. package/spec/tests/flag_spec.js +243 -0
  79. package/spec/tests/host-api_spec.js +220 -0
  80. package/spec/tests/iframe-create_spec.js +43 -0
  81. package/spec/tests/iframe_container_spec.js +19 -0
  82. package/spec/tests/iframe_spec.js +265 -0
  83. package/spec/tests/inline_dialog_spec.js +41 -0
  84. package/spec/tests/inline_dialog_webitem_spec.js +331 -0
  85. package/spec/tests/loading_indicator_spec.js +48 -0
  86. package/spec/tests/messages_module_spec.js +108 -0
  87. package/spec/tests/meta_spec.js +71 -0
  88. package/spec/tests/module_args_spec.js +52 -0
  89. package/spec/tests/observe_spec.js +73 -0
  90. package/spec/tests/public_events.spec.js +102 -0
  91. package/spec/tests/scroll_position_spec.js +109 -0
  92. package/spec/tests/theming_spec.js +594 -0
  93. package/spec/tests/util_spec.js +55 -0
  94. package/spec/tests/utils/base64_spec.js +20 -0
  95. package/spec/tests/utils/button_spec.js +11 -0
  96. package/spec/tests/utils/cookie_spec.js +19 -0
  97. package/spec/tests/utils/deprecate_spec.js +22 -0
  98. package/spec/tests/utils/dialog_spec.js +297 -0
  99. package/spec/tests/utils/host_util_spec.js +45 -0
  100. package/spec/tests/utils/iframe_spec.js +41 -0
  101. package/spec/tests/utils/jwt_spec.js +135 -0
  102. package/spec/tests/utils/url_spec.js +37 -0
  103. package/spec/tests/utils/waitUntilReadyNextTick.js +5 -0
  104. package/spec/tests/utils/webitem.js +219 -0
  105. package/spec/tests/webitem_spec.js +131 -0
  106. package/src/css/host/dialog.css +144 -0
  107. package/src/css/host/flags.css +5 -0
  108. package/src/css/host/host.css +64 -0
  109. package/src/css/host/messages.css +12 -0
  110. package/src/css/plugin/legacy-text-colors.less +55 -0
  111. package/src/css/plugin/surfaces.css +11 -0
  112. package/src/host/ACJSFrameworkAdaptor.js +44 -0
  113. package/src/host/actions/analytics_action.js +35 -0
  114. package/src/host/actions/button_actions.js +21 -0
  115. package/src/host/actions/dialog_actions.js +27 -0
  116. package/src/host/actions/dialog_extension_actions.js +25 -0
  117. package/src/host/actions/dom_event_actions.js +32 -0
  118. package/src/host/actions/dropdown_actions.js +12 -0
  119. package/src/host/actions/env_actions.js +57 -0
  120. package/src/host/actions/event_actions.js +33 -0
  121. package/src/host/actions/flag_actions.js +22 -0
  122. package/src/host/actions/iframe_actions.js +27 -0
  123. package/src/host/actions/inline_dialog_actions.js +26 -0
  124. package/src/host/actions/inline_dialog_webitem_actions.js +10 -0
  125. package/src/host/actions/jwt_actions.js +51 -0
  126. package/src/host/actions/loading_indicator_actions.js +10 -0
  127. package/src/host/actions/module_actions.js +14 -0
  128. package/src/host/actions/webitem_actions.js +29 -0
  129. package/src/host/components/button.js +112 -0
  130. package/src/host/components/dialog.js +447 -0
  131. package/src/host/components/dialog_extension.js +106 -0
  132. package/src/host/components/dialog_webitem.js +69 -0
  133. package/src/host/components/flag.js +102 -0
  134. package/src/host/components/iframe.js +130 -0
  135. package/src/host/components/iframe_container.js +38 -0
  136. package/src/host/components/inline_dialog.js +108 -0
  137. package/src/host/components/inline_dialog_webitem.js +157 -0
  138. package/src/host/components/loading_indicator.js +110 -0
  139. package/src/host/components/webitem.js +227 -0
  140. package/src/host/deprecate.js +20 -0
  141. package/src/host/dispatchers/analytics_dispatcher.js +512 -0
  142. package/src/host/dispatchers/event_dispatcher.js +46 -0
  143. package/src/host/dollar.js +8 -0
  144. package/src/host/host-api.js +325 -0
  145. package/src/host/iframe-create.js +7 -0
  146. package/src/host/index.js +108 -0
  147. package/src/host/module-providers.js +13 -0
  148. package/src/host/modules/_featureFlag.js +42 -0
  149. package/src/host/modules/_performance.js +54 -0
  150. package/src/host/modules/analytics.js +17 -0
  151. package/src/host/modules/dialog.js +496 -0
  152. package/src/host/modules/dropdown.js +255 -0
  153. package/src/host/modules/env.js +156 -0
  154. package/src/host/modules/events.js +28 -0
  155. package/src/host/modules/flag.js +170 -0
  156. package/src/host/modules/host.js +19 -0
  157. package/src/host/modules/inline-dialog.js +33 -0
  158. package/src/host/modules/messages.js +309 -0
  159. package/src/host/modules/page.js +29 -0
  160. package/src/host/modules/scroll-position.js +102 -0
  161. package/src/host/modules/theming.js +114 -0
  162. package/src/host/stores/extension_configuration_options_store.js +24 -0
  163. package/src/host/util.js +98 -0
  164. package/src/host/utils/access-narrowing-context.js +18 -0
  165. package/src/host/utils/base64.js +22 -0
  166. package/src/host/utils/button.js +10 -0
  167. package/src/host/utils/cookie.js +14 -0
  168. package/src/host/utils/dialog.js +239 -0
  169. package/src/host/utils/feature-flag.js +27 -0
  170. package/src/host/utils/iframe.js +23 -0
  171. package/src/host/utils/jwt.js +60 -0
  172. package/src/host/utils/observe.js +34 -0
  173. package/src/host/utils/removal-observer.js +30 -0
  174. package/src/host/utils/simplexdm.js +58 -0
  175. package/src/host/utils/url.js +23 -0
  176. package/src/host/utils/webitem.js +214 -0
  177. package/src/plugin/amd.js +115 -0
  178. package/src/plugin/analytics.js +84 -0
  179. package/src/plugin/deprecate.js +16 -0
  180. package/src/plugin/dialog.js +197 -0
  181. package/src/plugin/dollar.js +77 -0
  182. package/src/plugin/events-instance.js +2 -0
  183. package/src/plugin/events.js +246 -0
  184. package/src/plugin/extension_configuration_options_store.js +27 -0
  185. package/src/plugin/featureFlag.js +8 -0
  186. package/src/plugin/index.js +118 -0
  187. package/src/plugin/meta.js +14 -0
  188. package/src/plugin/public-events.js +73 -0
  189. package/src/plugin/theming.js +211 -0
  190. package/src/plugin/util.js +104 -0
@@ -0,0 +1,395 @@
1
+ import DialogModule from 'src/host/modules/dialog';
2
+ import DialogComponent from 'src/host/components/dialog';
3
+ import DialogExtensionComponent from 'src/host/components/dialog_extension';
4
+ import EventActions from 'src/host/actions/event_actions';
5
+ import baseDialogComponentTests from 'fixtures/base_dialog_component_tests';
6
+ import IframeActions from 'src/host/actions/iframe_actions';
7
+ import EventDispatcher from 'src/host/dispatchers/event_dispatcher';
8
+
9
+ describe('Dialog module', () => {
10
+
11
+ afterEach(() => {
12
+ $('.aui-dialog2').remove();
13
+ $('.aui-blanket').remove();
14
+ });
15
+
16
+ it('defaults to chromeless', () => {
17
+ var options = {
18
+ key: 'anykey'
19
+ };
20
+ var callback = function(){};
21
+ callback._id = 'cbc123';
22
+ callback._context = {
23
+ extension: {
24
+ addon_key: 'some.addon_key',
25
+ key: 'some.different_module',
26
+ options: {}
27
+ }
28
+ };
29
+ new DialogModule.create.constructor(options, callback);
30
+ expect($('.aui-dialog2').hasClass('aui-dialog2-chromeless')).toEqual(true);
31
+ });
32
+
33
+ it('defaults to chrome in a dialogModule', () => {
34
+ window._AP = {
35
+ dialogModules: {
36
+ someaddon_key: {
37
+ dialogmodulekey: {
38
+ options: {}
39
+ }
40
+ }
41
+ }
42
+ }
43
+ var options = {
44
+ key: 'dialogmodulekey'
45
+ };
46
+ var callback = function(){};
47
+ callback._id = 'abdc123';
48
+ callback._context = {
49
+ extension: {
50
+ addon_key: 'someaddon_key',
51
+ key: 'some.different_module',
52
+ options: {}
53
+ }
54
+ };
55
+ new DialogModule.create.constructor(options, callback);
56
+ expect($('.aui-dialog2').hasClass('aui-dialog2-chromeless')).toEqual(false);
57
+ expect($('.aui-dialog2').hasClass('aui-dialog2')).toEqual(true);
58
+ });
59
+
60
+ it('renders a chromed dialog', () => {
61
+ var options = baseDialogComponentTests.getChromeOptions();
62
+ options.key = 'some.module_key';
63
+ var callback = function(){};
64
+ callback._id = 'abc123';
65
+ callback._context = {
66
+ extension: {
67
+ addon_key: 'some.addon_key',
68
+ key: 'some.different_module',
69
+ options: {}
70
+ }
71
+ };
72
+ new DialogModule.create.constructor(options, callback);
73
+ baseDialogComponentTests.testChrome(options);
74
+ });
75
+
76
+ it('renders a chromed dialog with productContext', (done) => {
77
+ var options = baseDialogComponentTests.getChromeOptions();
78
+ options.key = 'some.module_key';
79
+ var callback = function(){};
80
+ callback._id = 'abc123';
81
+ callback._context = {
82
+ extension: {
83
+ addon_key: 'some.addon_key',
84
+ key: 'some.different_module',
85
+ options: {
86
+ productContext: {
87
+ 'some': 'context'
88
+ }
89
+ }
90
+ }
91
+ };
92
+
93
+ EventDispatcher.registerOnce('dialog-extension-open', function(data){
94
+ expect(data.extension.options.productContext).toEqual(callback._context.extension.options.productContext);
95
+ done();
96
+ });
97
+ new DialogModule.create.constructor(options, callback);
98
+ });
99
+
100
+
101
+ it('renders a chromed dialog with dimensions', () => {
102
+ var options = baseDialogComponentTests.getChromeOptions();
103
+ delete options.size;
104
+ options.width = '123px';
105
+ options.height = '100px';
106
+ options.key = 'some.module_key';
107
+ var callback = function(){};
108
+ callback._id = 'abc123';
109
+ callback._context = {
110
+ extension: {
111
+ addon_key: 'some.addon_key',
112
+ key: 'some.different_module',
113
+ options: {}
114
+ }
115
+ };
116
+ new DialogModule.create.constructor(options, callback);
117
+ baseDialogComponentTests.testChrome(options);
118
+ });
119
+
120
+ it('renders a chromeless dialog', () => {
121
+ var options = baseDialogComponentTests.getChromelessOptions();
122
+ options.key = 'some.module_key';
123
+ var callback = function(){};
124
+ callback._id = 'abc123';
125
+ callback._context = {
126
+ extension: {
127
+ addon_key: 'some.addon_key',
128
+ key: 'some.different_module',
129
+ options: {}
130
+ }
131
+ };
132
+ new DialogModule.create.constructor(options, callback);
133
+ baseDialogComponentTests.testChromeless(options);
134
+ });
135
+
136
+ it('renders a chromeless dialog with dimensions', () => {
137
+ var options = baseDialogComponentTests.getChromelessOptions();
138
+ delete options.size;
139
+ options.width = '123px';
140
+ options.height = '100px';
141
+ options.key = 'some.module_key';
142
+ var callback = function(){};
143
+ callback._id = 'abc123';
144
+ callback._context = {
145
+ extension: {
146
+ addon_key: 'some.addon_key',
147
+ key: 'some.different_module',
148
+ options: {}
149
+ }
150
+ };
151
+ new DialogModule.create.constructor(options, callback);
152
+ baseDialogComponentTests.testChromeless(options);
153
+ });
154
+
155
+ it('closes on AP.dialog.close()', () => {
156
+ var extension = {
157
+ addon_key: 'some-key',
158
+ key: 'module-key',
159
+ url: 'http://www.example.com',
160
+ options: {
161
+ isDialog: true
162
+ }
163
+ };
164
+ var options = baseDialogComponentTests.getChromeOptions();
165
+ var $dialogExtension = DialogExtensionComponent.render(extension, options);
166
+ $dialogExtension.find('iframe')[0].bridgeEstablished = true;
167
+ var callback = function(){};
168
+ callback._context = {
169
+ extension: extension
170
+ };
171
+ expect($('.aui-dialog2').length).toEqual(1);
172
+ DialogModule.close(callback);
173
+ expect($('.aui-dialog2').length).toEqual(0);
174
+ });
175
+
176
+ it('button click dispatches an event', (done) => {
177
+ var extension = {
178
+ addon_key: 'some-key',
179
+ key: 'module-key',
180
+ url: 'http://www.example.com'
181
+ };
182
+
183
+ var options = baseDialogComponentTests.getChromeOptions();
184
+ var $dialogExtension = DialogExtensionComponent.render(extension, options);
185
+ $dialogExtension.find('iframe')[0].bridgeEstablished = true;
186
+ spyOn(EventActions, 'broadcast');
187
+ $dialogExtension.find('iframe').load(function(){
188
+ let cancelButton = $dialogExtension.find('button')[1];
189
+ cancelButton.click();
190
+ expect(EventActions.broadcast.calls.count()).toEqual(2);
191
+ expect(EventActions.broadcast.calls.first().args).toEqual([
192
+ 'dialog.cancel',
193
+ jasmine.objectContaining({
194
+ addon_key: extension.addon_key,
195
+ key: extension.key
196
+ }),
197
+ {
198
+ button: {
199
+ name: 'cancel',
200
+ identifier: 'cancel',
201
+ text: 'some cancel text'
202
+ }
203
+ }
204
+ ]);
205
+ expect(EventActions.broadcast.calls.all()[1].args).toEqual([
206
+ 'dialog.button.click',
207
+ jasmine.objectContaining({
208
+ addon_key: extension.addon_key,
209
+ key: extension.key
210
+ }),
211
+ {
212
+ button: {
213
+ name: 'cancel',
214
+ identifier: 'cancel',
215
+ text: 'some cancel text'
216
+ }
217
+ }
218
+ ]);
219
+
220
+ done();
221
+ });
222
+ });
223
+
224
+ it('closeOnEscape false button click dispatches an event', (done) => {
225
+ var extension = {
226
+ addon_key: 'some-key',
227
+ key: 'module-key',
228
+ url: 'http://www.example.com',
229
+ options: {
230
+ preventDialogCloseOnEscape: true
231
+ }
232
+ };
233
+
234
+ var options = baseDialogComponentTests.getChromeOptions();
235
+ options.closeOnEscape = false;
236
+ var $dialogExtension = DialogExtensionComponent.render(extension, options);
237
+ expect($dialogExtension.find('button.aui-button-primary')[0].getAttribute('aria-disabled')).toEqual('true');
238
+ EventDispatcher.registerOnce('after:iframe-bridge-established', (data) => {
239
+ expect($dialogExtension.find('button.aui-button-primary')[0].getAttribute('aria-disabled')).toEqual('false');
240
+ done();
241
+ });
242
+ EventDispatcher.dispatch('iframe-bridge-established', {
243
+ extension: extension,
244
+ $el: $dialogExtension.find('iframe')
245
+ });
246
+ });
247
+
248
+ it('creates a custom button', () => {
249
+ var extension = {
250
+ addon_key: 'some-key',
251
+ key: 'module-key',
252
+ url: 'http://www.example.com',
253
+ options: {
254
+ isDialog: true
255
+ }
256
+ };
257
+ var options = baseDialogComponentTests.getChromeOptions();
258
+ var $dialogExtension = DialogExtensionComponent.render(extension, options);
259
+ $dialogExtension.find('iframe')[0].bridgeEstablished = true;
260
+ var callback = function(){};
261
+ callback._context = {
262
+ extension: extension
263
+ };
264
+ expect($('.aui-dialog2').length).toEqual(1);
265
+ new DialogModule.createButton.constructor({text: 'abc123'}, callback);
266
+ expect($('.aui-dialog2 button').filter((i, button) => {
267
+ return button.innerHTML === 'abc123';
268
+ }).length).toEqual(1);
269
+ });
270
+
271
+ it('button click is ignored if iframe has not loaded', () => {
272
+ var extension = {
273
+ addon_key: 'some-key',
274
+ key: 'module-key',
275
+ url: 'http://www.example.com'
276
+ };
277
+
278
+ var options = baseDialogComponentTests.getChromeOptions();
279
+ var $dialogExtension = DialogExtensionComponent.render(extension, options);
280
+ spyOn(EventActions, 'broadcast');
281
+ $dialogExtension.find('button').first().click();
282
+ expect(EventActions.broadcast.calls.count()).toEqual(0);
283
+ });
284
+
285
+ describe('button modifier', () => {
286
+ it('hide dispatches an event', (done) => {
287
+ var extension = {
288
+ addon_key: 'some-key',
289
+ key: 'module-key',
290
+ url: 'http://www.example.com'
291
+ };
292
+ var options = baseDialogComponentTests.getChromeOptions();
293
+ DialogExtensionComponent.render(extension, options);
294
+
295
+ EventDispatcher.registerOnce('button-toggle-visibility', (data) => {
296
+ expect(data.hidden).toEqual(true);
297
+ expect(data.$el).not.toBeUndefined();
298
+ done();
299
+ });
300
+
301
+ var button = new DialogModule.getButton.constructor('submit');
302
+ button.hide();
303
+ });
304
+
305
+ it('show dispatches an event', (done) => {
306
+ var extension = {
307
+ addon_key: 'some-key',
308
+ key: 'module-key',
309
+ url: 'http://www.example.com'
310
+ };
311
+
312
+ var options = baseDialogComponentTests.getChromeOptions();
313
+ DialogExtensionComponent.render(extension, options);
314
+ EventDispatcher.registerOnce('button-toggle-visibility', (data) => {
315
+ expect(data.hidden).toEqual(false);
316
+ expect(data.$el).not.toBeUndefined();
317
+ done();
318
+ });
319
+ var button = new DialogModule.getButton.constructor('submit');
320
+ button.show();
321
+ });
322
+
323
+ it('enable dispatches an event', (done) => {
324
+ var extension = {
325
+ addon_key: 'some-key',
326
+ key: 'module-key',
327
+ url: 'http://www.example.com'
328
+ };
329
+
330
+ var options = baseDialogComponentTests.getChromeOptions();
331
+ DialogExtensionComponent.render(extension, options);
332
+ EventDispatcher.registerOnce('button-toggle', (data) => {
333
+ expect(data.disabled).toEqual(false);
334
+ expect(data.$el).not.toBeUndefined();
335
+ done();
336
+ });
337
+ var button = new DialogModule.getButton.constructor('submit');
338
+ button.enable();
339
+ });
340
+
341
+ it('disable dispatches an event', (done) => {
342
+ var extension = {
343
+ addon_key: 'some-key',
344
+ key: 'module-key',
345
+ url: 'http://www.example.com'
346
+ };
347
+
348
+ var options = baseDialogComponentTests.getChromeOptions();
349
+ DialogExtensionComponent.render(extension, options);
350
+ EventDispatcher.registerOnce('button-toggle', (data) => {
351
+ expect(data.disabled).toEqual(true);
352
+ expect(data.$el).not.toBeUndefined();
353
+ done();
354
+ });
355
+ var button = new DialogModule.getButton.constructor('submit');
356
+ button.disable();
357
+ });
358
+ });
359
+
360
+ describe('dialog custom data', () => {
361
+ it('is set in dialog module', () => {
362
+ var options = baseDialogComponentTests.getChromelessOptions();
363
+ options.key = 'some.module_key';
364
+ options.customData = {
365
+ someKey: 'some.value'
366
+ };
367
+ var callback = function(){};
368
+ callback._id = 'abc123';
369
+ callback._context = {
370
+ extension: {
371
+ addon_key: 'some.addon_key',
372
+ key: 'some.different_module',
373
+ options: {}
374
+ }
375
+ };
376
+ var dialog = new DialogModule.create.constructor(options, callback);
377
+ expect(dialog.customData).toEqual(options.customData);
378
+ });
379
+
380
+ it('callback runs even when no dialog is set', (done) => {
381
+ var cb = function(data){
382
+ expect(data).toEqual(undefined);
383
+ done();
384
+ };
385
+ cb._context = {
386
+ extension: {
387
+ addon_key: 'some.addon_key',
388
+ key: 'some.module_key',
389
+ options: { }
390
+ }
391
+ };
392
+ DialogModule.getCustomData(cb);
393
+ });
394
+ });
395
+ });
@@ -0,0 +1,296 @@
1
+ import DialogComponent from 'src/host/components/dialog';
2
+ import EventDispatcher from 'src/host/dispatchers/event_dispatcher';
3
+ import dialogUtils from 'src/host/utils/dialog';
4
+ import DialogActions from 'src/host/actions/dialog_actions';
5
+
6
+ function renderDialogWithCustomButton() {
7
+ DialogComponent.render({
8
+ chrome: true,
9
+ buttons: [{
10
+ text: 'custom button',
11
+ name: 'custom button',
12
+ identifier: 'custom-button-1'
13
+ }]
14
+ });
15
+ }
16
+
17
+ function renderDialogWithChrome() {
18
+ return DialogComponent.render({
19
+ chrome: true
20
+ });
21
+ }
22
+
23
+ describe('dialog component', () => {
24
+ afterEach(() => {
25
+ $('.aui-dialog2').remove();
26
+ $('.aui-blanket').remove();
27
+ });
28
+
29
+ describe('sanitize', () => {
30
+
31
+ it('extracts onHide if it is a function', () => {
32
+ var onHideSpy = jasmine.createSpy('onHide');
33
+ var raw = {
34
+ onHide: onHideSpy
35
+ };
36
+ var sanitizedOptions = dialogUtils.sanitizeOptions(raw);
37
+ expect(sanitizedOptions.onHide).toEqual(onHideSpy);
38
+ });
39
+
40
+ it('extracts noop function for onHide if it is not a function', () => {
41
+ var raw = {
42
+ onHide: 1
43
+ };
44
+ var sanitizedOptions = dialogUtils.sanitizeOptions(raw);
45
+ expect(typeof sanitizedOptions.onHide).toEqual('function');
46
+ });
47
+
48
+ });
49
+
50
+ describe('render', () => {
51
+
52
+ it('renders a dialog', () => {
53
+ var $dialog = DialogComponent.render();
54
+ expect($dialog.hasClass('aui-dialog2')).toEqual(true);
55
+ expect($dialog.hasClass('ap-aui-dialog2')).toEqual(true);
56
+ });
57
+
58
+ it('contains content', () => {
59
+ var content = $('<div />').text('some content');
60
+ var $dialog = DialogComponent.render({
61
+ $content: content
62
+ });
63
+ var $dialogContent = $dialog.find('.aui-dialog2-content');
64
+ expect($dialogContent.length).toEqual(1);
65
+ expect($dialogContent.text()).toEqual('some content');
66
+ });
67
+
68
+ it('is 50% height and width by default', () => {
69
+ var $dialog = DialogComponent.render();
70
+ expect($dialog[0].style.height).toEqual('50%');
71
+ expect($dialog[0].style.width).toEqual('50%');
72
+ });
73
+
74
+ it('calls onHide handler when dialog is closed', () => {
75
+ var onHideSpy = jasmine.createSpy('onHide');
76
+ var $dialog = DialogComponent.render({
77
+ onHide: onHideSpy
78
+ });
79
+ DialogActions.closeActive({});
80
+ expect(onHideSpy.calls.count()).toEqual(1);
81
+ });
82
+
83
+ describe('chrome', () => {
84
+
85
+ it('renders a chromeless dialog by default', () => {
86
+ var $dialog = DialogComponent.render();
87
+ expect($dialog.hasClass('aui-dialog2-chromeless')).toEqual(true);
88
+ });
89
+
90
+ it('iframe dimensions should be the opened dimensions', () => {
91
+ var $dialog = DialogComponent.render({
92
+ width: '200px',
93
+ height: '300px'
94
+ });
95
+ expect($dialog.width()).toEqual(200);
96
+ expect($dialog.height()).toEqual(300);
97
+ });
98
+
99
+
100
+ describe('footer', () => {
101
+
102
+ it('renders', () => {
103
+ var sanitizedOptions = dialogUtils.sanitizeOptions();
104
+ var $footer = DialogComponent._renderFooter(sanitizedOptions);
105
+ expect($footer.hasClass('aui-dialog2-footer')).toEqual(true);
106
+ });
107
+
108
+ it('has a hint', () => {
109
+ var sanitizedOptions = dialogUtils.sanitizeOptions({hint: 'abc123'});
110
+ var $footer = DialogComponent._renderFooter(sanitizedOptions);
111
+ var hint = $footer.find('.aui-dialog2-footer-hint');
112
+ expect(hint.length).toEqual(1);
113
+ expect(hint.text()).toEqual('abc123');
114
+ });
115
+
116
+ it('has actions', () => {
117
+ var sanitizedOptions = dialogUtils.sanitizeOptions();
118
+ var $footer = DialogComponent._renderFooter(sanitizedOptions);
119
+ var $actions = $footer.find('.aui-dialog2-footer-actions');
120
+ expect($actions.length).toEqual(1);
121
+ expect($actions.find('button').length).toEqual(2);
122
+ });
123
+
124
+ it('does not trigger event on button clicks when iframe is has not loaded', () => {
125
+ var sanitizedOptions = dialogUtils.sanitizeOptions();
126
+ var $footer = DialogComponent._renderFooter(sanitizedOptions);
127
+ spyOn(DialogActions, 'clickButton');
128
+ $footer.find('button').first().trigger('click');
129
+ expect(DialogActions.clickButton.calls.count()).toEqual(0);
130
+ });
131
+ });
132
+
133
+ describe('header', () => {
134
+
135
+ it('renders', () => {
136
+ var sanitizedOptions = dialogUtils.sanitizeOptions();
137
+ var $header = DialogComponent._renderHeader(sanitizedOptions);
138
+ expect($header.hasClass('aui-dialog2-header')).toEqual(true);
139
+ });
140
+
141
+ it('adds header text', () => {
142
+ var sanitizedOptions = dialogUtils.sanitizeOptions();
143
+ sanitizedOptions.header = 'header text';
144
+ var $header = DialogComponent._renderHeader(sanitizedOptions);
145
+ expect($header.find('.aui-dialog2-header-main').text()).toEqual(sanitizedOptions.header);
146
+ });
147
+
148
+ it('has a close button', () => {
149
+ var sanitizedOptions = dialogUtils.sanitizeOptions();
150
+ var $header = DialogComponent._renderHeader(sanitizedOptions);
151
+ expect($header.find('.aui-dialog2-header-close').length).toEqual(1);
152
+ });
153
+ });
154
+
155
+ describe('buttons', () => {
156
+
157
+ describe('default', () => {
158
+ it('gets the button visibility', () => {
159
+ renderDialogWithChrome();
160
+ expect(DialogComponent.buttonIsVisible('submit')).toBe(true);
161
+ expect(DialogComponent.buttonIsVisible('cancel')).toBe(true);
162
+ });
163
+
164
+ it('gets the button visibility of hidden buttons', () => {
165
+ renderDialogWithChrome();
166
+ $('.aui-dialog2-footer-actions .ap-aui-button').hide();
167
+ expect(DialogComponent.buttonIsVisible('submit')).toBe(false);
168
+ expect(DialogComponent.buttonIsVisible('cancel')).toBe(false);
169
+ });
170
+
171
+ it('gets the button state', () => {
172
+ renderDialogWithChrome();
173
+ expect(DialogComponent.buttonIsEnabled('submit')).toBe(false);
174
+ expect(DialogComponent.buttonIsEnabled('cancel')).toBe(true);
175
+ });
176
+
177
+ it('gets the state of disabled buttons', () => {
178
+ renderDialogWithChrome();
179
+ $('.aui-dialog2-footer-actions .ap-aui-button').attr('aria-disabled', true);
180
+ expect(DialogComponent.buttonIsEnabled('submit')).toBe(false);
181
+ expect(DialogComponent.buttonIsEnabled('cancel')).toBe(false);
182
+ });
183
+ });
184
+
185
+ describe('custom', () => {
186
+ it('gets the button visibility', () => {
187
+ renderDialogWithCustomButton()
188
+ expect(DialogComponent.buttonIsVisible('custom-button-1')).toBe(true);
189
+ });
190
+
191
+ it('gets the button visibility of hidden buttons', () => {
192
+ renderDialogWithCustomButton()
193
+ $('.aui-dialog2-footer-actions .ap-aui-button').hide();
194
+ expect(DialogComponent.buttonIsVisible('custom-button-1')).toBe(false);
195
+ });
196
+
197
+ it('gets the button state', () => {
198
+ renderDialogWithCustomButton()
199
+ expect(DialogComponent.buttonIsEnabled('custom-button-1')).toBe(true);
200
+ });
201
+
202
+ it('gets the state of disabled buttons', () => {
203
+ renderDialogWithCustomButton()
204
+ $('.aui-dialog2-footer-actions .ap-aui-button').attr('aria-disabled', true);
205
+ expect(DialogComponent.buttonIsEnabled('custom-button-1')).toBe(false);
206
+ });
207
+ });
208
+ });
209
+ });
210
+
211
+ describe('chromeless', () => {
212
+
213
+ it('does not have chrome', () => {
214
+ var $dialog = DialogComponent.render({
215
+ chrome: false
216
+ });
217
+ expect($dialog.hasClass('aui-dialog2-chromeless')).toEqual(true);
218
+ expect($dialog.find('header').length).toEqual(0);
219
+ expect($dialog.find('footer').length).toEqual(0);
220
+ });
221
+
222
+ it('iframe dimensions should be the opened dimensions', () => {
223
+ var $dialog = DialogComponent.render({
224
+ width: '200px',
225
+ height: '300px',
226
+ chrome: false
227
+ });
228
+
229
+ expect($dialog.width()).toEqual(200);
230
+ expect($dialog.height()).toEqual(300);
231
+ });
232
+
233
+ });
234
+
235
+ describe('fullscreen/maximum', () => {
236
+ // Back compatibility support for addons like Gliffy and Balsamiq which have a special 100% height and width chromeless Dialogs.
237
+ // This is not API or documented and should be deprecated.
238
+ it('100% width and height takes up the entire screen', () => {
239
+ var $dialog = DialogComponent.render({
240
+ height: '100%',
241
+ width: '100%'
242
+ });
243
+ expect($dialog.hasClass('aui-dialog2-chromeless')).toEqual(true);
244
+ expect($dialog.hasClass('ap-header-controls')).toEqual(false);
245
+ expect($dialog.height()).toEqual($(window).height());
246
+ expect($dialog.width()).toEqual($(window).width());
247
+ });
248
+
249
+ it('maximum dialog takes up the entire screen', () => {
250
+ var $dialog = DialogComponent.render({
251
+ size: 'maximum'
252
+ });
253
+ expect($dialog.hasClass('aui-dialog2-chromeless')).toEqual(true);
254
+ expect($dialog.hasClass('ap-header-controls')).toEqual(false);
255
+ expect($dialog.height()).toEqual($(window).height());
256
+ expect($dialog.width()).toEqual($(window).width());
257
+ });
258
+
259
+ it('combination of size and dimensions', () => {
260
+ var $dialog = DialogComponent.render({
261
+ height: '100%',
262
+ width: '100%',
263
+ size: 'maximum'
264
+ });
265
+ expect($dialog.hasClass('aui-dialog2-chromeless')).toEqual(true);
266
+ expect($dialog.hasClass('ap-header-controls')).toEqual(false);
267
+ expect($dialog.height()).toEqual($(window).height());
268
+ expect($dialog.width()).toEqual($(window).width());
269
+ });
270
+ })
271
+
272
+ });
273
+
274
+ describe('max dimensions are no greater than the window', () => {
275
+ it('will not open larger than 100% width / height', () => {
276
+ var $dialog = DialogComponent.render({
277
+ height: '101%',
278
+ width: '102%'
279
+ });
280
+
281
+ expect($dialog[0].style.height).toEqual('100%');
282
+ expect($dialog[0].style.width).toEqual('100%');
283
+ });
284
+
285
+ it('will not open larger than window in PX', () => {
286
+ var $dialog = DialogComponent.render({
287
+ height: '100000px',
288
+ width: '100000px',
289
+ });
290
+ expect($dialog.height()).toEqual($(window).height());
291
+ expect($dialog.width()).toEqual($(window).width());
292
+ });
293
+ });
294
+
295
+
296
+ });