Skip to content

Commit 04a77c7

Browse files
authored
test: stabilize dashboard tests with onceResized helper (#7825)
1 parent 3bdf028 commit 04a77c7

5 files changed

Lines changed: 66 additions & 43 deletions

File tree

‎packages/dashboard/test/dashboard-layout.test.ts‎

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
getColumnWidths,
1010
getRowHeights,
1111
getScrollingContainer,
12+
onceResized,
1213
setColspan,
1314
setGap,
1415
setMaximumColumnCount,
@@ -40,7 +41,7 @@ describe('dashboard layout', () => {
4041
// Make the dashboard wide enough to fit all items on a single row
4142
dashboard.style.width = `${columnWidth * dashboard.childElementCount}px`;
4243

43-
await nextFrame();
44+
await onceResized(dashboard);
4445
// @ts-expect-error Test without padding
4546
dashboard.$.grid.style.padding = '0';
4647

@@ -60,7 +61,7 @@ describe('dashboard layout', () => {
6061
it('should be responsive', async () => {
6162
// Narrow down the component to fit one column
6263
dashboard.style.width = `${columnWidth}px`;
63-
await nextFrame();
64+
await onceResized(dashboard);
6465

6566
/* prettier-ignore */
6667
expectLayout(dashboard, [
@@ -73,7 +74,7 @@ describe('dashboard layout', () => {
7374
dashboard.style.width = `${columnWidth}px`;
7475
const rowHeight = Math.ceil(getRowHeights(dashboard)[0]);
7576
dashboard.style.height = `${rowHeight}px`;
76-
await nextFrame();
77+
await onceResized(dashboard);
7778

7879
const scrollingContainer = getScrollingContainer(dashboard);
7980
expect(getComputedStyle(scrollingContainer).overflowY).to.eql('auto');
@@ -85,7 +86,7 @@ describe('dashboard layout', () => {
8586

8687
it('should scroll horizontally when content overflows', async () => {
8788
dashboard.style.width = `${columnWidth / 2}px`;
88-
await nextFrame();
89+
await onceResized(dashboard);
8990

9091
const scrollingContainer = getScrollingContainer(dashboard);
9192
expect(getComputedStyle(scrollingContainer).overflowX).to.eql('auto');
@@ -105,15 +106,15 @@ describe('dashboard layout', () => {
105106
setMinimumColumnWidth(dashboard, undefined);
106107
// Narrow down the component to have the width of 0
107108
dashboard.style.width = '0';
108-
await nextFrame();
109+
await onceResized(dashboard);
109110
// Expect the column width to equal the default minimum column width
110111
expect(getColumnWidths(dashboard)).to.eql([remValue * 25]);
111112
});
112113

113114
it('should have one overflown column if narrowed below minimum column width', async () => {
114115
// Narrow down the component to have the width of half a column
115116
dashboard.style.width = `${columnWidth / 2}px`;
116-
await nextFrame();
117+
await onceResized(dashboard);
117118
// Expect the column width to still be the same (overflown)
118119
expect(getColumnWidths(dashboard)).to.eql([columnWidth]);
119120
});
@@ -123,7 +124,7 @@ describe('dashboard layout', () => {
123124
setMinimumColumnWidth(dashboard, columnWidth / 2);
124125
// Narrow down the component to have the width of half a column
125126
dashboard.style.width = `${columnWidth / 2}px`;
126-
await nextFrame();
127+
await onceResized(dashboard);
127128
// Expect the column width to equal the min column width
128129
expect(getColumnWidths(dashboard)).to.eql([columnWidth / 2]);
129130
});
@@ -132,7 +133,7 @@ describe('dashboard layout', () => {
132133
setMaximumColumnWidth(dashboard, columnWidth * 2);
133134
// Set the min column width to be twice as wide
134135
setMinimumColumnWidth(dashboard, columnWidth * 2);
135-
await nextFrame();
136+
await onceResized(dashboard);
136137
// Expect there to only be one column with twice the width
137138
expect(getColumnWidths(dashboard)).to.eql([columnWidth * 2]);
138139
/* prettier-ignore */
@@ -150,22 +151,22 @@ describe('dashboard layout', () => {
150151
expect(getColumnWidths(dashboard)).to.eql([columnWidth, columnWidth]);
151152
// Widen the component to have the width of 2.5 columns
152153
dashboard.style.width = `${columnWidth * 2.5}px`;
153-
await nextFrame();
154+
await onceResized(dashboard);
154155
expect(getColumnWidths(dashboard)).to.eql([columnWidth * 1.25, columnWidth * 1.25]);
155156
// Widen the component to have the width of 3 columns
156157
dashboard.style.width = `${columnWidth * 3}px`;
157-
await nextFrame();
158+
await onceResized(dashboard);
158159
expect(getColumnWidths(dashboard)).to.eql([columnWidth, columnWidth, columnWidth]);
159160
// Shrink the component to have the width of 1.5 columns
160161
dashboard.style.width = `${columnWidth * 1.5}px`;
161-
await nextFrame();
162+
await onceResized(dashboard);
162163
expect(getColumnWidths(dashboard)).to.eql([columnWidth * 1.5]);
163164
});
164165

165166
it('should have one wide column with large maximum column width', async () => {
166167
// Allow the column to be twice as wide
167168
setMaximumColumnWidth(dashboard, columnWidth * 2);
168-
await nextFrame();
169+
await onceResized(dashboard);
169170
// Expect there to only be one column with twice the width
170171
expect(getColumnWidths(dashboard)).to.eql([columnWidth * 2]);
171172
/* prettier-ignore */
@@ -202,7 +203,7 @@ describe('dashboard layout', () => {
202203
it('should use minimum row height for all rows', async () => {
203204
dashboard.style.width = `${columnWidth}px`;
204205
setMinimumRowHeight(dashboard, rowHeight);
205-
await nextFrame();
206+
await onceResized(dashboard);
206207
expect(getRowHeights(dashboard)).to.eql([rowHeight, rowHeight]);
207208
});
208209
});
@@ -224,7 +225,7 @@ describe('dashboard layout', () => {
224225
await nextFrame();
225226

226227
dashboard.style.width = `${columnWidth}px`;
227-
await nextFrame();
228+
await onceResized(dashboard);
228229

229230
/* prettier-ignore */
230231
expectLayout(dashboard, [
@@ -238,7 +239,7 @@ describe('dashboard layout', () => {
238239
await nextFrame();
239240

240241
dashboard.style.width = `${columnWidth * 3}px`;
241-
await nextFrame();
242+
await onceResized(dashboard);
242243

243244
/* prettier-ignore */
244245
expectLayout(dashboard, [
@@ -264,7 +265,7 @@ describe('dashboard layout', () => {
264265
// Expect widget 1 to still have the same width
265266
expect(childElements[1].offsetWidth).to.eql(widget1Width);
266267

267-
await nextFrame();
268+
await onceResized(dashboard);
268269

269270
/* prettier-ignore */
270271
expectLayout(dashboard, [
@@ -296,7 +297,7 @@ describe('dashboard layout', () => {
296297
await nextFrame();
297298

298299
dashboard.style.width = `${columnWidth}px`;
299-
await nextFrame();
300+
await onceResized(dashboard);
300301

301302
/* prettier-ignore */
302303
expectLayout(dashboard, [
@@ -313,7 +314,7 @@ describe('dashboard layout', () => {
313314
setGap(dashboard, undefined);
314315
// Increase the width of the dashboard to fit two items and a gap
315316
dashboard.style.width = `${columnWidth * 2 + remValue}px`;
316-
await nextFrame();
317+
await onceResized(dashboard);
317318

318319
const { right: item0Right } = childElements[0].getBoundingClientRect();
319320
const { left: item1Left } = childElements[1].getBoundingClientRect();
@@ -326,7 +327,7 @@ describe('dashboard layout', () => {
326327
setGap(dashboard, customGap);
327328
// Increase the width of the dashboard to fit two items and a gap
328329
dashboard.style.width = `${columnWidth * 2 + customGap}px`;
329-
await nextFrame();
330+
await onceResized(dashboard);
330331

331332
const { right: item0Right } = childElements[0].getBoundingClientRect();
332333
const { left: item1Left } = childElements[1].getBoundingClientRect();
@@ -338,7 +339,7 @@ describe('dashboard layout', () => {
338339
const customGap = 10;
339340
setGap(dashboard, customGap);
340341
dashboard.style.width = `${columnWidth}px`;
341-
await nextFrame();
342+
await onceResized(dashboard);
342343

343344
const { bottom: item0Bottom } = childElements[0].getBoundingClientRect();
344345
const { top: item1Top } = childElements[1].getBoundingClientRect();
@@ -350,21 +351,21 @@ describe('dashboard layout', () => {
350351
describe('maximum column count', () => {
351352
it('should not limit column count by default', async () => {
352353
dashboard.style.width = `${columnWidth * 100}px`;
353-
await nextFrame();
354+
await onceResized(dashboard);
354355
expect(getColumnWidths(dashboard).length).to.eql(100);
355356
});
356357

357358
it('should limit column count to custom value', async () => {
358359
setMaximumColumnCount(dashboard, 5);
359360
dashboard.style.width = `${columnWidth * 100}px`;
360-
await nextFrame();
361+
await onceResized(dashboard);
361362
expect(getColumnWidths(dashboard).length).to.eql(5);
362363
});
363364

364365
it('should limit column count to one', async () => {
365366
setMaximumColumnCount(dashboard, 1);
366367
dashboard.style.width = `${columnWidth * 10}px`;
367-
await nextFrame();
368+
await onceResized(dashboard);
368369
/* prettier-ignore */
369370
expectLayout(dashboard, [
370371
[0],
@@ -375,7 +376,7 @@ describe('dashboard layout', () => {
375376
it('should allow fewer columns', async () => {
376377
setMaximumColumnCount(dashboard, 2);
377378
dashboard.style.width = `${columnWidth}px`;
378-
await nextFrame();
379+
await onceResized(dashboard);
379380
/* prettier-ignore */
380381
expectLayout(dashboard, [
381382
[0],
@@ -397,7 +398,7 @@ describe('dashboard layout', () => {
397398
it('should increase max column count dynamically', async () => {
398399
setMaximumColumnCount(dashboard, 2);
399400
dashboard.style.width = `${columnWidth * 100}px`;
400-
await nextFrame();
401+
await onceResized(dashboard);
401402
expect(getColumnWidths(dashboard).length).to.eql(2);
402403

403404
setMaximumColumnCount(dashboard, 20);
@@ -431,7 +432,7 @@ describe('dashboard layout', () => {
431432

432433
it('should be on its own row', async () => {
433434
dashboard.style.width = `${columnWidth * 4}px`;
434-
await nextFrame();
435+
await onceResized(dashboard);
435436

436437
/* prettier-ignore */
437438
expectLayout(dashboard, [
@@ -443,7 +444,7 @@ describe('dashboard layout', () => {
443444
it('following items should end up in the next row', async () => {
444445
dashboard.style.width = `${columnWidth * 4}px`;
445446
dashboard.appendChild(fixtureSync('<div id="item-4">Item 4</div>'));
446-
await nextFrame();
447+
await onceResized(dashboard);
447448

448449
/* prettier-ignore */
449450
expectLayout(dashboard, [
@@ -455,7 +456,7 @@ describe('dashboard layout', () => {
455456

456457
it('should be capped to currently available columns', async () => {
457458
dashboard.style.width = `${columnWidth}px`;
458-
await nextFrame();
459+
await onceResized(dashboard);
459460

460461
/* prettier-ignore */
461462
expectLayout(dashboard, [
@@ -469,7 +470,7 @@ describe('dashboard layout', () => {
469470
it('should span multiple columns inside a section', async () => {
470471
dashboard.style.width = `${columnWidth * 3}px`;
471472
setColspan(childElements[2], 2);
472-
await nextFrame();
473+
await onceResized(dashboard);
473474

474475
/* prettier-ignore */
475476
expectLayout(dashboard, [
@@ -495,7 +496,7 @@ describe('dashboard layout', () => {
495496
it('should use minimum row height for all section rows', async () => {
496497
dashboard.style.width = `${columnWidth}px`;
497498
setMinimumRowHeight(dashboard, 300);
498-
await nextFrame();
499+
await onceResized(dashboard);
499500

500501
expect(childElements[2].offsetHeight).to.eql(300);
501502
expect(childElements[3].offsetHeight).to.eql(300);
@@ -514,23 +515,25 @@ describe('dashboard layout', () => {
514515
});
515516

516517
describe('gap', () => {
517-
it('should have a default gap', () => {
518+
it('should have a default gap', async () => {
518519
// Clear the gap used in the tests
519520
setGap(dashboard, undefined);
520521
// Increase the width of the dashboard to fit two items and a gap
521522
dashboard.style.width = `${columnWidth * 2 + remValue}px`;
523+
await onceResized(dashboard);
522524

523525
const { right: item2Right } = childElements[2].getBoundingClientRect();
524526
const { left: item3Left } = childElements[3].getBoundingClientRect();
525527
// Expect the items to have a gap of 1rem
526528
expect(item3Left - item2Right).to.eql(remValue);
527529
});
528530

529-
it('should have a custom gap between items horizontally', () => {
531+
it('should have a custom gap between items horizontally', async () => {
530532
const customGap = 10;
531533
setGap(dashboard, customGap);
532534
// Increase the width of the dashboard to fit two items and a gap
533535
dashboard.style.width = `${columnWidth * 2 + customGap}px`;
536+
await onceResized(dashboard);
534537

535538
const { right: item2Right } = childElements[2].getBoundingClientRect();
536539
const { left: item3Left } = childElements[3].getBoundingClientRect();
@@ -542,7 +545,7 @@ describe('dashboard layout', () => {
542545
const customGap = 10;
543546
setGap(dashboard, customGap);
544547
dashboard.style.width = `${columnWidth}px`;
545-
await nextFrame();
548+
await onceResized(dashboard);
546549

547550
const { bottom: item2Bottom } = childElements[2].getBoundingClientRect();
548551
const { top: item3Top } = childElements[3].getBoundingClientRect();

‎packages/dashboard/test/dashboard-widget-reordering.test.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
getDraggable,
1414
getElementFromCell,
1515
getParentSection,
16+
onceResized,
1617
resetReorderTimeout,
1718
setGap,
1819
setMaximumColumnWidth,
@@ -112,7 +113,7 @@ describe('dashboard - widget reordering', () => {
112113

113114
it('should reorder the widgets while dragging (top -> bottom)', async () => {
114115
dashboard.style.width = `${columnWidth}px`;
115-
await nextFrame();
116+
await onceResized(dashboard);
116117

117118
// prettier-ignore
118119
expectLayout(dashboard, [
@@ -135,7 +136,7 @@ describe('dashboard - widget reordering', () => {
135136

136137
it('should not reorder if dragged barely over another widget (top -> bottom)', async () => {
137138
dashboard.style.width = `${columnWidth}px`;
138-
await nextFrame();
139+
await onceResized(dashboard);
139140

140141
// prettier-ignore
141142
expectLayout(dashboard, [
@@ -158,7 +159,7 @@ describe('dashboard - widget reordering', () => {
158159

159160
it('should reorder the widgets while dragging (bottom -> top)', async () => {
160161
dashboard.style.width = `${columnWidth}px`;
161-
await nextFrame();
162+
await onceResized(dashboard);
162163

163164
// prettier-ignore
164165
expectLayout(dashboard, [
@@ -181,7 +182,7 @@ describe('dashboard - widget reordering', () => {
181182

182183
it('should not reorder if dragged barely over another widget (bottom -> top)', async () => {
183184
dashboard.style.width = `${columnWidth}px`;
184-
await nextFrame();
185+
await onceResized(dashboard);
185186

186187
// prettier-ignore
187188
expectLayout(dashboard, [
@@ -392,7 +393,7 @@ describe('dashboard - widget reordering', () => {
392393
// Add a third widget
393394
dashboard.style.width = `${columnWidth * 3}px`;
394395
dashboard.items = [...dashboard.items, { id: 2 }];
395-
await nextFrame();
396+
await onceResized(dashboard);
396397
// prettier-ignore
397398
expectLayout(dashboard, [
398399
[0, 1, 2],

‎packages/dashboard/test/dashboard-widget-resizing.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
fireResizeOver,
1212
fireResizeStart,
1313
getElementFromCell,
14+
onceResized,
1415
setGap,
1516
setMaximumColumnWidth,
1617
setMinimumColumnWidth,
@@ -345,7 +346,7 @@ describe('dashboard - widget resizing', () => {
345346

346347
// Narrow the dashboard to have only one column
347348
dashboard.style.width = `${columnWidth}px`;
348-
await nextFrame();
349+
await onceResized(dashboard);
349350
// prettier-ignore
350351
expectLayout(dashboard, [
351352
[0],
@@ -443,7 +444,7 @@ describe('dashboard - widget resizing', () => {
443444

444445
it('should not throw with a lazy renderer while resizing', async () => {
445446
dashboard.style.width = `${columnWidth}px`;
446-
await nextFrame();
447+
await onceResized(dashboard);
447448
// prettier-ignore
448449
expectLayout(dashboard, [
449450
[0],
@@ -486,7 +487,7 @@ describe('dashboard - widget resizing', () => {
486487
it('should take gap into account when resizing', async () => {
487488
dashboard.style.width = `${columnWidth * 3}px`;
488489
setGap(dashboard, columnWidth / 2);
489-
await nextFrame();
490+
await onceResized(dashboard);
490491

491492
// prettier-ignore
492493
expectLayout(dashboard, [

0 commit comments

Comments
 (0)