kempo-ui 0.0.35 → 0.0.37
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.
- package/dist/components/ThemeSwitcher.js +2 -2
- package/dist/utils/context.js +1 -0
- package/dist/utils/theme.js +1 -0
- package/docs/components/theme-switcher.html +18 -6
- package/docs/index.html +18 -6
- package/docs/nav-1.inc.html +2 -0
- package/docs/nav.inc.html +2 -0
- package/docs/src/components/ThemeSwitcher.js +2 -2
- package/docs/src/utils/context.js +1 -0
- package/docs/src/utils/theme.js +1 -0
- package/docs/utils/context.html +160 -0
- package/docs/utils/theme.html +153 -0
- package/package.json +2 -2
- package/src/components/Table.js +2 -1
- package/src/components/ThemeSwitcher.js +17 -30
- package/src/components/tableControls/PageSelect.js +20 -28
- package/src/utils/context.js +40 -0
- package/src/utils/theme.js +50 -0
- package/tests/components/Accordion.browser-test.js +470 -0
- package/tests/components/Card.browser-test.js +286 -0
- package/tests/components/ColorPicker.browser-test.js +658 -0
- package/tests/components/ContentSlider.browser-test.js +495 -0
- package/tests/components/Dialog.browser-test.js +677 -0
- package/tests/components/FocusCapture.browser-test.js +187 -0
- package/tests/components/HybridComponent.browser-test.js +1 -1
- package/tests/components/Icon.browser-test.js +355 -0
- package/tests/components/Import.browser-test.js +312 -0
- package/tests/components/PhotoViewer.browser-test.js +640 -0
- package/tests/components/Resize.browser-test.js +553 -0
- package/tests/components/ShadowComponent.browser-test.js +3 -3
- package/tests/components/ShowMore.browser-test.js +618 -0
- package/tests/components/SideMenu.browser-test.js +667 -0
- package/tests/components/Sortable.browser-test.js +650 -0
- package/tests/components/Split.browser-test.js +629 -0
- package/tests/components/Table.browser-test.js +1119 -0
- package/tests/components/Tabs.browser-test.js +847 -0
- package/tests/components/Tags.browser-test.js +604 -0
- package/tests/components/ThemeSwitcher.browser-test.js +413 -0
- package/tests/components/Timestamp.browser-test.js +509 -0
- package/tests/components/Toast.browser-test.js +616 -0
- package/tests/components/Toggle.browser-test.js +557 -0
- package/tests/components/Tree.browser-test.js +790 -0
- package/tests/components/tableControls/ExportControls.browser-test.js +307 -0
- package/tests/components/tableControls/FieldSortHide.browser-test.js +347 -0
- package/tests/components/tableControls/Filters.browser-test.js +376 -0
- package/tests/components/tableControls/HiddenCount.browser-test.js +263 -0
- package/tests/components/tableControls/PaginationControls.browser-test.js +514 -0
- package/tests/components/tableControls/RecordControls.browser-test.js +360 -0
- package/tests/components/tableControls/Search.browser-test.js +283 -0
- package/tests/components/tableControls/TableControl.browser-test.js +300 -0
- package/tests/utils/context.test.js +224 -0
- package/tests/utils/cookie.browser-test.js +146 -0
- package/tests/utils/drag.browser-test.js +285 -0
- package/tests/utils/formatTimestamp.test.js +224 -0
- package/tests/utils/object.browser-test.js +378 -0
- package/tests/utils/propConverters.test.js +207 -0
- package/tests/utils/string.test.js +379 -0
- package/tests/utils/theme.browser-test.js +177 -0
- package/tests/utils/type.test.js +211 -0
- package/tests/utils/wait.browser-test.js +19 -0
|
@@ -0,0 +1,677 @@
|
|
|
1
|
+
import Dialog from '../../src/components/Dialog.js';
|
|
2
|
+
|
|
3
|
+
const createDialog = async (options = {}) => {
|
|
4
|
+
const container = document.createElement('div');
|
|
5
|
+
container.innerHTML = `
|
|
6
|
+
<k-dialog
|
|
7
|
+
${options.opened ? 'opened' : ''}
|
|
8
|
+
${options.closeBtn === false ? 'close-btn="false"' : ''}
|
|
9
|
+
${options.overlayClose === false ? 'overlay-close="false"' : ''}
|
|
10
|
+
${options.disableKeyboardClose ? 'disable-keyboard-close' : ''}
|
|
11
|
+
${options.confirmText ? `confirm-text="${options.confirmText}"` : ''}
|
|
12
|
+
${options.cancelText ? `cancel-text="${options.cancelText}"` : ''}
|
|
13
|
+
>
|
|
14
|
+
<span slot="title">${options.title || 'Test Dialog'}</span>
|
|
15
|
+
<div>${options.content || 'Dialog content'}</div>
|
|
16
|
+
</k-dialog>
|
|
17
|
+
`;
|
|
18
|
+
document.body.appendChild(container);
|
|
19
|
+
|
|
20
|
+
const dialog = container.querySelector('k-dialog');
|
|
21
|
+
await dialog.updateComplete;
|
|
22
|
+
|
|
23
|
+
return { container, dialog };
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const cleanup = container => {
|
|
27
|
+
if(container && container.parentNode){
|
|
28
|
+
container.parentNode.removeChild(container);
|
|
29
|
+
}
|
|
30
|
+
document.body.classList.remove('no-scroll');
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const cleanupAllDialogs = () => {
|
|
34
|
+
document.querySelectorAll('k-dialog').forEach(d => {
|
|
35
|
+
if(d.parentNode){
|
|
36
|
+
d.parentNode.removeChild(d);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
document.body.classList.remove('no-scroll');
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default {
|
|
43
|
+
/*
|
|
44
|
+
Element Creation Tests
|
|
45
|
+
*/
|
|
46
|
+
'should create dialog element': async ({pass, fail}) => {
|
|
47
|
+
const { container, dialog } = await createDialog();
|
|
48
|
+
|
|
49
|
+
if(!dialog){
|
|
50
|
+
cleanup(container);
|
|
51
|
+
fail('Dialog element should be created');
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if(!(dialog instanceof Dialog)){
|
|
56
|
+
cleanup(container);
|
|
57
|
+
fail('Element should be instance of Dialog');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
cleanup(container);
|
|
62
|
+
pass('Dialog element created correctly');
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
'should have shadow root': async ({pass, fail}) => {
|
|
66
|
+
const { container, dialog } = await createDialog();
|
|
67
|
+
|
|
68
|
+
if(!dialog.shadowRoot){
|
|
69
|
+
cleanup(container);
|
|
70
|
+
fail('Dialog should have shadow root');
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
cleanup(container);
|
|
75
|
+
pass('Dialog has shadow root');
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
/*
|
|
79
|
+
Default Property Tests
|
|
80
|
+
*/
|
|
81
|
+
'should be closed by default': async ({pass, fail}) => {
|
|
82
|
+
const { container, dialog } = await createDialog();
|
|
83
|
+
|
|
84
|
+
if(dialog.opened !== false){
|
|
85
|
+
cleanup(container);
|
|
86
|
+
fail(`Expected opened false, got ${dialog.opened}`);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
cleanup(container);
|
|
91
|
+
pass('Dialog is closed by default');
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
'should have closeBtn true by default': async ({pass, fail}) => {
|
|
95
|
+
const { container, dialog } = await createDialog();
|
|
96
|
+
|
|
97
|
+
if(dialog.closeBtn !== true){
|
|
98
|
+
cleanup(container);
|
|
99
|
+
fail(`Expected closeBtn true, got ${dialog.closeBtn}`);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
cleanup(container);
|
|
104
|
+
pass('closeBtn is true by default');
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
'should have overlayClose true by default': async ({pass, fail}) => {
|
|
108
|
+
const { container, dialog } = await createDialog();
|
|
109
|
+
|
|
110
|
+
if(dialog.overlayClose !== true){
|
|
111
|
+
cleanup(container);
|
|
112
|
+
fail(`Expected overlayClose true, got ${dialog.overlayClose}`);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
cleanup(container);
|
|
117
|
+
pass('overlayClose is true by default');
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
'should have disableKeyboardClose false by default': async ({pass, fail}) => {
|
|
121
|
+
const { container, dialog } = await createDialog();
|
|
122
|
+
|
|
123
|
+
if(dialog.disableKeyboardClose !== false){
|
|
124
|
+
cleanup(container);
|
|
125
|
+
fail(`Expected disableKeyboardClose false, got ${dialog.disableKeyboardClose}`);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
cleanup(container);
|
|
130
|
+
pass('disableKeyboardClose is false by default');
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
/*
|
|
134
|
+
Open/Close Tests
|
|
135
|
+
*/
|
|
136
|
+
'should open dialog with open method': async ({pass, fail}) => {
|
|
137
|
+
const { container, dialog } = await createDialog();
|
|
138
|
+
|
|
139
|
+
dialog.open();
|
|
140
|
+
await dialog.updateComplete;
|
|
141
|
+
|
|
142
|
+
if(dialog.opened !== true){
|
|
143
|
+
cleanup(container);
|
|
144
|
+
fail(`Expected opened true, got ${dialog.opened}`);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
cleanup(container);
|
|
149
|
+
pass('open() opens dialog');
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
'should close dialog with close method': async ({pass, fail}) => {
|
|
153
|
+
const { container, dialog } = await createDialog({ opened: true });
|
|
154
|
+
|
|
155
|
+
dialog.close();
|
|
156
|
+
await dialog.updateComplete;
|
|
157
|
+
|
|
158
|
+
if(dialog.opened !== false){
|
|
159
|
+
cleanup(container);
|
|
160
|
+
fail(`Expected opened false, got ${dialog.opened}`);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
cleanup(container);
|
|
165
|
+
pass('close() closes dialog');
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
'should toggle dialog state': async ({pass, fail}) => {
|
|
169
|
+
const { container, dialog } = await createDialog();
|
|
170
|
+
|
|
171
|
+
dialog.toggle();
|
|
172
|
+
await dialog.updateComplete;
|
|
173
|
+
|
|
174
|
+
if(dialog.opened !== true){
|
|
175
|
+
cleanup(container);
|
|
176
|
+
fail(`Expected opened true after first toggle, got ${dialog.opened}`);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
dialog.toggle();
|
|
181
|
+
await dialog.updateComplete;
|
|
182
|
+
|
|
183
|
+
if(dialog.opened !== false){
|
|
184
|
+
cleanup(container);
|
|
185
|
+
fail(`Expected opened false after second toggle, got ${dialog.opened}`);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
cleanup(container);
|
|
190
|
+
pass('toggle() switches dialog state');
|
|
191
|
+
},
|
|
192
|
+
|
|
193
|
+
/*
|
|
194
|
+
Event Tests
|
|
195
|
+
*/
|
|
196
|
+
'should dispatch opened event': async ({pass, fail}) => {
|
|
197
|
+
const { container, dialog } = await createDialog();
|
|
198
|
+
|
|
199
|
+
let eventFired = false;
|
|
200
|
+
dialog.addEventListener('opened', () => {
|
|
201
|
+
eventFired = true;
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
dialog.open();
|
|
205
|
+
await dialog.updateComplete;
|
|
206
|
+
|
|
207
|
+
if(!eventFired){
|
|
208
|
+
cleanup(container);
|
|
209
|
+
fail('opened event should be dispatched');
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
cleanup(container);
|
|
214
|
+
pass('opened event dispatched');
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
'should dispatch close event': async ({pass, fail}) => {
|
|
218
|
+
const { container, dialog } = await createDialog({ opened: true });
|
|
219
|
+
|
|
220
|
+
let eventFired = false;
|
|
221
|
+
dialog.addEventListener('close', () => {
|
|
222
|
+
eventFired = true;
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
dialog.close();
|
|
226
|
+
await dialog.updateComplete;
|
|
227
|
+
|
|
228
|
+
if(!eventFired){
|
|
229
|
+
cleanup(container);
|
|
230
|
+
fail('close event should be dispatched');
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
cleanup(container);
|
|
235
|
+
pass('close event dispatched');
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
/*
|
|
239
|
+
Close Button Tests
|
|
240
|
+
*/
|
|
241
|
+
'should render close button when enabled': async ({pass, fail}) => {
|
|
242
|
+
const { container, dialog } = await createDialog({ opened: true });
|
|
243
|
+
|
|
244
|
+
const closeBtn = dialog.shadowRoot.querySelector('#close');
|
|
245
|
+
|
|
246
|
+
if(!closeBtn){
|
|
247
|
+
cleanup(container);
|
|
248
|
+
fail('Should render close button');
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
cleanup(container);
|
|
253
|
+
pass('Close button rendered');
|
|
254
|
+
},
|
|
255
|
+
|
|
256
|
+
'should close on close button click': async ({pass, fail}) => {
|
|
257
|
+
const { container, dialog } = await createDialog({ opened: true });
|
|
258
|
+
|
|
259
|
+
const closeBtn = dialog.shadowRoot.querySelector('#close');
|
|
260
|
+
closeBtn.click();
|
|
261
|
+
await dialog.updateComplete;
|
|
262
|
+
|
|
263
|
+
if(dialog.opened !== false){
|
|
264
|
+
cleanup(container);
|
|
265
|
+
fail('Dialog should close on close button click');
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
cleanup(container);
|
|
270
|
+
pass('Close button closes dialog');
|
|
271
|
+
},
|
|
272
|
+
|
|
273
|
+
/*
|
|
274
|
+
Overlay Close Tests
|
|
275
|
+
*/
|
|
276
|
+
'should close on overlay click when enabled': async ({pass, fail}) => {
|
|
277
|
+
const { container, dialog } = await createDialog({ opened: true });
|
|
278
|
+
|
|
279
|
+
const overlay = dialog.shadowRoot.querySelector('#overlay');
|
|
280
|
+
overlay.click();
|
|
281
|
+
await dialog.updateComplete;
|
|
282
|
+
|
|
283
|
+
if(dialog.opened !== false){
|
|
284
|
+
cleanup(container);
|
|
285
|
+
fail('Dialog should close on overlay click');
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
cleanup(container);
|
|
290
|
+
pass('Overlay click closes dialog');
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
'should not close on overlay click when disabled': async ({pass, fail}) => {
|
|
294
|
+
const { container, dialog } = await createDialog({ opened: true });
|
|
295
|
+
|
|
296
|
+
// Set overlayClose via property, not attribute (boolExists converter)
|
|
297
|
+
dialog.overlayClose = false;
|
|
298
|
+
await dialog.updateComplete;
|
|
299
|
+
|
|
300
|
+
const overlay = dialog.shadowRoot.querySelector('#overlay');
|
|
301
|
+
overlay.click();
|
|
302
|
+
await dialog.updateComplete;
|
|
303
|
+
|
|
304
|
+
if(dialog.opened !== true){
|
|
305
|
+
cleanup(container);
|
|
306
|
+
fail('Dialog should not close on overlay click when disabled');
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
cleanup(container);
|
|
311
|
+
pass('Overlay click does not close dialog when disabled');
|
|
312
|
+
},
|
|
313
|
+
|
|
314
|
+
/*
|
|
315
|
+
Keyboard Close Tests
|
|
316
|
+
*/
|
|
317
|
+
'should close on Escape key': async ({pass, fail}) => {
|
|
318
|
+
const { container, dialog } = await createDialog();
|
|
319
|
+
|
|
320
|
+
// Must open with open() method to add keydown listener
|
|
321
|
+
dialog.open();
|
|
322
|
+
await dialog.updateComplete;
|
|
323
|
+
|
|
324
|
+
// Dialog listens on window, not document, and uses keyCode
|
|
325
|
+
window.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 27 }));
|
|
326
|
+
await dialog.updateComplete;
|
|
327
|
+
|
|
328
|
+
if(dialog.opened !== false){
|
|
329
|
+
cleanup(container);
|
|
330
|
+
fail('Dialog should close on Escape key');
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
cleanup(container);
|
|
335
|
+
pass('Escape key closes dialog');
|
|
336
|
+
},
|
|
337
|
+
|
|
338
|
+
'should not close on Escape when keyboard close disabled': async ({pass, fail}) => {
|
|
339
|
+
const { container, dialog } = await createDialog({ disableKeyboardClose: true });
|
|
340
|
+
|
|
341
|
+
dialog.open();
|
|
342
|
+
await dialog.updateComplete;
|
|
343
|
+
|
|
344
|
+
window.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 27 }));
|
|
345
|
+
await dialog.updateComplete;
|
|
346
|
+
|
|
347
|
+
if(dialog.opened !== true){
|
|
348
|
+
cleanup(container);
|
|
349
|
+
fail('Dialog should not close on Escape when disabled');
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
cleanup(container);
|
|
354
|
+
pass('Escape does not close when keyboard close disabled');
|
|
355
|
+
},
|
|
356
|
+
|
|
357
|
+
/*
|
|
358
|
+
Confirm/Cancel Button Tests
|
|
359
|
+
*/
|
|
360
|
+
'should call confirmAction when confirm button clicked': async ({pass, fail}) => {
|
|
361
|
+
const { container, dialog } = await createDialog({ opened: true, confirmText: 'OK' });
|
|
362
|
+
|
|
363
|
+
let callbackCalled = false;
|
|
364
|
+
dialog.confirmAction = () => {
|
|
365
|
+
callbackCalled = true;
|
|
366
|
+
};
|
|
367
|
+
await dialog.updateComplete;
|
|
368
|
+
|
|
369
|
+
const confirmBtn = dialog.shadowRoot.querySelector('#confirm');
|
|
370
|
+
confirmBtn.click();
|
|
371
|
+
await dialog.updateComplete;
|
|
372
|
+
|
|
373
|
+
if(!callbackCalled){
|
|
374
|
+
cleanup(container);
|
|
375
|
+
fail('confirmAction should be called');
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
cleanup(container);
|
|
380
|
+
pass('confirmAction called on confirm button click');
|
|
381
|
+
},
|
|
382
|
+
|
|
383
|
+
'should call cancelAction when cancel button clicked': async ({pass, fail}) => {
|
|
384
|
+
const { container, dialog } = await createDialog({ opened: true, cancelText: 'Cancel' });
|
|
385
|
+
|
|
386
|
+
let callbackCalled = false;
|
|
387
|
+
dialog.cancelAction = () => {
|
|
388
|
+
callbackCalled = true;
|
|
389
|
+
};
|
|
390
|
+
await dialog.updateComplete;
|
|
391
|
+
|
|
392
|
+
const cancelBtn = dialog.shadowRoot.querySelector('#cancel');
|
|
393
|
+
cancelBtn.click();
|
|
394
|
+
await dialog.updateComplete;
|
|
395
|
+
|
|
396
|
+
if(!callbackCalled){
|
|
397
|
+
cleanup(container);
|
|
398
|
+
fail('cancelAction should be called');
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
cleanup(container);
|
|
403
|
+
pass('cancelAction called on cancel button click');
|
|
404
|
+
},
|
|
405
|
+
|
|
406
|
+
'should close on confirm button click': async ({pass, fail}) => {
|
|
407
|
+
const { container, dialog } = await createDialog({ opened: true, confirmText: 'OK' });
|
|
408
|
+
await dialog.updateComplete;
|
|
409
|
+
|
|
410
|
+
const confirmBtn = dialog.shadowRoot.querySelector('#confirm');
|
|
411
|
+
confirmBtn.click();
|
|
412
|
+
await dialog.updateComplete;
|
|
413
|
+
|
|
414
|
+
if(dialog.opened !== false){
|
|
415
|
+
cleanup(container);
|
|
416
|
+
fail('Dialog should close on confirm');
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
cleanup(container);
|
|
421
|
+
pass('Dialog closes on confirm');
|
|
422
|
+
},
|
|
423
|
+
|
|
424
|
+
'should close on cancel button click': async ({pass, fail}) => {
|
|
425
|
+
const { container, dialog } = await createDialog({ opened: true, cancelText: 'Cancel' });
|
|
426
|
+
await dialog.updateComplete;
|
|
427
|
+
|
|
428
|
+
const cancelBtn = dialog.shadowRoot.querySelector('#cancel');
|
|
429
|
+
cancelBtn.click();
|
|
430
|
+
await dialog.updateComplete;
|
|
431
|
+
|
|
432
|
+
if(dialog.opened !== false){
|
|
433
|
+
cleanup(container);
|
|
434
|
+
fail('Dialog should close on cancel');
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
cleanup(container);
|
|
439
|
+
pass('Dialog closes on cancel');
|
|
440
|
+
},
|
|
441
|
+
|
|
442
|
+
/*
|
|
443
|
+
Static Method Tests
|
|
444
|
+
*/
|
|
445
|
+
'Dialog.create should create and return dialog': async ({pass, fail}) => {
|
|
446
|
+
const dialog = Dialog.create('<p>Created content</p>', { title: 'Created Dialog' });
|
|
447
|
+
|
|
448
|
+
if(!dialog){
|
|
449
|
+
cleanupAllDialogs();
|
|
450
|
+
fail('Dialog.create should return dialog');
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if(!(dialog instanceof Dialog)){
|
|
455
|
+
cleanupAllDialogs();
|
|
456
|
+
fail('Returned value should be Dialog instance');
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
cleanupAllDialogs();
|
|
461
|
+
pass('Dialog.create works correctly');
|
|
462
|
+
},
|
|
463
|
+
|
|
464
|
+
'Dialog.create should open dialog automatically': async ({pass, fail}) => {
|
|
465
|
+
const dialog = Dialog.create('<p>Content</p>', { title: 'Auto Open' });
|
|
466
|
+
|
|
467
|
+
await dialog.updateComplete;
|
|
468
|
+
|
|
469
|
+
if(dialog.opened !== true){
|
|
470
|
+
cleanupAllDialogs();
|
|
471
|
+
fail('Created dialog should be opened');
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
cleanupAllDialogs();
|
|
476
|
+
pass('Dialog.create opens dialog automatically');
|
|
477
|
+
},
|
|
478
|
+
|
|
479
|
+
'Dialog.create should set custom confirm/cancel text': async ({pass, fail}) => {
|
|
480
|
+
const dialog = Dialog.create('<p>Content</p>', {
|
|
481
|
+
title: 'Custom Buttons',
|
|
482
|
+
confirmText: 'Yes',
|
|
483
|
+
cancelText: 'No'
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
await dialog.updateComplete;
|
|
487
|
+
|
|
488
|
+
if(dialog.confirmText !== 'Yes'){
|
|
489
|
+
cleanupAllDialogs();
|
|
490
|
+
fail(`Expected confirmText "Yes", got "${dialog.confirmText}"`);
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
if(dialog.cancelText !== 'No'){
|
|
495
|
+
cleanupAllDialogs();
|
|
496
|
+
fail(`Expected cancelText "No", got "${dialog.cancelText}"`);
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
cleanupAllDialogs();
|
|
501
|
+
pass('Custom button text set correctly');
|
|
502
|
+
},
|
|
503
|
+
|
|
504
|
+
'Dialog.confirm should create confirmation dialog': async ({pass, fail}) => {
|
|
505
|
+
let response = null;
|
|
506
|
+
const dialog = Dialog.confirm('Are you sure?', r => { response = r; });
|
|
507
|
+
|
|
508
|
+
await dialog.updateComplete;
|
|
509
|
+
|
|
510
|
+
const confirmBtn = dialog.shadowRoot.querySelector('#confirm');
|
|
511
|
+
const cancelBtn = dialog.shadowRoot.querySelector('#cancel');
|
|
512
|
+
|
|
513
|
+
if(!confirmBtn){
|
|
514
|
+
cleanupAllDialogs();
|
|
515
|
+
fail('Confirm dialog should have confirm button');
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
if(!cancelBtn){
|
|
520
|
+
cleanupAllDialogs();
|
|
521
|
+
fail('Confirm dialog should have cancel button');
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
cleanupAllDialogs();
|
|
526
|
+
pass('Dialog.confirm creates confirmation dialog');
|
|
527
|
+
},
|
|
528
|
+
|
|
529
|
+
'Dialog.alert should create alert dialog': async ({pass, fail}) => {
|
|
530
|
+
const dialog = Dialog.alert('Alert message');
|
|
531
|
+
|
|
532
|
+
await dialog.updateComplete;
|
|
533
|
+
|
|
534
|
+
if(!dialog){
|
|
535
|
+
cleanupAllDialogs();
|
|
536
|
+
fail('Dialog.alert should create dialog');
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
cleanupAllDialogs();
|
|
541
|
+
pass('Dialog.alert creates alert dialog');
|
|
542
|
+
},
|
|
543
|
+
|
|
544
|
+
'Dialog.error should create error dialog': async ({pass, fail}) => {
|
|
545
|
+
const dialog = Dialog.error('Error message');
|
|
546
|
+
|
|
547
|
+
await dialog.updateComplete;
|
|
548
|
+
|
|
549
|
+
const titleEl = dialog.querySelector('[slot="title"]');
|
|
550
|
+
|
|
551
|
+
if(!titleEl){
|
|
552
|
+
cleanupAllDialogs();
|
|
553
|
+
fail('Error dialog should have title');
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// Title uses tc-danger CSS class, not inline style
|
|
558
|
+
if(!titleEl.classList.contains('tc-danger')){
|
|
559
|
+
cleanupAllDialogs();
|
|
560
|
+
fail('Error dialog title should have tc-danger class');
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
cleanupAllDialogs();
|
|
565
|
+
pass('Dialog.error creates error dialog with danger styling');
|
|
566
|
+
},
|
|
567
|
+
|
|
568
|
+
'Dialog.success should create success dialog': async ({pass, fail}) => {
|
|
569
|
+
const dialog = Dialog.success('Success message');
|
|
570
|
+
|
|
571
|
+
await dialog.updateComplete;
|
|
572
|
+
|
|
573
|
+
const titleEl = dialog.querySelector('[slot="title"]');
|
|
574
|
+
|
|
575
|
+
if(!titleEl){
|
|
576
|
+
cleanupAllDialogs();
|
|
577
|
+
fail('Success dialog should have title');
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// Title uses tc-success CSS class, not inline style
|
|
582
|
+
if(!titleEl.classList.contains('tc-success')){
|
|
583
|
+
cleanupAllDialogs();
|
|
584
|
+
fail('Success dialog title should have tc-success class');
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
cleanupAllDialogs();
|
|
589
|
+
pass('Dialog.success creates success dialog with success styling');
|
|
590
|
+
},
|
|
591
|
+
|
|
592
|
+
/*
|
|
593
|
+
Callback Tests for Static Methods
|
|
594
|
+
*/
|
|
595
|
+
'Dialog.create should call confirmAction callback': async ({pass, fail}) => {
|
|
596
|
+
let callbackCalled = false;
|
|
597
|
+
|
|
598
|
+
const dialog = Dialog.create('<p>Content</p>', {
|
|
599
|
+
title: 'Test',
|
|
600
|
+
confirmText: 'Confirm',
|
|
601
|
+
confirmAction: () => {
|
|
602
|
+
callbackCalled = true;
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
await dialog.updateComplete;
|
|
607
|
+
const confirmBtn = dialog.shadowRoot.querySelector('#confirm');
|
|
608
|
+
confirmBtn.click();
|
|
609
|
+
|
|
610
|
+
if(!callbackCalled){
|
|
611
|
+
cleanupAllDialogs();
|
|
612
|
+
fail('confirmAction callback should be called');
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
cleanupAllDialogs();
|
|
617
|
+
pass('confirmAction callback called');
|
|
618
|
+
},
|
|
619
|
+
|
|
620
|
+
'Dialog.create should call cancelAction callback': async ({pass, fail}) => {
|
|
621
|
+
let callbackCalled = false;
|
|
622
|
+
|
|
623
|
+
const dialog = Dialog.create('<p>Content</p>', {
|
|
624
|
+
title: 'Test',
|
|
625
|
+
cancelText: 'Cancel',
|
|
626
|
+
cancelAction: () => {
|
|
627
|
+
callbackCalled = true;
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
await dialog.updateComplete;
|
|
632
|
+
const cancelBtn = dialog.shadowRoot.querySelector('#cancel');
|
|
633
|
+
cancelBtn.click();
|
|
634
|
+
|
|
635
|
+
if(!callbackCalled){
|
|
636
|
+
cleanupAllDialogs();
|
|
637
|
+
fail('cancelAction callback should be called');
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
cleanupAllDialogs();
|
|
642
|
+
pass('cancelAction callback called');
|
|
643
|
+
},
|
|
644
|
+
|
|
645
|
+
/*
|
|
646
|
+
Content Slot Tests
|
|
647
|
+
*/
|
|
648
|
+
'should render title slot': async ({pass, fail}) => {
|
|
649
|
+
const { container, dialog } = await createDialog({ title: 'My Title', opened: true });
|
|
650
|
+
|
|
651
|
+
const titleSlot = dialog.shadowRoot.querySelector('slot[name="title"]');
|
|
652
|
+
|
|
653
|
+
if(!titleSlot){
|
|
654
|
+
cleanup(container);
|
|
655
|
+
fail('Should have title slot');
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
cleanup(container);
|
|
660
|
+
pass('Title slot rendered');
|
|
661
|
+
},
|
|
662
|
+
|
|
663
|
+
'should render default slot for content': async ({pass, fail}) => {
|
|
664
|
+
const { container, dialog } = await createDialog({ opened: true });
|
|
665
|
+
|
|
666
|
+
const defaultSlot = dialog.shadowRoot.querySelector('slot:not([name])');
|
|
667
|
+
|
|
668
|
+
if(!defaultSlot){
|
|
669
|
+
cleanup(container);
|
|
670
|
+
fail('Should have default slot');
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
cleanup(container);
|
|
675
|
+
pass('Default content slot rendered');
|
|
676
|
+
}
|
|
677
|
+
};
|