Skip to content

Commit 9a4b06a

Browse files
authored
test: update combo-box tests to use await, minor cleanup (#7145)
1 parent b4fa5d4 commit 9a4b06a

15 files changed

Lines changed: 95 additions & 155 deletions

‎packages/combo-box/test/aria.test.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { expect } from '@esm-bundle/chai';
2-
import { arrowDownKeyDown, escKeyDown, fixtureSync, nextFrame } from '@vaadin/testing-helpers';
2+
import { arrowDownKeyDown, escKeyDown, fixtureSync, nextFrame, nextRender } from '@vaadin/testing-helpers';
33
import './not-animated-styles.js';
44
import '../vaadin-combo-box.js';
55
import { getAllItems } from './helpers.js';
66

77
describe('ARIA', () => {
88
let comboBox, input;
99

10-
beforeEach(() => {
10+
beforeEach(async () => {
1111
comboBox = fixtureSync('<vaadin-combo-box></vaadin-combo-box>');
1212
comboBox.items = ['foo', 'bar', 'baz'];
13+
await nextRender();
1314
input = comboBox.inputElement;
1415
});
1516

@@ -32,8 +33,8 @@ describe('ARIA', () => {
3233

3334
beforeEach(async () => {
3435
arrowDownKeyDown(input);
35-
items = getAllItems(comboBox);
3636
await nextFrame();
37+
items = getAllItems(comboBox);
3738
});
3839

3940
it('should set aria-activedescendant on the input element depending on the focused item', () => {

‎packages/combo-box/test/basic.test.js‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { expect } from '@esm-bundle/chai';
2-
import { fixtureSync, outsideClick } from '@vaadin/testing-helpers';
2+
import { fixtureSync, nextRender, outsideClick } from '@vaadin/testing-helpers';
33
import sinon from 'sinon';
44
import './not-animated-styles.js';
55
import '../vaadin-combo-box.js';
66
import { getViewportItems, setInputValue } from './helpers.js';
77

8-
describe('Properties', () => {
8+
describe('basic features', () => {
99
let comboBox, overlay, input;
1010

11-
beforeEach(() => {
11+
beforeEach(async () => {
1212
comboBox = fixtureSync('<vaadin-combo-box></vaadin-combo-box>');
13+
await nextRender();
1314
overlay = comboBox.$.overlay;
1415
input = comboBox.inputElement;
1516
});
@@ -106,7 +107,7 @@ describe('Properties', () => {
106107
input.focus();
107108
});
108109

109-
it('should set bind value after setting value property', () => {
110+
it('should set input value after setting value property', () => {
110111
comboBox.value = 'foo';
111112

112113
expect(input.value).to.eql('foo');
@@ -207,10 +208,6 @@ describe('Properties', () => {
207208
expect(comboBox.hasAttribute('focused')).to.be.false;
208209
});
209210

210-
it('should not throw on focusout', () => {
211-
expect(() => comboBox.dispatchEvent(new Event('focusout'))).not.to.throw(Error);
212-
});
213-
214211
it('should focus the input with focus method', () => {
215212
comboBox.focus();
216213

@@ -273,12 +270,13 @@ describe('Properties', () => {
273270
describe('inside flexbox', () => {
274271
let container;
275272

276-
beforeEach(() => {
273+
beforeEach(async () => {
277274
container = fixtureSync(`
278275
<div style="display: flex; flex-direction: column; width:500px;">
279276
<vaadin-combo-box></vaadin-combo-box>
280277
</div>
281278
`);
279+
await nextRender();
282280
});
283281

284282
it('combo-box should stretch to fit the flex container', () => {
@@ -292,8 +290,9 @@ describe('clear button', () => {
292290
let comboBox, clearButton;
293291

294292
describe('default', () => {
295-
beforeEach(() => {
293+
beforeEach(async () => {
296294
comboBox = fixtureSync('<vaadin-combo-box></vaadin-combo-box>');
295+
await nextRender();
297296
});
298297

299298
it('should not have clear button visible by default', () => {
@@ -302,8 +301,9 @@ describe('clear button', () => {
302301
});
303302

304303
describe('visible', () => {
305-
beforeEach(() => {
304+
beforeEach(async () => {
306305
comboBox = fixtureSync('<vaadin-combo-box clear-button-visible></vaadin-combo-box>');
306+
await nextRender();
307307
clearButton = comboBox.$.clearButton;
308308
});
309309

@@ -334,10 +334,11 @@ describe('value set before attach', () => {
334334
comboBox.remove();
335335
});
336336

337-
it('should set value to the input when added to the DOM', () => {
337+
it('should set value to the input when added to the DOM', async () => {
338338
comboBox.items = ['a', 'b'];
339339
comboBox.value = 'a';
340340
document.body.appendChild(comboBox);
341+
await nextRender();
341342
expect(comboBox.inputElement.value).to.equal('a');
342343
});
343344
});
@@ -351,20 +352,22 @@ describe('pre-opened', () => {
351352
expect(() => fixtureSync(`<vaadin-combo-box opened items="[0]"></vaadin-combo-box>`)).to.not.throw(Error);
352353
});
353354

354-
it('should have overlay with correct width', () => {
355+
it('should have overlay with correct width', async () => {
355356
const comboBox = fixtureSync(`<vaadin-combo-box opened items="[0]"></vaadin-combo-box>`);
357+
await nextRender();
356358
const expectedOverlayWidth = comboBox.clientWidth;
357359
const actualOverlayWidth = comboBox.$.overlay.$.content.clientWidth;
358360
expect(actualOverlayWidth).to.eq(expectedOverlayWidth);
359361
});
360362

361-
it('should have overlay with correct width', () => {
363+
it('should have scroller with correct max height', async () => {
362364
const comboBox = fixtureSync(`
363365
<vaadin-combo-box
364366
opened
365367
items="[0]"
366368
style="--vaadin-combo-box-overlay-max-height: 200px"
367369
></vaadin-combo-box>`);
370+
await nextRender();
368371
const scroller = comboBox.$.overlay.querySelector('vaadin-combo-box-scroller');
369372
expect(scroller.style.maxHeight).to.equal('200px');
370373
});

‎packages/combo-box/test/combo-box-light.test.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
fire,
77
fixtureSync,
88
isDesktopSafari,
9-
isIOS,
109
mousedown,
1110
mouseup,
1211
nextRender,
@@ -122,7 +121,7 @@ describe('vaadin-combo-box-light', () => {
122121
});
123122
});
124123

125-
(isIOS ? describe.skip : describe)('after opening', () => {
124+
describe('after opening', () => {
126125
beforeEach(() => {
127126
comboBox.open();
128127
});

‎packages/combo-box/test/dynamic-size.test.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@esm-bundle/chai';
2-
import { fixtureSync, nextFrame } from '@vaadin/testing-helpers';
2+
import { fixtureSync, nextFrame, nextRender } from '@vaadin/testing-helpers';
33
import '../src/vaadin-combo-box.js';
44
import { flushComboBox, getViewportItems, scrollToIndex } from './helpers.js';
55

@@ -26,9 +26,10 @@ describe('dynamic size change', () => {
2626
callback(items, size);
2727
}
2828

29-
beforeEach(() => {
29+
beforeEach(async () => {
3030
comboBox = fixtureSync('<vaadin-combo-box></vaadin-combo-box>');
3131
comboBox.dataProvider = dataProvider;
32+
await nextRender();
3233
});
3334

3435
it('should not have item placeholders after size gets reduced', async () => {

‎packages/combo-box/test/events.test.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@esm-bundle/chai';
2-
import { fixtureSync, focusout, outsideClick } from '@vaadin/testing-helpers';
2+
import { fixtureSync, focusout, nextRender, outsideClick } from '@vaadin/testing-helpers';
33
import sinon from 'sinon';
44
import './not-animated-styles.js';
55
import '../vaadin-combo-box.js';
@@ -9,10 +9,11 @@ describe('events', () => {
99
let comboBox;
1010

1111
describe('custom-value-set event', () => {
12-
beforeEach(() => {
12+
beforeEach(async () => {
1313
comboBox = fixtureSync('<vaadin-combo-box></vaadin-combo-box>');
1414
comboBox.allowCustomValue = true;
1515
comboBox.items = ['a', 'b'];
16+
await nextRender();
1617
comboBox.inputElement.focus();
1718
});
1819

‎packages/combo-box/test/external-filtering.test.js‎

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expect } from '@esm-bundle/chai';
2-
import { aTimeout, enter, fixtureSync } from '@vaadin/testing-helpers';
3-
import sinon from 'sinon';
2+
import { aTimeout, enter, fixtureSync, nextRender } from '@vaadin/testing-helpers';
43
import './not-animated-styles.js';
54
import '../vaadin-combo-box.js';
65
import { getFocusedItemIndex, setInputValue } from './helpers.js';
@@ -9,9 +8,10 @@ describe('external filtering', () => {
98
let comboBox, overlay;
109

1110
describe('basic', () => {
12-
beforeEach(() => {
11+
beforeEach(async () => {
1312
comboBox = fixtureSync('<vaadin-combo-box></vaadin-combo-box>');
1413
comboBox.filteredItems = ['foo', 'bar', 'baz'];
14+
await nextRender();
1515
overlay = comboBox.$.overlay;
1616
});
1717

@@ -50,7 +50,7 @@ describe('external filtering', () => {
5050

5151
it('should update focus when opening with filling filter', () => {
5252
comboBox.filteredItems = ['foo', 'bar', 'baz'];
53-
comboBox.close();
53+
expect(comboBox.opened).to.be.false;
5454

5555
setInputValue(comboBox, 'bar');
5656

@@ -65,17 +65,7 @@ describe('external filtering', () => {
6565

6666
expect(comboBox.opened).to.be.true;
6767
expect(comboBox.$.overlay.hasAttribute('hidden')).to.be.false;
68-
});
69-
70-
// FIXME(@platosha): Hiding does not play nice with lazy loading.
71-
// Should display a loading indicator instead.
72-
it.skip('should hide the scroller while loading', () => {
73-
setInputValue(comboBox, 'foo');
74-
75-
comboBox.loading = true;
76-
77-
expect(comboBox.opened).to.be.true;
78-
expect(comboBox._scroller.hidden).to.be.true;
68+
expect(comboBox._scroller.hidden).to.be.false;
7969
});
8070

8171
it('should refresh items after reassignment', () => {
@@ -94,18 +84,12 @@ describe('external filtering', () => {
9484
expect(comboBox.hasAttribute('loading')).to.be.false;
9585
expect(overlay.hasAttribute('loading')).to.be.false;
9686
});
97-
98-
it('should not perform measurements when loading changes if not opened', () => {
99-
const measureSpy = sinon.spy(comboBox.inputElement, 'getBoundingClientRect');
100-
comboBox.loading = true;
101-
102-
expect(measureSpy.called).to.be.false;
103-
});
10487
});
10588

10689
describe('filtered items attribute', () => {
107-
beforeEach(() => {
90+
beforeEach(async () => {
10891
comboBox = fixtureSync(`<vaadin-combo-box filtered-items='["a", "b", "c"]' value='b'></vaadin-combo-box>`);
92+
await nextRender();
10993
});
11094

11195
it('should not throw when passing filteredItems and value as attributes', () => {
@@ -115,8 +99,9 @@ describe('external filtering', () => {
11599
});
116100

117101
describe('value is set after', () => {
118-
beforeEach(() => {
102+
beforeEach(async () => {
119103
comboBox = fixtureSync(`<vaadin-combo-box></vaadin-combo-box>`);
104+
await nextRender();
120105
comboBox.filteredItems = ['foo', 'bar'];
121106
comboBox.value = 'foo';
122107
});
@@ -152,8 +137,9 @@ describe('external filtering', () => {
152137
});
153138

154139
describe('value is set before', () => {
155-
beforeEach(() => {
140+
beforeEach(async () => {
156141
comboBox = fixtureSync(`<vaadin-combo-box value="foo"></vaadin-combo-box>`);
142+
await nextRender();
157143
comboBox.filteredItems = ['foo', 'bar'];
158144
});
159145

@@ -180,8 +166,9 @@ describe('external filtering', () => {
180166
});
181167

182168
describe('value is set before + autoOpenDisabled', () => {
183-
beforeEach(() => {
169+
beforeEach(async () => {
184170
comboBox = fixtureSync(`<vaadin-combo-box auto-open-disabled value="bar"></vaadin-combo-box>`);
171+
await nextRender();
185172
comboBox.filteredItems = ['foo', 'bar'];
186173
});
187174

@@ -237,8 +224,9 @@ describe('external filtering', () => {
237224
{ label: 'Item 2', value: '2' },
238225
];
239226

240-
beforeEach(() => {
227+
beforeEach(async () => {
241228
comboBox = fixtureSync(`<vaadin-combo-box></vaadin-combo-box>`);
229+
await nextRender();
242230
comboBox.selectedItem = items[0];
243231
comboBox.filteredItems = items;
244232
});

‎packages/combo-box/test/internal-filtering.test.js‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@esm-bundle/chai';
2-
import { fixtureSync, outsideClick } from '@vaadin/testing-helpers';
2+
import { fixtureSync, nextRender, outsideClick } from '@vaadin/testing-helpers';
33
import sinon from 'sinon';
44
import './not-animated-styles.js';
55
import '../vaadin-combo-box.js';
@@ -10,8 +10,9 @@ describe('internal filtering', () => {
1010
let comboBox;
1111

1212
describe('value is set before', () => {
13-
beforeEach(() => {
13+
beforeEach(async () => {
1414
comboBox = fixtureSync(`<vaadin-combo-box value="foo"></vaadin-combo-box>`);
15+
await nextRender();
1516
comboBox.items = ['foo', 'bar'];
1617
});
1718

@@ -25,8 +26,9 @@ describe('internal filtering', () => {
2526
});
2627

2728
describe('setting the input field value', () => {
28-
beforeEach(() => {
29+
beforeEach(async () => {
2930
comboBox = fixtureSync('<vaadin-combo-box></vaadin-combo-box>');
31+
await nextRender();
3032
comboBox.items = ['foo', 'bar', 'baz'];
3133
});
3234

@@ -120,8 +122,9 @@ describe('internal filtering', () => {
120122
});
121123

122124
describe('focusing items while filtering', () => {
123-
beforeEach(() => {
125+
beforeEach(async () => {
124126
comboBox = fixtureSync('<vaadin-combo-box></vaadin-combo-box>');
127+
await nextRender();
125128
comboBox.items = ['foo', 'bar', 'baz'];
126129
});
127130

@@ -170,8 +173,9 @@ describe('internal filtering', () => {
170173
describe('filtering items', () => {
171174
let overlay;
172175

173-
beforeEach(() => {
176+
beforeEach(async () => {
174177
comboBox = fixtureSync('<vaadin-combo-box></vaadin-combo-box>');
178+
await nextRender();
175179
comboBox.items = ['foo', 'bar', 'baz'];
176180
overlay = comboBox.$.overlay;
177181
});
@@ -278,8 +282,9 @@ describe('internal filtering', () => {
278282
});
279283

280284
describe('setting items when opened', () => {
281-
beforeEach(() => {
285+
beforeEach(async () => {
282286
comboBox = fixtureSync('<vaadin-combo-box></vaadin-combo-box>');
287+
await nextRender();
283288
comboBox.items = [];
284289
});
285290

@@ -291,8 +296,9 @@ describe('internal filtering', () => {
291296
});
292297

293298
describe('setting placeholder items', () => {
294-
beforeEach(() => {
299+
beforeEach(async () => {
295300
comboBox = fixtureSync('<vaadin-combo-box></vaadin-combo-box>');
301+
await nextRender();
296302
comboBox.items = [new ComboBoxPlaceholder(), new ComboBoxPlaceholder()];
297303
});
298304

0 commit comments

Comments
 (0)