@nyaruka/temba-components 0.123.0 → 0.124.0
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/.github/copilot-instructions.md +22 -4
- package/CHANGELOG.md +11 -0
- package/demo/drag-drop-demo.html +141 -0
- package/demo/index.html +15 -0
- package/demo/test-drag-drop.html +94 -0
- package/dist/temba-components.js +323 -191
- package/dist/temba-components.js.map +1 -1
- package/out-tsc/src/fields/FieldManager.js +27 -34
- package/out-tsc/src/fields/FieldManager.js.map +1 -1
- package/out-tsc/src/list/SortableList.js +257 -60
- package/out-tsc/src/list/SortableList.js.map +1 -1
- package/out-tsc/src/omnibox/Omnibox.js +1 -1
- package/out-tsc/src/omnibox/Omnibox.js.map +1 -1
- package/out-tsc/src/select/Select.js +198 -38
- package/out-tsc/src/select/Select.js.map +1 -1
- package/out-tsc/src/webchat/WebChat.js +5 -2
- package/out-tsc/src/webchat/WebChat.js.map +1 -1
- package/out-tsc/test/temba-flow-editor-node.test.js +273 -0
- package/out-tsc/test/temba-flow-editor-node.test.js.map +1 -0
- package/out-tsc/test/temba-flow-editor.test.js +244 -0
- package/out-tsc/test/temba-flow-editor.test.js.map +1 -0
- package/out-tsc/test/temba-flow-plumber.test.js +145 -0
- package/out-tsc/test/temba-flow-plumber.test.js.map +1 -0
- package/out-tsc/test/temba-flow-render.test.js +171 -0
- package/out-tsc/test/temba-flow-render.test.js.map +1 -0
- package/out-tsc/test/temba-omnibox.test.js +2 -3
- package/out-tsc/test/temba-omnibox.test.js.map +1 -1
- package/out-tsc/test/temba-select.test.js +134 -53
- package/out-tsc/test/temba-select.test.js.map +1 -1
- package/out-tsc/test/temba-sortable-list.test.js +91 -15
- package/out-tsc/test/temba-sortable-list.test.js.map +1 -1
- package/out-tsc/test/temba-webchat-lightbox-fix.test.js +42 -0
- package/out-tsc/test/temba-webchat-lightbox-fix.test.js.map +1 -0
- package/out-tsc/test/utils.test.js +30 -0
- package/out-tsc/test/utils.test.js.map +1 -1
- package/package.json +1 -1
- package/screenshots/truth/flow/editor-basic.png +0 -0
- package/screenshots/truth/list/fields-dragging.png +0 -0
- package/screenshots/truth/list/sortable-dragging.png +0 -0
- package/screenshots/truth/list/sortable-dropped.png +0 -0
- package/screenshots/truth/list/sortable.png +0 -0
- package/screenshots/truth/omnibox/selected.png +0 -0
- package/screenshots/truth/select/disabled-multi-selection.png +0 -0
- package/screenshots/truth/select/disabled-selection.png +0 -0
- package/screenshots/truth/select/disabled.png +0 -0
- package/screenshots/truth/select/embedded.png +0 -0
- package/screenshots/truth/select/empty-options.png +0 -0
- package/screenshots/truth/select/expression-selected.png +0 -0
- package/screenshots/truth/select/expressions.png +0 -0
- package/screenshots/truth/select/functions.png +0 -0
- package/screenshots/truth/select/local-options.png +0 -0
- package/screenshots/truth/select/multi-reorder-final.png +0 -0
- package/screenshots/truth/select/multi-reorder-initial.png +0 -0
- package/screenshots/truth/select/multi-with-endpoint.png +0 -0
- package/screenshots/truth/select/multiple-initial-values.png +0 -0
- package/screenshots/truth/select/remote-options.png +0 -0
- package/screenshots/truth/select/search-enabled.png +0 -0
- package/screenshots/truth/select/search-multi-no-matches.png +0 -0
- package/screenshots/truth/select/search-selected-focus.png +0 -0
- package/screenshots/truth/select/search-selected.png +0 -0
- package/screenshots/truth/select/search-with-selected.png +0 -0
- package/screenshots/truth/select/searching.png +0 -0
- package/screenshots/truth/select/selected-multi-maxitems-reached.png +0 -0
- package/screenshots/truth/select/selected-multi.png +0 -0
- package/screenshots/truth/select/selected-single.png +0 -0
- package/screenshots/truth/select/selection-clearable.png +0 -0
- package/screenshots/truth/select/static-initial-value.png +0 -0
- package/screenshots/truth/select/static-initial-via-selected.png +0 -0
- package/screenshots/truth/select/truncated-selection.png +0 -0
- package/screenshots/truth/select/with-placeholder.png +0 -0
- package/screenshots/truth/select/without-placeholder.png +0 -0
- package/screenshots/truth/templates/default.png +0 -0
- package/screenshots/truth/templates/unapproved.png +0 -0
- package/src/fields/FieldManager.ts +30 -38
- package/src/list/SortableList.ts +291 -67
- package/src/omnibox/Omnibox.ts +1 -1
- package/src/select/Select.ts +213 -42
- package/src/webchat/WebChat.ts +5 -2
- package/test/temba-flow-editor-node.test.ts +344 -0
- package/test/temba-flow-editor.test.ts +301 -0
- package/test/temba-flow-plumber.test.ts +189 -0
- package/test/temba-flow-render.test.ts +220 -0
- package/test/temba-omnibox.test.ts +2 -3
- package/test/temba-select.test.ts +180 -79
- package/test/temba-sortable-list.test.ts +108 -15
- package/test/temba-webchat-lightbox-fix.test.ts +57 -0
- package/test/utils.test.ts +52 -0
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import * as sinon from 'sinon';
|
|
1
|
+
import Sinon, * as sinon from 'sinon';
|
|
2
2
|
import { fixture, expect, assert } from '@open-wc/testing';
|
|
3
3
|
import { useFakeTimers } from 'sinon';
|
|
4
4
|
import { Options } from '../src/options/Options';
|
|
5
5
|
import { Select, SelectOption } from '../src/select/Select';
|
|
6
6
|
import {
|
|
7
7
|
assertScreenshot,
|
|
8
|
-
checkTimers,
|
|
9
8
|
getClip,
|
|
9
|
+
getOptions,
|
|
10
10
|
loadStore,
|
|
11
|
-
|
|
11
|
+
openAndClick,
|
|
12
|
+
openSelect
|
|
12
13
|
} from './utils.test';
|
|
13
|
-
import { CustomEventType } from '../src/interfaces';
|
|
14
14
|
|
|
15
15
|
const colors = [
|
|
16
16
|
{ name: 'Red', value: '0' },
|
|
@@ -20,7 +20,7 @@ const colors = [
|
|
|
20
20
|
|
|
21
21
|
export const createSelect = async (clock, def: string) => {
|
|
22
22
|
const parentNode = document.createElement('div');
|
|
23
|
-
parentNode.setAttribute('style', 'width:
|
|
23
|
+
parentNode.setAttribute('style', 'width: 400px;');
|
|
24
24
|
|
|
25
25
|
const select: Select<SelectOption> = await fixture(def, { parentNode });
|
|
26
26
|
clock.runAll();
|
|
@@ -28,66 +28,10 @@ export const createSelect = async (clock, def: string) => {
|
|
|
28
28
|
return select;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
export const open = async (clock, select: Select<SelectOption>) => {
|
|
32
|
-
if (!select.endpoint) {
|
|
33
|
-
await mouseClickElement(select);
|
|
34
|
-
await clock.runAll();
|
|
35
|
-
await clock.runAll();
|
|
36
|
-
return select;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const promise = new Promise<Select<SelectOption>>((resolve) => {
|
|
40
|
-
select.addEventListener(
|
|
41
|
-
CustomEventType.FetchComplete,
|
|
42
|
-
async () => {
|
|
43
|
-
await clock.runAll();
|
|
44
|
-
resolve(select);
|
|
45
|
-
},
|
|
46
|
-
{ once: true }
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
await mouseClickElement(select);
|
|
51
|
-
await clock.runAll();
|
|
52
|
-
|
|
53
|
-
return promise;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
31
|
export const clear = (select: Select<SelectOption>) => {
|
|
57
32
|
(select.shadowRoot.querySelector('.clear-button') as HTMLDivElement).click();
|
|
58
33
|
};
|
|
59
34
|
|
|
60
|
-
export const getOptions = (select: Select<SelectOption>): Options => {
|
|
61
|
-
return select.shadowRoot.querySelector('temba-options[visible]');
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const clickOption = async (
|
|
65
|
-
clock: any,
|
|
66
|
-
select: Select<SelectOption>,
|
|
67
|
-
index: number
|
|
68
|
-
) => {
|
|
69
|
-
const options = getOptions(select);
|
|
70
|
-
const option = options.shadowRoot.querySelector(
|
|
71
|
-
`[data-option-index="${index}"]`
|
|
72
|
-
) as HTMLDivElement;
|
|
73
|
-
|
|
74
|
-
await mouseClickElement(option);
|
|
75
|
-
await options.updateComplete;
|
|
76
|
-
await select.updateComplete;
|
|
77
|
-
await clock.runAll();
|
|
78
|
-
|
|
79
|
-
checkTimers(clock);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export const openAndClick = async (
|
|
83
|
-
clock: any,
|
|
84
|
-
select: Select<SelectOption>,
|
|
85
|
-
index: number
|
|
86
|
-
) => {
|
|
87
|
-
await open(clock, select);
|
|
88
|
-
await clickOption(clock, select, index);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
35
|
export const getSelectHTML = (
|
|
92
36
|
options: SelectOption[] = colors,
|
|
93
37
|
attrs: any = { placeholder: 'Select a color', name: 'color' },
|
|
@@ -143,7 +87,7 @@ const getClipWithOptions = (select: Select<any>) => {
|
|
|
143
87
|
};
|
|
144
88
|
|
|
145
89
|
describe('temba-select', () => {
|
|
146
|
-
let clock:
|
|
90
|
+
let clock: Sinon.SinonFakeTimers;
|
|
147
91
|
beforeEach(function () {
|
|
148
92
|
clock = useFakeTimers();
|
|
149
93
|
clock.tick(400);
|
|
@@ -190,7 +134,7 @@ describe('temba-select', () => {
|
|
|
190
134
|
expect(select.disabled).to.equal(true);
|
|
191
135
|
|
|
192
136
|
// make sure we can't select anymore
|
|
193
|
-
await
|
|
137
|
+
await openSelect(clock, select);
|
|
194
138
|
expect(select.isOpen()).to.equal(false);
|
|
195
139
|
await assertScreenshot('select/disabled-multi-selection', getClip(select));
|
|
196
140
|
});
|
|
@@ -211,7 +155,7 @@ describe('temba-select', () => {
|
|
|
211
155
|
|
|
212
156
|
it('shows options when opened', async () => {
|
|
213
157
|
const select = await createSelect(clock, getSelectHTML());
|
|
214
|
-
await
|
|
158
|
+
await openSelect(clock, select);
|
|
215
159
|
const options = getOptions(select);
|
|
216
160
|
assert.instanceOf(options, Options);
|
|
217
161
|
|
|
@@ -241,7 +185,7 @@ describe('temba-select', () => {
|
|
|
241
185
|
);
|
|
242
186
|
|
|
243
187
|
// attempt to open the select with no options
|
|
244
|
-
await
|
|
188
|
+
await openSelect(clock, select);
|
|
245
189
|
|
|
246
190
|
// should show options dropdown even though there are no options
|
|
247
191
|
const options = getOptions(select);
|
|
@@ -297,13 +241,13 @@ describe('temba-select', () => {
|
|
|
297
241
|
expect(select.values[0].name).to.equal('Green');
|
|
298
242
|
|
|
299
243
|
// for single selection our current selection should be in the list and focused
|
|
300
|
-
await
|
|
244
|
+
await openSelect(clock, select);
|
|
301
245
|
assert.equal(select.cursorIndex, 1);
|
|
302
246
|
assert.equal(select.visibleOptions.length, 3);
|
|
303
247
|
|
|
304
248
|
// now lets do a search, we should see our selection (green) and one other (red)
|
|
305
249
|
await typeInto('temba-select', 're', false);
|
|
306
|
-
await
|
|
250
|
+
await openSelect(clock, select);
|
|
307
251
|
assert.equal(select.visibleOptions.length, 2);
|
|
308
252
|
|
|
309
253
|
await assertScreenshot(
|
|
@@ -369,7 +313,7 @@ describe('temba-select', () => {
|
|
|
369
313
|
assert(changeEvent.called, 'change event not fired');
|
|
370
314
|
|
|
371
315
|
changeEvent.resetHistory();
|
|
372
|
-
await
|
|
316
|
+
await openSelect(clock, select);
|
|
373
317
|
assert.equal(select.visibleOptions.length, 0);
|
|
374
318
|
assert(!changeEvent.called, 'change event should not be fired');
|
|
375
319
|
|
|
@@ -404,6 +348,163 @@ describe('temba-select', () => {
|
|
|
404
348
|
});
|
|
405
349
|
});
|
|
406
350
|
|
|
351
|
+
describe('drag and drop reordering', () => {
|
|
352
|
+
it('handles drag and drop with swap-based logic', async () => {
|
|
353
|
+
const select = await createSelect(
|
|
354
|
+
clock,
|
|
355
|
+
getSelectHTML(
|
|
356
|
+
[
|
|
357
|
+
{ name: 'Red', value: '0', selected: true },
|
|
358
|
+
{ name: 'Green', value: '1', selected: true },
|
|
359
|
+
{ name: 'Blue', value: '2', selected: true }
|
|
360
|
+
],
|
|
361
|
+
{
|
|
362
|
+
placeholder: 'Select colors',
|
|
363
|
+
multi: true
|
|
364
|
+
}
|
|
365
|
+
)
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
// Verify initial order: Red, Green, Blue
|
|
369
|
+
expect(select.values.length).to.equal(3);
|
|
370
|
+
expect(select.values[0].name).to.equal('Red');
|
|
371
|
+
expect(select.values[1].name).to.equal('Green');
|
|
372
|
+
expect(select.values[2].name).to.equal('Blue');
|
|
373
|
+
|
|
374
|
+
const sortableList = select.shadowRoot.querySelector(
|
|
375
|
+
'temba-sortable-list'
|
|
376
|
+
);
|
|
377
|
+
expect(sortableList).to.not.be.null;
|
|
378
|
+
|
|
379
|
+
// Example 1: Pick up Blue (index 2), drop between Red and Green
|
|
380
|
+
// Expected result: Red, Blue, Green (swap [1,2])
|
|
381
|
+
const blueItem = sortableList.querySelector('#selected-2');
|
|
382
|
+
const greenItem = sortableList.querySelector('#selected-1');
|
|
383
|
+
expect(blueItem).to.not.be.null;
|
|
384
|
+
expect(greenItem).to.not.be.null;
|
|
385
|
+
|
|
386
|
+
const blueBounds = blueItem.getBoundingClientRect();
|
|
387
|
+
const greenBounds = greenItem.getBoundingClientRect();
|
|
388
|
+
|
|
389
|
+
// Start drag from Blue item
|
|
390
|
+
await moveMouse(blueBounds.left + 10, blueBounds.top + 10);
|
|
391
|
+
await mouseDown();
|
|
392
|
+
|
|
393
|
+
// Drag to position between Red and Green (left side of Green)
|
|
394
|
+
await moveMouse(greenBounds.left - 5, greenBounds.top + 10);
|
|
395
|
+
await waitFor(100);
|
|
396
|
+
await mouseUp();
|
|
397
|
+
clock.runAll();
|
|
398
|
+
|
|
399
|
+
// Verify result: Red, Blue, Green (Green and Blue swapped)
|
|
400
|
+
expect(select.values.length).to.equal(3);
|
|
401
|
+
expect(select.values[0].name).to.equal('Red');
|
|
402
|
+
expect(select.values[1].name).to.equal('Blue');
|
|
403
|
+
expect(select.values[2].name).to.equal('Green');
|
|
404
|
+
|
|
405
|
+
// Reset for next test
|
|
406
|
+
select.values = [
|
|
407
|
+
{ name: 'Red', value: '0', selected: true },
|
|
408
|
+
{ name: 'Green', value: '1', selected: true },
|
|
409
|
+
{ name: 'Blue', value: '2', selected: true }
|
|
410
|
+
];
|
|
411
|
+
await select.updateComplete;
|
|
412
|
+
|
|
413
|
+
// Example 2: Pick up Red (index 0), drop at end
|
|
414
|
+
// Expected result: Green, Blue, Red (swap [0,2])
|
|
415
|
+
const redItem = sortableList.querySelector('#selected-0');
|
|
416
|
+
const redBounds = redItem.getBoundingClientRect();
|
|
417
|
+
const blueItemBounds = sortableList
|
|
418
|
+
.querySelector('#selected-2')
|
|
419
|
+
.getBoundingClientRect();
|
|
420
|
+
|
|
421
|
+
// Start drag from Red item
|
|
422
|
+
await moveMouse(redBounds.left + 10, redBounds.top + 10);
|
|
423
|
+
await mouseDown();
|
|
424
|
+
|
|
425
|
+
// Drag to end position (right side of Blue)
|
|
426
|
+
await moveMouse(blueItemBounds.right + 5, blueItemBounds.top + 10);
|
|
427
|
+
await waitFor(100);
|
|
428
|
+
await mouseUp();
|
|
429
|
+
clock.runAll();
|
|
430
|
+
|
|
431
|
+
// Verify result: Green, Blue, Red (Red and Blue swapped)
|
|
432
|
+
expect(select.values.length).to.equal(3);
|
|
433
|
+
expect(select.values[0].name).to.equal('Green');
|
|
434
|
+
expect(select.values[1].name).to.equal('Blue');
|
|
435
|
+
expect(select.values[2].name).to.equal('Red');
|
|
436
|
+
|
|
437
|
+
// Reset for next test
|
|
438
|
+
select.values = [
|
|
439
|
+
{ name: 'Red', value: '0', selected: true },
|
|
440
|
+
{ name: 'Green', value: '1', selected: true },
|
|
441
|
+
{ name: 'Blue', value: '2', selected: true }
|
|
442
|
+
];
|
|
443
|
+
await select.updateComplete;
|
|
444
|
+
|
|
445
|
+
// Example 3: Pick up Green (index 1), drop at same position
|
|
446
|
+
// Expected result: No change, no event
|
|
447
|
+
const greenItemNew = sortableList.querySelector('#selected-1');
|
|
448
|
+
const greenBoundsNew = greenItemNew.getBoundingClientRect();
|
|
449
|
+
|
|
450
|
+
// Start drag from Green item
|
|
451
|
+
await moveMouse(greenBoundsNew.left + 10, greenBoundsNew.top + 10);
|
|
452
|
+
await mouseDown();
|
|
453
|
+
|
|
454
|
+
// Drag slightly but return to same position
|
|
455
|
+
await moveMouse(greenBoundsNew.left + 15, greenBoundsNew.top + 10);
|
|
456
|
+
await moveMouse(greenBoundsNew.left + 10, greenBoundsNew.top + 10);
|
|
457
|
+
await waitFor(100);
|
|
458
|
+
await mouseUp();
|
|
459
|
+
clock.runAll();
|
|
460
|
+
|
|
461
|
+
// Verify result: No change
|
|
462
|
+
expect(select.values.length).to.equal(3);
|
|
463
|
+
expect(select.values[0].name).to.equal('Red');
|
|
464
|
+
expect(select.values[1].name).to.equal('Green');
|
|
465
|
+
expect(select.values[2].name).to.equal('Blue');
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it('does not show sortable list for single item', async () => {
|
|
469
|
+
const select = await createSelect(
|
|
470
|
+
clock,
|
|
471
|
+
getSelectHTML([{ name: 'Red', value: '0', selected: true }], {
|
|
472
|
+
placeholder: 'Select a color',
|
|
473
|
+
multi: true
|
|
474
|
+
})
|
|
475
|
+
);
|
|
476
|
+
|
|
477
|
+
// Should not have a sortable list with only one item
|
|
478
|
+
const sortableList = select.shadowRoot.querySelector(
|
|
479
|
+
'temba-sortable-list'
|
|
480
|
+
);
|
|
481
|
+
expect(sortableList).to.be.null;
|
|
482
|
+
|
|
483
|
+
// Should still show the selected item normally
|
|
484
|
+
expect(select.values.length).to.equal(1);
|
|
485
|
+
expect(select.values[0].name).to.equal('Red');
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
it('does not show sortable list for non-multi select', async () => {
|
|
489
|
+
const select = await createSelect(
|
|
490
|
+
clock,
|
|
491
|
+
getSelectHTML([{ name: 'Red', value: '0', selected: true }], {
|
|
492
|
+
placeholder: 'Select a color',
|
|
493
|
+
multi: false
|
|
494
|
+
})
|
|
495
|
+
);
|
|
496
|
+
|
|
497
|
+
// Should not have a sortable list for single select
|
|
498
|
+
const sortableList = select.shadowRoot.querySelector(
|
|
499
|
+
'temba-sortable-list'
|
|
500
|
+
);
|
|
501
|
+
expect(sortableList).to.be.null;
|
|
502
|
+
|
|
503
|
+
expect(select.values.length).to.equal(1);
|
|
504
|
+
expect(select.values[0].name).to.equal('Red');
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
|
|
407
508
|
describe('static options', () => {
|
|
408
509
|
it('accepts an initial value', async () => {
|
|
409
510
|
const select = await createSelect(
|
|
@@ -434,7 +535,7 @@ describe('temba-select', () => {
|
|
|
434
535
|
})
|
|
435
536
|
);
|
|
436
537
|
|
|
437
|
-
await
|
|
538
|
+
await openSelect(clock, select);
|
|
438
539
|
await assertScreenshot(
|
|
439
540
|
'select/remote-options',
|
|
440
541
|
getClipWithOptions(select)
|
|
@@ -453,7 +554,7 @@ describe('temba-select', () => {
|
|
|
453
554
|
);
|
|
454
555
|
|
|
455
556
|
await typeInto('temba-select', 're', false);
|
|
456
|
-
await
|
|
557
|
+
await openSelect(clock, select);
|
|
457
558
|
assert.equal(select.visibleOptions.length, 2);
|
|
458
559
|
|
|
459
560
|
await assertScreenshot('select/searching', getClipWithOptions(select));
|
|
@@ -490,7 +591,7 @@ describe('temba-select', () => {
|
|
|
490
591
|
})
|
|
491
592
|
);
|
|
492
593
|
|
|
493
|
-
await
|
|
594
|
+
await openSelect(clock, select);
|
|
494
595
|
|
|
495
596
|
// should have all three pages visible right away
|
|
496
597
|
assert.equal(select.visibleOptions.length, 15);
|
|
@@ -508,14 +609,14 @@ describe('temba-select', () => {
|
|
|
508
609
|
);
|
|
509
610
|
|
|
510
611
|
// wait for updates from fetching three pages
|
|
511
|
-
await
|
|
612
|
+
await openSelect(clock, select);
|
|
512
613
|
assert.equal(select.visibleOptions.length, 15);
|
|
513
614
|
|
|
514
615
|
// close and reopen
|
|
515
616
|
select.blur();
|
|
516
617
|
await clock.tick(250);
|
|
517
618
|
|
|
518
|
-
await
|
|
619
|
+
await openSelect(clock, select);
|
|
519
620
|
assert.equal(select.visibleOptions.length, 15);
|
|
520
621
|
|
|
521
622
|
// close and reopen once more (previous bug failed on third opening)
|
|
@@ -536,7 +637,7 @@ describe('temba-select', () => {
|
|
|
536
637
|
);
|
|
537
638
|
|
|
538
639
|
await typeInto('temba-select', 'Hi there @contact', false);
|
|
539
|
-
await
|
|
640
|
+
await openSelect(clock, select);
|
|
540
641
|
|
|
541
642
|
assert.equal(select.completionOptions.length, 14);
|
|
542
643
|
await assertScreenshot('select/expressions', getClipWithOptions(select));
|
|
@@ -596,7 +697,7 @@ describe('temba-select', () => {
|
|
|
596
697
|
await openAndClick(clock, select, 1);
|
|
597
698
|
|
|
598
699
|
// now open and look at focus
|
|
599
|
-
await
|
|
700
|
+
await openSelect(clock, select);
|
|
600
701
|
await assertScreenshot(
|
|
601
702
|
'select/search-selected-focus',
|
|
602
703
|
getClipWithOptions(select)
|
|
@@ -616,11 +717,11 @@ describe('temba-select', () => {
|
|
|
616
717
|
// select the first option
|
|
617
718
|
await openAndClick(clock, select, 0);
|
|
618
719
|
await openAndClick(clock, select, 0);
|
|
619
|
-
await
|
|
720
|
+
await openSelect(clock, select);
|
|
620
721
|
|
|
621
722
|
// now lets do a search, we should see our selection (green) and one other (red)
|
|
622
723
|
await typeInto('temba-select', 're', false);
|
|
623
|
-
await
|
|
724
|
+
await openSelect(clock, select);
|
|
624
725
|
|
|
625
726
|
// should have two things selected and active query and no matching options
|
|
626
727
|
await assertScreenshot(
|
|
@@ -642,7 +743,7 @@ describe('temba-select', () => {
|
|
|
642
743
|
);
|
|
643
744
|
|
|
644
745
|
await typeInto('temba-select', 'look at @(max(m', false);
|
|
645
|
-
await
|
|
746
|
+
await openSelect(clock, select);
|
|
646
747
|
|
|
647
748
|
await assertScreenshot('select/functions', getClipWithOptions(select));
|
|
648
749
|
});
|
|
@@ -650,7 +751,7 @@ describe('temba-select', () => {
|
|
|
650
751
|
it('should truncate selection if necessesary', async () => {
|
|
651
752
|
const options = [
|
|
652
753
|
{
|
|
653
|
-
name: '
|
|
754
|
+
name: 'this_is_a_long_selection_to_make_sure_it_truncates_but_it_needs_to_be_longer',
|
|
654
755
|
value: '0'
|
|
655
756
|
}
|
|
656
757
|
];
|
|
@@ -3,52 +3,145 @@ import { html, TemplateResult } from 'lit';
|
|
|
3
3
|
import { CustomEventType } from '../src/interfaces';
|
|
4
4
|
import { SortableList } from '../src/list/SortableList';
|
|
5
5
|
import { assertScreenshot, getClip } from './utils.test';
|
|
6
|
+
import Sinon, { useFakeTimers } from 'sinon';
|
|
6
7
|
|
|
7
8
|
const BORING_LIST = html`
|
|
8
9
|
<temba-sortable-list>
|
|
9
|
-
<
|
|
10
|
-
|
|
10
|
+
<style>
|
|
11
|
+
.sortable {
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
text-align: center;
|
|
16
|
+
height: 20px;
|
|
17
|
+
}
|
|
18
|
+
</style>
|
|
19
|
+
<div class="sortable" id="chicken" style="">Chicken</div>
|
|
20
|
+
<div class="sortable" id="fish">Fish</div>
|
|
21
|
+
</temba-sortable-list>
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
const HORIZONTAL_LIST = html`
|
|
25
|
+
<temba-sortable-list horizontal>
|
|
26
|
+
<style>
|
|
27
|
+
.sortable {
|
|
28
|
+
display: flex;
|
|
29
|
+
align-items: center;
|
|
30
|
+
justify-content: center;
|
|
31
|
+
text-align: center;
|
|
32
|
+
height: 20px;
|
|
33
|
+
width: 50px;
|
|
34
|
+
}
|
|
35
|
+
</style>
|
|
36
|
+
<div class="sortable" id="red">Red</div>
|
|
37
|
+
<div class="sortable" id="blue">Blue</div>
|
|
38
|
+
<div class="sortable" id="green">Green</div>
|
|
11
39
|
</temba-sortable-list>
|
|
12
40
|
`;
|
|
13
41
|
|
|
14
42
|
const createSorter = async (def: TemplateResult) => {
|
|
15
43
|
const parentNode = document.createElement('div');
|
|
16
|
-
parentNode.setAttribute('style', 'width:
|
|
44
|
+
parentNode.setAttribute('style', 'width: 100px;');
|
|
17
45
|
return (await fixture(def, { parentNode })) as SortableList;
|
|
18
46
|
};
|
|
19
47
|
|
|
20
48
|
describe('temba-sortable-list', () => {
|
|
49
|
+
let clock: Sinon.SinonFakeTimers;
|
|
50
|
+
beforeEach(function () {
|
|
51
|
+
clock = useFakeTimers();
|
|
52
|
+
clock.runAll();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
afterEach(function () {
|
|
56
|
+
clock.restore();
|
|
57
|
+
});
|
|
58
|
+
|
|
21
59
|
it('renders default', async () => {
|
|
22
60
|
const list: SortableList = await createSorter(BORING_LIST);
|
|
23
61
|
await assertScreenshot('list/sortable', getClip(list));
|
|
24
62
|
});
|
|
25
63
|
|
|
26
|
-
it('
|
|
64
|
+
it('can get ids of sortable elements', async () => {
|
|
27
65
|
const list: SortableList = await createSorter(BORING_LIST);
|
|
28
|
-
|
|
29
|
-
|
|
66
|
+
await list.updateComplete;
|
|
67
|
+
|
|
68
|
+
const ids = list.getIds();
|
|
69
|
+
expect(ids).to.deep.equal(['chicken', 'fish']);
|
|
70
|
+
});
|
|
30
71
|
|
|
72
|
+
it('works with horizontal layout', async () => {
|
|
73
|
+
const list: SortableList = await createSorter(HORIZONTAL_LIST);
|
|
74
|
+
await list.updateComplete;
|
|
75
|
+
|
|
76
|
+
const ids = list.getIds();
|
|
77
|
+
expect(ids).to.deep.equal(['red', 'blue', 'green']);
|
|
78
|
+
|
|
79
|
+
// Test horizontal drag behavior
|
|
31
80
|
const bounds = list.getBoundingClientRect();
|
|
81
|
+
const orderChanged = oneEvent(list, CustomEventType.OrderChanged, false);
|
|
32
82
|
|
|
33
|
-
|
|
83
|
+
// Drag the first item (red) to after the second item (blue)
|
|
84
|
+
await moveMouse(bounds.left + 10, bounds.top + 10);
|
|
34
85
|
await mouseDown();
|
|
35
|
-
await moveMouse(bounds.left +
|
|
86
|
+
await moveMouse(bounds.left + 80, bounds.top + 10);
|
|
87
|
+
await mouseUp();
|
|
88
|
+
clock.runAll();
|
|
36
89
|
|
|
37
|
-
// we should fire an order changed event
|
|
38
90
|
const orderEvent = await orderChanged;
|
|
39
91
|
expect(orderEvent.detail).to.deep.equal({
|
|
40
|
-
|
|
41
|
-
to: 'chicken',
|
|
42
|
-
fromIdx: 1,
|
|
43
|
-
toIdx: 0
|
|
92
|
+
swap: [0, 2]
|
|
44
93
|
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('handles prepareGhost callback', async () => {
|
|
97
|
+
const list: SortableList = await createSorter(BORING_LIST);
|
|
98
|
+
let ghostPrepared = false;
|
|
99
|
+
|
|
100
|
+
list.prepareGhost = (ghost: HTMLElement) => {
|
|
101
|
+
ghostPrepared = true;
|
|
102
|
+
ghost.style.backgroundColor = 'red';
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const bounds = list.getBoundingClientRect();
|
|
106
|
+
|
|
107
|
+
// Start dragging to trigger ghost creation
|
|
108
|
+
await moveMouse(bounds.left + 20, bounds.bottom - 10);
|
|
109
|
+
await mouseDown();
|
|
110
|
+
await moveMouse(bounds.left + 30, bounds.bottom - 10);
|
|
111
|
+
|
|
112
|
+
expect(ghostPrepared).to.be.true;
|
|
113
|
+
|
|
114
|
+
// Clean up
|
|
115
|
+
await mouseUp();
|
|
116
|
+
clock.runAll();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('drags', async () => {
|
|
120
|
+
const list: SortableList = await createSorter(BORING_LIST);
|
|
121
|
+
const updated = oneEvent(list, 'change', false);
|
|
122
|
+
|
|
123
|
+
const bounds = list.getBoundingClientRect();
|
|
124
|
+
|
|
125
|
+
await moveMouse(bounds.left + 20, bounds.bottom - 10);
|
|
126
|
+
await mouseDown();
|
|
127
|
+
await moveMouse(bounds.left + 20, bounds.top + 5);
|
|
45
128
|
|
|
46
129
|
// should be hovered
|
|
47
130
|
await assertScreenshot('list/sortable-dragging', getClip(list));
|
|
48
131
|
|
|
49
|
-
// now lets drop
|
|
50
|
-
|
|
132
|
+
// now lets drop - this will fire the order changed event
|
|
133
|
+
const orderChanged = oneEvent(list, CustomEventType.OrderChanged, false);
|
|
51
134
|
await mouseUp();
|
|
135
|
+
clock.runAll();
|
|
136
|
+
await list.updateComplete;
|
|
137
|
+
clock.runAll();
|
|
138
|
+
|
|
139
|
+
// we should fire an order changed event on drop
|
|
140
|
+
const orderEvent = await orderChanged;
|
|
141
|
+
expect(orderEvent.detail).to.deep.equal({
|
|
142
|
+
swap: [1, 0]
|
|
143
|
+
});
|
|
144
|
+
|
|
52
145
|
await assertScreenshot('list/sortable-dropped', getClip(list));
|
|
53
146
|
|
|
54
147
|
// we should fire a change event
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { expect } from '@open-wc/testing';
|
|
2
|
+
import { WebChat } from '../src/webchat/WebChat';
|
|
3
|
+
import { getComponent } from './utils.test';
|
|
4
|
+
|
|
5
|
+
const getWebChat = async (attrs: any = {}) => {
|
|
6
|
+
const webChat = (await getComponent(
|
|
7
|
+
'temba-webchat',
|
|
8
|
+
attrs,
|
|
9
|
+
'',
|
|
10
|
+
400,
|
|
11
|
+
600
|
|
12
|
+
)) as WebChat;
|
|
13
|
+
return webChat;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
describe('WebChat Lightbox Fix', () => {
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
// Clean up any lightbox elements after each test
|
|
19
|
+
const lightboxes = document.querySelectorAll('temba-lightbox');
|
|
20
|
+
lightboxes.forEach((lightbox) => lightbox.remove());
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should only create one lightbox element even with multiple WebChat instances', async () => {
|
|
24
|
+
// Create first WebChat instance
|
|
25
|
+
await getWebChat({
|
|
26
|
+
channel: 'test-channel-1'
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Verify lightbox was created
|
|
30
|
+
let lightboxes = document.querySelectorAll('temba-lightbox');
|
|
31
|
+
expect(lightboxes.length).to.equal(1);
|
|
32
|
+
|
|
33
|
+
// Create second WebChat instance
|
|
34
|
+
await getWebChat({
|
|
35
|
+
channel: 'test-channel-2'
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Verify still only one lightbox exists
|
|
39
|
+
lightboxes = document.querySelectorAll('temba-lightbox');
|
|
40
|
+
expect(lightboxes.length).to.equal(1);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should not create lightbox if one already exists', async () => {
|
|
44
|
+
// Manually create a lightbox first
|
|
45
|
+
const existingLightbox = document.createElement('temba-lightbox');
|
|
46
|
+
document.body.appendChild(existingLightbox);
|
|
47
|
+
|
|
48
|
+
// Create WebChat instance
|
|
49
|
+
await getWebChat({
|
|
50
|
+
channel: 'test-channel'
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Verify still only one lightbox exists
|
|
54
|
+
const lightboxes = document.querySelectorAll('temba-lightbox');
|
|
55
|
+
expect(lightboxes.length).to.equal(1);
|
|
56
|
+
});
|
|
57
|
+
});
|
package/test/utils.test.ts
CHANGED
|
@@ -11,6 +11,8 @@ import { expect, fixture, html, assert, waitUntil } from '@open-wc/testing';
|
|
|
11
11
|
import MouseHelper from './MouseHelper';
|
|
12
12
|
import { Store } from '../src/store/Store';
|
|
13
13
|
import { replace, stub } from 'sinon';
|
|
14
|
+
import { Select, SelectOption } from '../src/select/Select';
|
|
15
|
+
import { Options } from '../src/options/Options';
|
|
14
16
|
|
|
15
17
|
export interface CodeMock {
|
|
16
18
|
endpoint: RegExp;
|
|
@@ -279,3 +281,53 @@ export const mockNow = (isodate: string) => {
|
|
|
279
281
|
return now;
|
|
280
282
|
});
|
|
281
283
|
};
|
|
284
|
+
|
|
285
|
+
export const getOptions = (select: Select<SelectOption>): Options => {
|
|
286
|
+
return select.shadowRoot.querySelector('temba-options[visible]');
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
export const clickOption = async (
|
|
290
|
+
clock: any,
|
|
291
|
+
select: Select<SelectOption>,
|
|
292
|
+
index: number
|
|
293
|
+
) => {
|
|
294
|
+
const options = getOptions(select);
|
|
295
|
+
const option = options.shadowRoot.querySelector(
|
|
296
|
+
`[data-option-index="${index}"]`
|
|
297
|
+
) as HTMLDivElement;
|
|
298
|
+
|
|
299
|
+
await mouseClickElement(option);
|
|
300
|
+
await options.updateComplete;
|
|
301
|
+
await select.updateComplete;
|
|
302
|
+
await clock.runAll();
|
|
303
|
+
|
|
304
|
+
checkTimers(clock);
|
|
305
|
+
};
|
|
306
|
+
export const openSelect = async (clock: any, select: Select<SelectOption>) => {
|
|
307
|
+
const container = select.shadowRoot.querySelector('.select-container');
|
|
308
|
+
container.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
|
309
|
+
|
|
310
|
+
clock.runAll();
|
|
311
|
+
|
|
312
|
+
// add more explicit waiting and clock ticks
|
|
313
|
+
await select.updateComplete;
|
|
314
|
+
clock.runAll();
|
|
315
|
+
|
|
316
|
+
// ensure options are visible before proceeding
|
|
317
|
+
await waitFor(100);
|
|
318
|
+
clock.runAll();
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
export const openAndClick = async (
|
|
322
|
+
clock: any,
|
|
323
|
+
select: Select<SelectOption>,
|
|
324
|
+
idx: number
|
|
325
|
+
) => {
|
|
326
|
+
await openSelect(clock, select);
|
|
327
|
+
|
|
328
|
+
// Add this line to ensure proper timing when running as part of a test suite
|
|
329
|
+
await select.updateComplete;
|
|
330
|
+
clock.tick(50); // Give extra time for options to render
|
|
331
|
+
|
|
332
|
+
await clickOption(clock, select, idx);
|
|
333
|
+
};
|