@triptease/tt-combobox 5.7.0 → 5.7.2

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.
@@ -1,664 +0,0 @@
1
- import { html } from 'lit';
2
- import { elementUpdated, expect, fixture, oneEvent } from '@open-wc/testing';
3
- import { TtCombobox } from '../src/index.js';
4
- import '../src/tt-combobox.js';
5
- import { TtOption } from '../src/tt-option/TtOption.js';
6
-
7
- describe('TtCombobox', () => {
8
- const getCombobox = (el: TtCombobox) => el.shadowRoot!.querySelector('[role="combobox"]') as HTMLInputElement;
9
-
10
- const comboboxPlaceholderText = (combobox: HTMLInputElement) => combobox.getAttribute('placeholder');
11
-
12
- const filterCombobox = (combobox: HTMLInputElement, text: string) => {
13
- combobox.value = text;
14
- combobox.dispatchEvent(new InputEvent('input', { bubbles: true, composed: true }));
15
- };
16
-
17
- it('Should render with the default placeholder text', async () => {
18
- const el = await fixture<TtCombobox>(
19
- html` <tt-combobox id="combobox">
20
- <span slot="label">Test combobox</span>
21
- <option slot="option" value="1">Option 1</option>
22
- <option slot="option" value="2">Option 2</option>
23
- <option slot="option" value="3">Option 3</option>
24
- </tt-combobox>`
25
- );
26
-
27
- const combobox = getCombobox(el);
28
-
29
- await expect(comboboxPlaceholderText(combobox)).to.equal('No options selected');
30
- });
31
-
32
- it('should render with the options visible when clicking the combobox', async () => {
33
- const el = await fixture<TtCombobox>(
34
- html` <tt-combobox id="combobox">
35
- <span slot="label">Test combobox</span>
36
- <option slot="option" value="1">Option 1</option>
37
- <option slot="option" value="2">Option 2</option>
38
- <option slot="option" value="3">Option 3</option>
39
- </tt-combobox>`
40
- );
41
-
42
- const combobox = getCombobox(el);
43
- combobox.click();
44
-
45
- const options = el.shadowRoot!.querySelectorAll('tt-option');
46
- await expect(options.length).to.equal(3);
47
- options.forEach((option) => {
48
- expect(option.checkVisibility()).to.be.true;
49
- });
50
- });
51
-
52
- it('should update the placeholder with the selected option', async () => {
53
- const el = await fixture<TtCombobox>(
54
- html` <tt-combobox id="combobox">
55
- <span slot="label">Test combobox</span>
56
- <option slot="option" value="1">Option 1</option>
57
- <option slot="option" value="2">Option 2</option>
58
- <option slot="option" value="3">Option 3</option>
59
- </tt-combobox>`
60
- );
61
-
62
- const combobox = getCombobox(el);
63
- combobox.click();
64
-
65
- const option = el.shadowRoot!.querySelector('tt-option[value="2"]') as HTMLLIElement;
66
- option.click();
67
- await elementUpdated(el);
68
- expect(comboboxPlaceholderText(combobox)).to.equal('Option 2');
69
- });
70
-
71
- it('should update the placeholder with the selected option when setting it via selectedValues', async () => {
72
- const el = await fixture<TtCombobox>(
73
- html` <tt-combobox id="combobox" multiselect>
74
- <span slot="label">Test combobox</span>
75
- <option slot="option" value="1">Option 1</option>
76
- <option slot="option" value="2">Option 2</option>
77
- <option slot="option" value="3">Option 3</option>
78
- </tt-combobox>`
79
- );
80
-
81
- const combobox = getCombobox(el);
82
- el.value = ['2'];
83
- await elementUpdated(el);
84
- await expect(comboboxPlaceholderText(combobox)).to.equal('Option 2');
85
- });
86
-
87
- it('should display select all option when multiselect is true and display-select-all is true, and select all options when clicked', async () => {
88
- const el = await fixture<TtCombobox>(
89
- html` <tt-combobox id="combobox" multiselect display-select-all>
90
- <span slot="label">Test combobox</span>
91
- <option slot="option" value="1">Option 1</option>
92
- <option slot="option" value="2">Option 2</option>
93
- <option slot="option" value="3">Option 3</option>
94
- </tt-combobox>`
95
- );
96
-
97
- const combobox = getCombobox(el);
98
- await combobox.click();
99
-
100
- const selectAll = el.shadowRoot!.querySelector('tt-option.select-all') as HTMLLIElement;
101
- expect(selectAll).to.exist;
102
-
103
- selectAll.click();
104
- await oneEvent(el, 'change');
105
-
106
- const options = el.shadowRoot!.querySelectorAll('tt-option');
107
- options.forEach((option) => {
108
- expect(option.selected).to.be.true;
109
- });
110
- });
111
-
112
- it('should display total selected count after filtering when options were selected before filtering', async () => {
113
- const el = await fixture<TtCombobox>(
114
- html` <tt-combobox id="combobox" multiselect>
115
- <span slot="label">Test combobox</span>
116
- <option slot="option" value="1">Option 1</option>
117
- <option slot="option" value="2">Option 2</option>
118
- <option slot="option" value="3">Option 3</option>
119
- </tt-combobox>`
120
- );
121
-
122
- const combobox = getCombobox(el);
123
- combobox.click();
124
- await elementUpdated(el);
125
-
126
- // Select options 1, 2, and 3 (all of them)
127
- const option1 = el.shadowRoot!.querySelector('tt-option[value="1"]') as HTMLLIElement;
128
- option1.click();
129
- await elementUpdated(el);
130
- const option2 = el.shadowRoot!.querySelector('tt-option[value="2"]') as HTMLLIElement;
131
- option2.click();
132
- await elementUpdated(el);
133
- const option3 = el.shadowRoot!.querySelector('tt-option[value="3"]') as HTMLLIElement;
134
- option3.click();
135
- await elementUpdated(el);
136
-
137
- // Should show 3 options selected
138
- expect(comboboxPlaceholderText(combobox)).to.equal('All options selected');
139
-
140
- // Now filter to show only "Option 1"
141
- filterCombobox(combobox, 'Option 1');
142
- await elementUpdated(el);
143
-
144
- // Should still show 3 options selected (not 1)
145
- expect(comboboxPlaceholderText(combobox)).to.equal('3 options selected');
146
- });
147
-
148
- it('should show correct count after clearing filter when only filtered options were selected', async () => {
149
- const el = await fixture<TtCombobox>(
150
- html` <tt-combobox id="combobox" multiselect>
151
- <span slot="label">Test combobox</span>
152
- <option slot="option" value="1">Option 1</option>
153
- <option slot="option" value="11">Option 11</option>
154
- <option slot="option" value="2">Option 2</option>
155
- <option slot="option" value="3">Option 3</option>
156
- <option slot="option" value="4">Option 4</option>
157
- <option slot="option" value="5">Option 5</option>
158
- </tt-combobox>`
159
- );
160
-
161
- const combobox = getCombobox(el);
162
- combobox.click();
163
- await elementUpdated(el);
164
-
165
- // Filter to show only 2 options (Option 1 and Option 11 match "1")
166
- filterCombobox(combobox, '1');
167
- await elementUpdated(el);
168
-
169
- // Select both visible filtered options
170
- const option1 = el.shadowRoot!.querySelector('tt-option[value="1"]') as HTMLLIElement;
171
- option1.click();
172
- await elementUpdated(el);
173
- const option11 = el.shadowRoot!.querySelector('tt-option[value="11"]') as HTMLLIElement;
174
- option11.click();
175
- await elementUpdated(el);
176
-
177
- // Verify 2 options selected while filter is active
178
- expect(comboboxPlaceholderText(combobox)).to.equal('2 options selected');
179
-
180
- // Clear the filter
181
- filterCombobox(combobox, '');
182
- await elementUpdated(el);
183
-
184
- // Should show "2 options selected", NOT "All options selected"
185
- // This is the critical test - when filter is cleared, it should count
186
- // all selected options (2), not say "all" just because all visible options
187
- // during filtering were selected
188
- expect(comboboxPlaceholderText(combobox)).to.equal('2 options selected');
189
- });
190
-
191
- it('should not allow a disabled option to be selected', async () => {
192
- const el = await fixture<TtCombobox>(
193
- html` <tt-combobox id="combobox">
194
- <span slot="label">Test combobox</span>
195
- <option slot="option" value="1">Option 1</option>
196
- <option slot="option" value="2" disabled>Option 2</option>
197
- <option slot="option" value="3">Option 3</option>
198
- </tt-combobox>`
199
- );
200
-
201
- const combobox = getCombobox(el);
202
- await combobox.click();
203
-
204
- await elementUpdated(el);
205
-
206
- const option = el.shadowRoot!.querySelector('tt-option[value="2"]') as TtOption;
207
-
208
- await expect(option.disabled).to.be.true;
209
- option.click();
210
-
211
- await elementUpdated(el);
212
-
213
- await expect(comboboxPlaceholderText(combobox)).to.equal('No options selected');
214
- await expect(el.value).to.deep.equal([]);
215
- });
216
-
217
- it('should disable the combobox when the disabled attribute is set', async () => {
218
- const el = await fixture<TtCombobox>(
219
- html` <tt-combobox id="combobox" disabled>
220
- <span slot="label">Test combobox</span>
221
- <option slot="option" value="1">Option 1</option>
222
- <option slot="option" value="2">Option 2</option>
223
- <option slot="option" value="3">Option 3</option>
224
- </tt-combobox>`
225
- );
226
-
227
- const combobox = getCombobox(el);
228
- expect(combobox.disabled).to.be.true;
229
- });
230
-
231
- xit('should render the error message', async () => {
232
- const el = await fixture<TtCombobox>(
233
- html` <tt-combobox id="combobox">
234
- <span slot="label">Test combobox</span>
235
- <option slot="option" value="1">Option 1</option>
236
- <option slot="option" value="2">Option 2</option>
237
- <option slot="option" value="3">Option 3</option>
238
- <span slot="error">There was an error</span>
239
- </tt-combobox>`
240
- );
241
- await elementUpdated(el);
242
- const combobox = getCombobox(el);
243
- const ariaInvalid = combobox.getAttribute('aria-invalid');
244
- expect(ariaInvalid).to.equal('false');
245
-
246
- const errorMessage = el.shadowRoot!.querySelector('[id="error-msg-combobox"]');
247
- expect(errorMessage!.checkVisibility()).to.be.false;
248
-
249
- el.invalid = true;
250
-
251
- await elementUpdated(el);
252
-
253
- expect(combobox).to.have.attribute('aria-invalid');
254
- expect(errorMessage!.checkVisibility()).to.be.true;
255
- });
256
-
257
- it('should call the event handler when the value changes', async () => {
258
- const el = await fixture<TtCombobox>(
259
- html` <tt-combobox id="combobox">
260
- <span slot="label">Test combobox</span>
261
- <option slot="option" value="1">Option 1</option>
262
- <option slot="option" value="2">Option 2</option>
263
- <option slot="option" value="3">Option 3</option>
264
- </tt-combobox>`
265
- );
266
-
267
- const combobox = getCombobox(el);
268
-
269
- combobox.click();
270
-
271
- const option = el.shadowRoot!.querySelector('tt-option[value="2"]') as HTMLLIElement;
272
- option.click();
273
-
274
- const event = await oneEvent(el, 'change');
275
- const eventValue = (event.target! as HTMLLIElement).value;
276
- expect(eventValue).to.be.an('array').that.includes('2');
277
- });
278
-
279
- it("Should prevent the form from submitting when it's required and no option is selected", async () => {
280
- const el = await fixture<TtCombobox>(
281
- html` <tt-combobox id="combobox" required>
282
- <span slot="label">Test combobox</span>
283
- <option slot="option" value="1">Option 1</option>
284
- <option slot="option" value="2">Option 2</option>
285
- <option slot="option" value="3">Option 3</option>
286
- </tt-combobox>`
287
- );
288
-
289
- const form = document.createElement('form');
290
- form.appendChild(el);
291
- document.body.appendChild(form);
292
-
293
- const submitEvent = new Event('submit', { bubbles: true });
294
- form.dispatchEvent(submitEvent);
295
-
296
- await elementUpdated(el);
297
-
298
- expect(form.checkValidity()).to.be.false;
299
- });
300
-
301
- it('passes the a11y audit', async () => {
302
- const el = await fixture<TtCombobox>(html` <tt-combobox></tt-combobox>`);
303
-
304
- await expect(el).shadowDom.to.be.accessible();
305
- });
306
-
307
- it('should allow hidden options', async () => {
308
- const el = await fixture<TtCombobox>(
309
- html` <tt-combobox id="combobox" multiselect display-select-all>
310
- <span slot="label">Test combobox</span>
311
- <option slot="option" value="1">Option 1</option>
312
- <option slot="option" value="2">Option 2</option>
313
- <option slot="option" value="3">Option 3</option>
314
- <option slot="option" value="4" hidden>Option 4</option>
315
- </tt-combobox>`
316
- );
317
-
318
- const combobox = getCombobox(el);
319
- combobox.click();
320
-
321
- await combobox.click();
322
-
323
- const selectAll = el.shadowRoot!.querySelector('tt-option.select-all') as TtOption;
324
- expect(selectAll).to.exist;
325
-
326
- selectAll.click();
327
- const changeEvent = await oneEvent<InputEvent>(el, 'change');
328
-
329
- expect(changeEvent).to.exist;
330
- expect((changeEvent.target as TtCombobox).value).to.deep.equal(['1', '2', '3', '4']);
331
-
332
- const hiddenOption = el.shadowRoot!.querySelector('tt-option[value="4"][hidden]') as TtOption;
333
- expect(hiddenOption).to.exist;
334
- });
335
-
336
- it('should not include hidden options in the placeholder text', async () => {
337
- const el = await fixture<TtCombobox>(
338
- html` <tt-combobox id="combobox" multiselect display-select-all>
339
- <span slot="label">Test combobox</span>
340
- <option slot="option" value="1">Option 1</option>
341
- <option slot="option" value="2">Option 2</option>
342
- <option slot="option" value="3">Option 3</option>
343
- <option slot="option" value="4" hidden>Option 4</option>
344
- </tt-combobox>`
345
- );
346
-
347
- const combobox = getCombobox(el);
348
- combobox.click();
349
-
350
- await combobox.click();
351
-
352
- const selectAll = el.shadowRoot!.querySelector('tt-option.select-all') as TtOption;
353
- expect(selectAll).to.exist;
354
-
355
- selectAll.click();
356
-
357
- (<TtOption>el.shadowRoot!.querySelector('tt-option[value="3"]')).click();
358
-
359
- const changeEvent = await oneEvent<InputEvent>(el, 'change');
360
-
361
- expect(changeEvent).to.exist;
362
- expect((changeEvent.target as TtCombobox).value).to.deep.equal(['1', '2', '4']);
363
-
364
- expect(combobox.placeholder).to.equal('2 options selected');
365
- });
366
-
367
- it('should close after selecting an option when multiselect is false', async () => {
368
- const el = await fixture<TtCombobox>(
369
- html` <tt-combobox id="combobox">
370
- <span slot="label">Test combobox</span>
371
- <option slot="option" value="1">Option 1</option>
372
- <option slot="option" value="2">Option 2</option>
373
- <option slot="option" value="3">Option 3</option>
374
- </tt-combobox>`
375
- );
376
-
377
- const combobox = getCombobox(el);
378
- combobox.click();
379
-
380
- let options = el.shadowRoot!.querySelectorAll('tt-option');
381
- expect(options.length).to.equal(3);
382
-
383
- const option = el.shadowRoot!.querySelector('tt-option[value="2"]') as HTMLLIElement;
384
- option.click();
385
- await elementUpdated(el);
386
-
387
- options = el.shadowRoot!.querySelectorAll('tt-option');
388
- options.forEach((o) => {
389
- expect(o.checkVisibility()).to.be.false;
390
- });
391
- });
392
-
393
- it('should include selected options in the value', async () => {
394
- const el = await fixture<TtCombobox>(
395
- html` <tt-combobox id="combobox" multiselect display-select-all>
396
- <span slot="label">Test combobox</span>
397
- <option slot="option" value="1">Option 1</option>
398
- <option slot="option" value="2">Option 2</option>
399
- <option slot="option" value="3">Option 3</option>
400
- <option slot="option" value="4" selected>Option 4</option>
401
- </tt-combobox>`
402
- );
403
-
404
- await elementUpdated(el);
405
- expect(el.value).to.deep.equal(['4']);
406
-
407
- const option = el.querySelector('option[value="3"]') as HTMLOptionElement;
408
- option.setAttribute('selected', 'true');
409
-
410
- await elementUpdated(el);
411
- await elementUpdated(el); // We have to update twice because we handle the value change, and then rerender
412
-
413
- expect(el.value).to.be.an('array').that.includes('4').and.includes('3');
414
- });
415
-
416
- it('should accept a JSON string as value', async () => {
417
- const value = ['1', '2'];
418
-
419
- const el = await fixture<TtCombobox>(
420
- html` <tt-combobox id="combobox" multiselect display-select-all value="${JSON.stringify(value)}">
421
- <span slot="label">Test combobox</span>
422
- <option slot="option" value="1">Option 1</option>
423
- <option slot="option" value="2">Option 2</option>
424
- <option slot="option" value="3">Option 3</option>
425
- </tt-combobox>`
426
- );
427
-
428
- await expect(el.value).to.deep.equal(value);
429
- const selectedOptions = el.shadowRoot!.querySelectorAll('tt-option[selected]') as NodeListOf<TtOption>;
430
- expect(selectedOptions).to.have.lengthOf(2);
431
- await expect(Array.from(selectedOptions).map((option) => option.value)).to.deep.equal(value);
432
- });
433
-
434
- it('should display the passed placeholder when all options are selected', async () => {
435
- const el = await fixture<TtCombobox>(
436
- html` <tt-combobox id="combobox" multiselect display-select-all select-all-placeholder="Everything">
437
- <span slot="label">Test combobox</span>
438
- <option slot="option" value="1">Option 1</option>
439
- <option slot="option" value="2">Option 2</option>
440
- <option slot="option" value="3">Option 3</option>
441
- </tt-combobox>`
442
- );
443
-
444
- const combobox = getCombobox(el);
445
- combobox.click();
446
-
447
- const selectAll = el.shadowRoot!.querySelector('tt-option.select-all') as TtOption;
448
- expect(selectAll).to.exist;
449
-
450
- selectAll.click();
451
- await oneEvent(el, 'change');
452
-
453
- expect(comboboxPlaceholderText(combobox)).to.equal('Everything');
454
- });
455
-
456
- it('should render selected options correctly after filtering and deselecting', async () => {
457
- const el = await fixture<TtCombobox>(
458
- html` <tt-combobox id="combobox" multiselect display-select-all select-all-placeholder="Everything">
459
- <span slot="label">Test combobox</span>
460
- <option slot="option" value="1">Option 1</option>
461
- <option slot="option" value="2">Option 2</option>
462
- <option slot="option" value="3">Option 3</option>
463
- </tt-combobox>`
464
- );
465
-
466
- const combobox = getCombobox(el);
467
- combobox.click();
468
-
469
- // Select all options
470
- const selectAll = el.shadowRoot!.querySelector('tt-option.select-all') as TtOption;
471
- expect(selectAll).to.exist;
472
-
473
- selectAll.click();
474
- await elementUpdated(el);
475
-
476
- // Filter options by typing "Option 1"
477
- combobox.value = 'Option 1';
478
- combobox.dispatchEvent(new InputEvent('input', { bubbles: true, composed: true }));
479
- await elementUpdated(el);
480
-
481
- // Deselect "Option 1"
482
- const option1 = el.shadowRoot!.querySelector('tt-option[value="1"]') as TtOption;
483
- expect(option1).to.exist;
484
-
485
- option1.click();
486
- await elementUpdated(el);
487
-
488
- // Clear the filter
489
- combobox.value = '';
490
- combobox.dispatchEvent(new InputEvent('input', { bubbles: true, composed: true }));
491
- await elementUpdated(el);
492
-
493
- // Verify selected options
494
- const selectedOptions = el.shadowRoot!.querySelectorAll('tt-option[selected]');
495
- expect(selectedOptions).to.have.lengthOf(2);
496
- });
497
-
498
- it('should only add the visible options to the value when select all is clicked after filtering', async () => {
499
- const el = await fixture<TtCombobox>(
500
- html` <tt-combobox id="combobox" multiselect display-select-all select-all-placeholder="Everything">
501
- <span slot="label">Test combobox</span>
502
- <option slot="option" value="1">Option 1</option>
503
- <option slot="option" value="2">Option 2</option>
504
- <option slot="option" value="3">Option 3</option>
505
- </tt-combobox>`
506
- );
507
-
508
- // Open the combobox
509
- const combobox = getCombobox(el);
510
- combobox.click();
511
-
512
- // Filter options by typing "Option 1" to only show that option
513
- filterCombobox(combobox, 'Option 1');
514
- await elementUpdated(el);
515
-
516
- // Only Option 1 should be visible
517
- const visibleOptions = el.shadowRoot!.querySelectorAll('tt-option:not(.select-all, [hidden])');
518
- await expect(visibleOptions.length).to.equal(1);
519
- await expect(visibleOptions[0].getAttribute('value')).to.equal('1');
520
-
521
- // Click "Select All"
522
- const selectAll = el.shadowRoot!.querySelector('tt-option.select-all') as TtOption;
523
- selectAll.click();
524
- await elementUpdated(el);
525
-
526
- // Clear the filter
527
- filterCombobox(combobox, '');
528
- await elementUpdated(el);
529
-
530
- // Verify that only "Option 1" is selected
531
- await expect(el.value).to.deep.equal(['1']);
532
- });
533
-
534
- it('should only remove the visible options from the value when deselecting select all after filtering', async () => {
535
- const el = await fixture<TtCombobox>(
536
- html` <tt-combobox id="combobox" multiselect display-select-all select-all-placeholder="Everything">
537
- <span slot="label">Test combobox</span>
538
- <option slot="option" value="1">Option 1</option>
539
- <option slot="option" value="2">Option 2</option>
540
- <option slot="option" value="3">Option 3</option>
541
- </tt-combobox>`
542
- );
543
-
544
- // Open the combobox
545
- const combobox = getCombobox(el);
546
- combobox.click();
547
-
548
- // Click "Select All"
549
- const selectAll = el.shadowRoot!.querySelector('tt-option.select-all') as TtOption;
550
- selectAll.click();
551
- await elementUpdated(el);
552
-
553
- // Filter options by typing "Option 1" to only show that option
554
- filterCombobox(combobox, 'Option 1');
555
- await elementUpdated(el);
556
-
557
- // Click "Select All" again to deselect visible options
558
- selectAll.click();
559
- await elementUpdated(el);
560
-
561
- // Clear the filter
562
- filterCombobox(combobox, '');
563
- await elementUpdated(el);
564
-
565
- // Verify that only "Option 1" is selected
566
- await expect(el.value).to.deep.equal(['2', '3']);
567
- });
568
-
569
- describe('Form Integration', () => {
570
- it('should include its values in FormData when submitted', async () => {
571
- // Create a form with the combobox component
572
- const form = await fixture<HTMLFormElement>(html`
573
- <form method="post" action="#">
574
- <input type="text" name="text_field" value="test_input" />
575
- <tt-combobox name="country_select" id="combobox">
576
- <option slot="option" value="us">United States</option>
577
- <option slot="option" value="ca">Canada</option>
578
- <option slot="option" value="mx">Mexico</option>
579
- </tt-combobox>
580
- <button type="submit">Submit</button>
581
- </form>
582
- `);
583
-
584
- const combobox = form.querySelector('tt-combobox') as TtCombobox;
585
- expect(combobox).to.exist;
586
-
587
- // Select an option by setting the value directly
588
- combobox.value = ['ca'];
589
- await elementUpdated(combobox);
590
-
591
- // Create FormData from the form and verify the combobox's value is included
592
- const formData = new FormData(form);
593
- const comboboxValue = formData.get('country_select');
594
-
595
- expect(comboboxValue).to.exist;
596
- const parsedValue = JSON.parse(comboboxValue as string);
597
- expect(parsedValue).to.deep.equal(['ca']);
598
- });
599
-
600
- it('should include multiple selected values in FormData when multiselect is true', async () => {
601
- // Create a form with a multiselect combobox
602
- const form = await fixture<HTMLFormElement>(html`
603
- <form method="post" action="#">
604
- <tt-combobox name="countries" multiselect id="multiselect-combobox">
605
- <option slot="option" value="us">United States</option>
606
- <option slot="option" value="ca">Canada</option>
607
- <option slot="option" value="mx">Mexico</option>
608
- <option slot="option" value="uk">United Kingdom</option>
609
- </tt-combobox>
610
- <button type="submit">Submit</button>
611
- </form>
612
- `);
613
-
614
- const combobox = form.querySelector('tt-combobox') as TtCombobox;
615
-
616
- // Select multiple options
617
- combobox.value = ['us', 'mx', 'uk'];
618
- await elementUpdated(combobox);
619
-
620
- // Verify FormData contains the multiple selected values
621
- const formData = new FormData(form);
622
- const comboboxValue = formData.get('countries');
623
-
624
- expect(comboboxValue).to.exist;
625
- const parsedValue = JSON.parse(comboboxValue as string);
626
- expect(parsedValue).to.be.an('array').that.includes('us');
627
- expect(parsedValue).to.be.an('array').that.includes('mx');
628
- expect(parsedValue).to.be.an('array').that.includes('uk');
629
- expect(parsedValue).to.have.lengthOf(3);
630
- });
631
-
632
- it('should update FormData when selections change', async () => {
633
- const form = await fixture<HTMLFormElement>(html`
634
- <form method="post" action="#">
635
- <tt-combobox name="selection" id="combobox">
636
- <option slot="option" value="option1">Option 1</option>
637
- <option slot="option" value="option2">Option 2</option>
638
- <option slot="option" value="option3">Option 3</option>
639
- </tt-combobox>
640
- </form>
641
- `);
642
-
643
- const combobox = form.querySelector('tt-combobox') as TtCombobox;
644
-
645
- // Initial selection
646
- combobox.value = ['option1'];
647
- await elementUpdated(combobox);
648
-
649
- // Check initial FormData
650
- let formData = new FormData(form);
651
- let value = JSON.parse(formData.get('selection') as string);
652
- expect(value).to.deep.equal(['option1']);
653
-
654
- // Change selection
655
- combobox.value = ['option2'];
656
- await elementUpdated(combobox);
657
-
658
- // Check updated FormData
659
- formData = new FormData(form);
660
- value = JSON.parse(formData.get('selection') as string);
661
- expect(value).to.deep.equal(['option2']);
662
- });
663
- });
664
- });
package/tsconfig.cjs.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.packages.cjs.json",
3
- "compilerOptions": {
4
- "rootDir": "./",
5
- "outDir": "dist/cjs"
6
- },
7
- "include": ["src/**/*.ts"],
8
- "exclude": ["node_modules", "dist"]
9
- }
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.packages.esm.json",
3
- "compilerOptions": {
4
- "rootDir": "./",
5
- "outDir": "dist/esm"
6
- },
7
- "include": ["src/**/*.ts", "test/**/*.ts"],
8
- "exclude": ["node_modules", "dist"]
9
- }