@triptease/tt-combobox 5.4.2 → 5.5.1

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.
@@ -2,6 +2,7 @@ import { html } from 'lit';
2
2
  import { elementUpdated, expect, fixture, oneEvent } from '@open-wc/testing';
3
3
  import { TtCombobox } from '../src/index.js';
4
4
  import '../src/tt-combobox.js';
5
+ import { TtOption } from '../src/tt-option/TtOption.js';
5
6
 
6
7
  describe('TtCombobox', () => {
7
8
  const getCombobox = (el: TtCombobox) => el.shadowRoot!.querySelector('[role="combobox"]') as HTMLInputElement;
@@ -40,7 +41,7 @@ describe('TtCombobox', () => {
40
41
  const combobox = getCombobox(el);
41
42
  combobox.click();
42
43
 
43
- const options = el.shadowRoot!.querySelectorAll('[role="option"]');
44
+ const options = el.shadowRoot!.querySelectorAll('tt-option');
44
45
  await expect(options.length).to.equal(3);
45
46
  options.forEach((option) => {
46
47
  expect(option.checkVisibility()).to.be.true;
@@ -59,7 +60,7 @@ describe('TtCombobox', () => {
59
60
  const combobox = getCombobox(el);
60
61
  combobox.click();
61
62
 
62
- const option = el.shadowRoot!.querySelector('[role="option"][data-value="2"]') as HTMLLIElement;
63
+ const option = el.shadowRoot!.querySelector('tt-option[value="2"]') as HTMLLIElement;
63
64
  option.click();
64
65
  await elementUpdated(el);
65
66
  expect(comboboxPlaceholderText(combobox)).to.equal('Option 2');
@@ -93,15 +94,15 @@ describe('TtCombobox', () => {
93
94
  const combobox = getCombobox(el);
94
95
  await combobox.click();
95
96
 
96
- const selectAll = el.shadowRoot!.querySelector('[role="option"][data-value="select-all"]') as HTMLLIElement;
97
+ const selectAll = el.shadowRoot!.querySelector('tt-option.select-all') as HTMLLIElement;
97
98
  expect(selectAll).to.exist;
98
99
 
99
100
  selectAll.click();
100
101
  await oneEvent(el, 'change');
101
102
 
102
- const options = el.shadowRoot!.querySelectorAll('[role="option"]');
103
+ const options = el.shadowRoot!.querySelectorAll('tt-option');
103
104
  options.forEach((option) => {
104
- expect(option.getAttribute('aria-selected')).to.equal('true');
105
+ expect(option.selected).to.be.true;
105
106
  });
106
107
  });
107
108
 
@@ -117,10 +118,17 @@ describe('TtCombobox', () => {
117
118
  const combobox = getCombobox(el);
118
119
  await combobox.click();
119
120
 
120
- const option = el.shadowRoot!.querySelector('[role="option"][data-value="2"]') as HTMLLIElement;
121
+ await elementUpdated(el);
122
+
123
+ const option = el.shadowRoot!.querySelector('tt-option[value="2"]') as TtOption;
124
+
125
+ await expect(option.disabled).to.be.true;
121
126
  option.click();
122
127
 
128
+ await elementUpdated(el);
129
+
123
130
  await expect(comboboxPlaceholderText(combobox)).to.equal('No options selected');
131
+ await expect(el.value).to.deep.equal([]);
124
132
  });
125
133
 
126
134
  it('should disable the combobox when the disabled attribute is set', async () => {
@@ -174,7 +182,7 @@ describe('TtCombobox', () => {
174
182
 
175
183
  combobox.click();
176
184
 
177
- const option = el.shadowRoot!.querySelector('[role="option"][data-value="2"]') as HTMLLIElement;
185
+ const option = el.shadowRoot!.querySelector('tt-option[value="2"]') as HTMLLIElement;
178
186
  option.click();
179
187
 
180
188
  const event = await oneEvent(el, 'change');
@@ -227,7 +235,7 @@ describe('TtCombobox', () => {
227
235
 
228
236
  await combobox.click();
229
237
 
230
- const selectAll = el.shadowRoot!.querySelector('[role="option"][data-value="select-all"]') as HTMLLIElement;
238
+ const selectAll = el.shadowRoot!.querySelector('tt-option.select-all') as TtOption;
231
239
  expect(selectAll).to.exist;
232
240
 
233
241
  selectAll.click();
@@ -236,9 +244,8 @@ describe('TtCombobox', () => {
236
244
  expect(changeEvent).to.exist;
237
245
  expect((changeEvent.target as TtCombobox).value).to.deep.equal(['1', '2', '3', '4']);
238
246
 
239
- const hiddenOption = el.shadowRoot!.querySelector('[role="option"][data-value="4"]') as HTMLLIElement;
247
+ const hiddenOption = el.shadowRoot!.querySelector('tt-option[value="4"][hidden]') as TtOption;
240
248
  expect(hiddenOption).to.exist;
241
- expect(hiddenOption).to.have.attribute('aria-hidden', 'true');
242
249
  });
243
250
 
244
251
  it('should not include hidden options in the placeholder text', async () => {
@@ -256,12 +263,12 @@ describe('TtCombobox', () => {
256
263
 
257
264
  await combobox.click();
258
265
 
259
- const selectAll = el.shadowRoot!.querySelector('[role="option"][data-value="select-all"]') as HTMLLIElement;
266
+ const selectAll = el.shadowRoot!.querySelector('tt-option.select-all') as TtOption;
260
267
  expect(selectAll).to.exist;
261
268
 
262
269
  selectAll.click();
263
270
 
264
- (<HTMLLIElement>el.shadowRoot!.querySelector('[role="option"][data-value="3"]')).click();
271
+ (<TtOption>el.shadowRoot!.querySelector('tt-option[value="3"]')).click();
265
272
 
266
273
  const changeEvent = await oneEvent<InputEvent>(el, 'change');
267
274
 
@@ -283,21 +290,18 @@ describe('TtCombobox', () => {
283
290
  const combobox = getCombobox(el);
284
291
  combobox.click();
285
292
 
286
- let options = el.shadowRoot!.querySelectorAll('[role="option"]');
293
+ let options = el.shadowRoot!.querySelectorAll('tt-option');
287
294
  expect(options.length).to.equal(3);
288
295
 
289
296
 
290
- const option = el.shadowRoot!.querySelector('[role="option"][data-value="2"]') as HTMLLIElement;
297
+ const option = el.shadowRoot!.querySelector('tt-option[value="2"]') as HTMLLIElement;
291
298
  option.click();
292
299
  await elementUpdated(el);
293
300
 
294
- options = el.shadowRoot!.querySelectorAll('[role="option"]');
301
+ options = el.shadowRoot!.querySelectorAll('tt-option');
295
302
  options.forEach((o) => {
296
303
  expect(o.checkVisibility()).to.be.false;
297
304
  });
298
-
299
-
300
-
301
305
  });
302
306
 
303
307
 
@@ -335,9 +339,9 @@ describe('TtCombobox', () => {
335
339
  </tt-combobox>`);
336
340
 
337
341
  await expect(el.value).to.deep.equal(value);
338
- const selectedOptions = el.shadowRoot!.querySelectorAll('li[role="option"][aria-selected="true"]');
342
+ const selectedOptions = el.shadowRoot!.querySelectorAll('tt-option[selected]') as NodeListOf<TtOption>;
339
343
  expect(selectedOptions).to.have.lengthOf(2);
340
- await expect(Array.from(selectedOptions).map(option => option.getAttribute('data-value'))).to.deep.equal(value);
344
+ await expect(Array.from(selectedOptions).map(option => option.value)).to.deep.equal(value);
341
345
  });
342
346
 
343
347
  it('should display the passed placeholder when all options are selected', async () => {
@@ -352,7 +356,7 @@ describe('TtCombobox', () => {
352
356
  const combobox = getCombobox(el);
353
357
  combobox.click();
354
358
 
355
- const selectAll = el.shadowRoot!.querySelector('[role="option"][data-value="select-all"]') as HTMLLIElement;
359
+ const selectAll = el.shadowRoot!.querySelector('tt-option.select-all') as TtOption;
356
360
  expect(selectAll).to.exist;
357
361
 
358
362
  selectAll.click();
@@ -374,7 +378,7 @@ describe('TtCombobox', () => {
374
378
  combobox.click();
375
379
 
376
380
  // Select all options
377
- const selectAll = el.shadowRoot!.querySelector('[role="option"][data-value="select-all"]') as HTMLLIElement;
381
+ const selectAll = el.shadowRoot!.querySelector('tt-option.select-all') as TtOption;
378
382
  expect(selectAll).to.exist;
379
383
 
380
384
  selectAll.click();
@@ -386,7 +390,7 @@ describe('TtCombobox', () => {
386
390
  await elementUpdated(el);
387
391
 
388
392
  // Deselect "Option 1"
389
- const option1 = el.shadowRoot!.querySelector('[role="option"][data-value="1"]') as HTMLLIElement;
393
+ const option1 = el.shadowRoot!.querySelector('tt-option[value="1"]') as TtOption;
390
394
  expect(option1).to.exist;
391
395
 
392
396
  option1.click();
@@ -398,7 +402,7 @@ describe('TtCombobox', () => {
398
402
  await elementUpdated(el);
399
403
 
400
404
  // Verify selected options
401
- const selectedOptions = el.shadowRoot!.querySelectorAll('li[role="option"][aria-selected="true"]');
405
+ const selectedOptions = el.shadowRoot!.querySelectorAll('tt-option[selected]');
402
406
  expect(selectedOptions).to.have.lengthOf(2);
403
407
  });
404
408
 
@@ -420,12 +424,12 @@ describe('TtCombobox', () => {
420
424
  await elementUpdated(el);
421
425
 
422
426
  // Only Option 1 should be visible
423
- const visibleOptions = el.shadowRoot!.querySelectorAll('[role="option"]:not([data-value="select-all"]):not([aria-hidden="true"])');
427
+ const visibleOptions = el.shadowRoot!.querySelectorAll('tt-option:not(.select-all, [hidden])');
424
428
  await expect(visibleOptions.length).to.equal(1);
425
- await expect(visibleOptions[0].getAttribute('data-value')).to.equal('1');
429
+ await expect(visibleOptions[0].getAttribute('value')).to.equal('1');
426
430
 
427
431
  // Click "Select All"
428
- const selectAll = el.shadowRoot!.querySelector('[role="option"][data-value="select-all"]') as HTMLLIElement;
432
+ const selectAll = el.shadowRoot!.querySelector('tt-option.select-all') as TtOption;
429
433
  selectAll.click();
430
434
  await elementUpdated(el);
431
435
 
@@ -451,7 +455,7 @@ describe('TtCombobox', () => {
451
455
  combobox.click();
452
456
 
453
457
  // Click "Select All"
454
- const selectAll = el.shadowRoot!.querySelector('[role="option"][data-value="select-all"]') as HTMLLIElement;
458
+ const selectAll = el.shadowRoot!.querySelector('tt-option.select-all') as TtOption;
455
459
  selectAll.click();
456
460
  await elementUpdated(el);
457
461