Skip to content

Commit 274c8d9

Browse files
committed
test: use plain numbers as item IDs
1 parent 1415b01 commit 274c8d9

6 files changed

Lines changed: 43 additions & 55 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ describe('dashboard layout', () => {
2828
beforeEach(async () => {
2929
dashboard = fixtureSync(`
3030
<vaadin-dashboard-layout>
31-
<div id="item-0">Item 0</div>
32-
<div id="item-1">Item 1</div>
31+
<div id="0">Item 0</div>
32+
<div id="1">Item 1</div>
3333
</vaadin-dashboard-layout>
3434
`);
3535
childElements = [...dashboard.children] as HTMLElement[];
@@ -413,8 +413,8 @@ describe('dashboard layout', () => {
413413
beforeEach(async () => {
414414
section = fixtureSync(`
415415
<vaadin-dashboard-section section-title="Section">
416-
<div id="item-2">Section item 2</div>
417-
<div id="item-3">Section item 3</div>
416+
<div id="2">Section item 2</div>
417+
<div id="3">Section item 3</div>
418418
</vaadin-dashboard-section>
419419
`);
420420
dashboard.appendChild(section);
@@ -443,7 +443,7 @@ describe('dashboard layout', () => {
443443

444444
it('following items should end up in the next row', async () => {
445445
dashboard.style.width = `${columnWidth * 4}px`;
446-
dashboard.appendChild(fixtureSync('<div id="item-4">Item 4</div>'));
446+
dashboard.appendChild(fixtureSync('<div id="4">Item 4</div>'));
447447
await onceResized(dashboard);
448448

449449
/* prettier-ignore */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ describe('dashboard section', () => {
1616
beforeEach(async () => {
1717
section = fixtureSync(`
1818
<vaadin-dashboard-section>
19-
<div id="item-0">Item 0</div>
20-
<div id="item-1">Item 1</div>
19+
<div id="0">Item 0</div>
20+
<div id="1">Item 1</div>
2121
</vaadin-dashboard-section>
2222
`);
2323
await nextFrame();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('dashboard - widget reordering', () => {
3939
dashboard.renderer = (root, _, model) => {
4040
root.textContent = '';
4141
const widget = fixtureSync(`
42-
<vaadin-dashboard-widget id="item-${model.item.id}" widget-title="${model.item.id} title">
42+
<vaadin-dashboard-widget id="${model.item.id}" widget-title="${model.item.id} title">
4343
<div class="content">Widget content</div>
4444
</vaadin-dashboard-widget>`);
4545
root.appendChild(widget);
@@ -591,13 +591,13 @@ describe('dashboard - widget reordering', () => {
591591

592592
// Make sure the original dragged element is removed from the host if it was
593593
// restored.
594-
expect(dashboard.querySelectorAll(`vaadin-dashboard-widget[id='item-0']`).length).to.equal(1);
594+
expect(dashboard.querySelectorAll(`vaadin-dashboard-widget[id='0']`).length).to.equal(1);
595595
});
596596

597597
it('should not remove dragged element with a renderer that reuses same instances', async () => {
598598
const reusedWidgets = [
599-
fixtureSync('<vaadin-dashboard-widget id="item-0" widget-title="0 title"></vaadin-dashboard-widget>'),
600-
fixtureSync('<vaadin-dashboard-widget id="item-1" widget-title="1 title"></vaadin-dashboard-widget>'),
599+
fixtureSync('<vaadin-dashboard-widget id="0" widget-title="0 title"></vaadin-dashboard-widget>'),
600+
fixtureSync('<vaadin-dashboard-widget id="1" widget-title="1 title"></vaadin-dashboard-widget>'),
601601
];
602602
dashboard.renderer = (root, _, model) => {
603603
root.textContent = '';

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('dashboard - widget resizing', () => {
3939
dashboard.renderer = (root, _, model) => {
4040
root.textContent = '';
4141
const widget = fixtureSync(`
42-
<vaadin-dashboard-widget id="item-${model.item.id}" widget-title="${model.item.id} title">
42+
<vaadin-dashboard-widget id="${model.item.id}" widget-title="${model.item.id} title">
4343
<div class="content">Widget content</div>
4444
</vaadin-dashboard-widget>`);
4545
root.appendChild(widget);
@@ -495,13 +495,13 @@ describe('dashboard - widget resizing', () => {
495495

496496
// Make sure the original dragged element is removed from the host if it was
497497
// restored.
498-
expect(dashboard.querySelectorAll(`vaadin-dashboard-widget[id='item-0']`).length).to.equal(1);
498+
expect(dashboard.querySelectorAll(`vaadin-dashboard-widget[id='0']`).length).to.equal(1);
499499
});
500500

501501
it('should not remove resized element with a renderer that reuses same instances', async () => {
502502
const reusedWidgets = [
503-
fixtureSync('<vaadin-dashboard-widget id="item-0" widget-title="0 title"></vaadin-dashboard-widget>'),
504-
fixtureSync('<vaadin-dashboard-widget id="item-1" widget-title="1 title"></vaadin-dashboard-widget>'),
503+
fixtureSync('<vaadin-dashboard-widget id="0" widget-title="0 title"></vaadin-dashboard-widget>'),
504+
fixtureSync('<vaadin-dashboard-widget id="1" widget-title="1 title"></vaadin-dashboard-widget>'),
505505
];
506506
dashboard.renderer = (root, _, model) => {
507507
root.textContent = '';

‎packages/dashboard/test/dashboard.test.ts‎

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ describe('dashboard', () => {
3232
setMaximumColumnWidth(dashboard, columnWidth);
3333
setGap(dashboard, 0);
3434

35-
dashboard.items = [{ id: 'Item 0' }, { id: 'Item 1' }];
35+
dashboard.items = [{ id: '0' }, { id: '1' }];
3636
dashboard.renderer = (root, _, model) => {
3737
root.textContent = '';
3838
const widget = document.createElement('vaadin-dashboard-widget');
39-
widget.widgetTitle = `${model.item.id} title`;
39+
widget.widgetTitle = `Item ${model.item.id} title`;
40+
widget.id = model.item.id;
4041
root.appendChild(widget);
4142
};
4243
await nextFrame();
@@ -55,7 +56,7 @@ describe('dashboard', () => {
5556
});
5657

5758
it('should render a new widget', async () => {
58-
dashboard.items = [...dashboard.items, { id: 'Item 2' }];
59+
dashboard.items = [...dashboard.items, { id: '2' }];
5960
await nextFrame();
6061

6162
const newWidget = getElementFromCell(dashboard, 1, 0);
@@ -68,7 +69,7 @@ describe('dashboard', () => {
6869
dashboard.renderer = (root, _, model) => {
6970
root.textContent = '';
7071
const widget = document.createElement('vaadin-dashboard-widget');
71-
widget.widgetTitle = `${model.item.id} new title`;
72+
widget.widgetTitle = `Item ${model.item.id} new title`;
7273
root.appendChild(widget);
7374
};
7475
await nextFrame();
@@ -98,7 +99,7 @@ describe('dashboard', () => {
9899
it('should remove a widget', () => {
99100
const widget = getElementFromCell(dashboard, 0, 1);
100101
getRemoveButton(widget as DashboardWidget).click();
101-
expect(dashboard.items).to.eql([{ id: 'Item 0' }]);
102+
expect(dashboard.items).to.eql([{ id: '0' }]);
102103
});
103104

104105
it('should dispatch an dashboard-item-removed event', () => {
@@ -107,8 +108,8 @@ describe('dashboard', () => {
107108
const widget = getElementFromCell(dashboard, 0, 1);
108109
getRemoveButton(widget as DashboardWidget).click();
109110
expect(spy).to.be.calledOnce;
110-
expect(spy.firstCall.args[0].detail.item).to.eql({ id: 'Item 1' });
111-
expect(spy.firstCall.args[0].detail.items).to.eql([{ id: 'Item 0' }]);
111+
expect(spy.firstCall.args[0].detail.item).to.eql({ id: '1' });
112+
expect(spy.firstCall.args[0].detail.items).to.eql([{ id: '0' }]);
112113
});
113114

114115
it('should not dispatch an item-remove event', () => {
@@ -143,7 +144,7 @@ describe('dashboard', () => {
143144
});
144145

145146
it('should span multiple columns', async () => {
146-
dashboard.items = [{ colspan: 2, id: 'Item 0' }];
147+
dashboard.items = [{ colspan: 2, id: '0' }];
147148
await nextFrame();
148149

149150
const widget = getElementFromCell(dashboard, 0, 0);
@@ -162,7 +163,7 @@ describe('dashboard', () => {
162163

163164
it('should span multiple rows', async () => {
164165
dashboard.style.width = `${columnWidth}px`;
165-
dashboard.items = [{ rowspan: 2, id: 'Item 0' }];
166+
dashboard.items = [{ rowspan: 2, id: '0' }];
166167
await onceResized(dashboard);
167168

168169
const widget = getElementFromCell(dashboard, 0, 0);
@@ -254,11 +255,7 @@ describe('dashboard', () => {
254255

255256
describe('section', () => {
256257
beforeEach(async () => {
257-
dashboard.items = [
258-
{ id: 'Item 0' },
259-
{ id: 'Item 1' },
260-
{ title: 'Section', items: [{ id: 'Item 2' }, { id: 'Item 3' }] },
261-
];
258+
dashboard.items = [{ id: '0' }, { id: '1' }, { title: 'Section', items: [{ id: '2' }, { id: '3' }] }];
262259
await nextFrame();
263260
});
264261

@@ -290,7 +287,7 @@ describe('dashboard', () => {
290287
const widget = getElementFromCell(dashboard, 1, 0);
291288
const section = widget?.closest('vaadin-dashboard-section');
292289
getRemoveButton(section!).click();
293-
expect(dashboard.items).to.eql([{ id: 'Item 0' }, { id: 'Item 1' }]);
290+
expect(dashboard.items).to.eql([{ id: '0' }, { id: '1' }]);
294291
});
295292
});
296293

@@ -357,11 +354,7 @@ describe('dashboard', () => {
357354

358355
describe('section', () => {
359356
beforeEach(async () => {
360-
dashboard.items = [
361-
{ id: 'Item 0' },
362-
{ id: 'Item 1' },
363-
{ title: 'Section', items: [{ id: 'Item 2' }, { id: 'Item 3' }] },
364-
];
357+
dashboard.items = [{ id: '0' }, { id: '1' }, { title: 'Section', items: [{ id: '2' }, { id: '3' }] }];
365358
await nextFrame();
366359
});
367360

@@ -420,14 +413,14 @@ describe('dashboard', () => {
420413
describe('item components', () => {
421414
it('should use the item component as widget', async () => {
422415
const widget = fixtureSync('<vaadin-dashboard-widget widget-title="Component 0"></vaadin-dashboard-widget>');
423-
dashboard.items = [{ id: 'Item 0', component: widget }];
416+
dashboard.items = [{ id: '0', component: widget }];
424417
await nextFrame();
425418

426419
expect(getElementFromCell(dashboard, 0, 0)).to.equal(widget);
427420
});
428421

429422
it('should render default widgets if component is not an element', async () => {
430-
dashboard.items = [{ id: 'Item 0', component: 'not-an-element' }];
423+
dashboard.items = [{ id: '0', component: 'not-an-element' }];
431424
await nextFrame();
432425

433426
const widget = getElementFromCell(dashboard, 0, 0);
@@ -440,7 +433,7 @@ describe('dashboard', () => {
440433
const renderer = sinon.spy();
441434
dashboard.renderer = renderer;
442435
const widget = fixtureSync('<vaadin-dashboard-widget widget-title="Component 0"></vaadin-dashboard-widget>');
443-
dashboard.items = [{ id: 'Item 0', component: widget }];
436+
dashboard.items = [{ id: '0', component: widget }];
444437
await nextFrame();
445438

446439
expect(renderer).to.not.be.called;
@@ -452,7 +445,7 @@ describe('dashboard', () => {
452445
(dashboard as any).items = [
453446
{
454447
component: section,
455-
items: [{ id: 'Item 0', component: widget }],
448+
items: [{ id: '0', component: widget }],
456449
},
457450
];
458451
await nextFrame();
@@ -462,7 +455,7 @@ describe('dashboard', () => {
462455
});
463456

464457
it('should render default section if component is not an element', async () => {
465-
(dashboard as any).items = [{ component: 'not-an-element', title: 'Section', items: [{ id: 'Item 0' }] }];
458+
(dashboard as any).items = [{ component: 'not-an-element', title: 'Section', items: [{ id: '0' }] }];
466459
await nextFrame();
467460

468461
const widget = getElementFromCell(dashboard, 0, 0);
@@ -486,7 +479,7 @@ describe('dashboard', () => {
486479
(dashboard as any).items = [
487480
{
488481
component: section,
489-
items: [{ id: 'Item 0', component: widget }],
482+
items: [{ id: '0', component: widget }],
490483
},
491484
];
492485
await nextFrame();
@@ -523,7 +516,7 @@ describe('dashboard', () => {
523516

524517
it('should not lose focus when prepending items', async () => {
525518
getElementFromCell(dashboard, 0, 0)!.focus();
526-
dashboard.items = [{ id: 'Item -1' }, ...dashboard.items];
519+
dashboard.items = [{ id: '-1' }, ...dashboard.items];
527520
await nextFrame();
528521
expect(document.activeElement).to.equal(getElementFromCell(dashboard, 0, 1)!);
529522
});
@@ -536,7 +529,7 @@ describe('dashboard', () => {
536529
});
537530

538531
it('should not lose focus when reassigning section items', async () => {
539-
dashboard.items = [{ title: 'Section', items: [{ id: 'Item 0' }] }, { id: 'Item 1' }];
532+
dashboard.items = [{ title: 'Section', items: [{ id: '0' }] }, { id: '1' }];
540533
await nextFrame();
541534
getElementFromCell(dashboard, 0, 0)!.focus();
542535
dashboard.items = [...dashboard.items];
@@ -555,7 +548,7 @@ describe('dashboard', () => {
555548
});
556549

557550
it('should unhide remove button of a section when editable', async () => {
558-
dashboard.items = [{ title: 'Section', items: [{ id: 'Item 0' }] }, { id: 'Item 1' }];
551+
dashboard.items = [{ title: 'Section', items: [{ id: '0' }] }, { id: '1' }];
559552
await nextFrame();
560553
getElementFromCell(dashboard, 0, 0)!.focus();
561554
await nextFrame();
@@ -572,11 +565,7 @@ describe('dashboard', () => {
572565
dashboard.editable = true;
573566
await nextFrame();
574567

575-
dashboard.items = [
576-
{ id: 'Item 0' },
577-
{ id: 'Item 1' },
578-
{ title: 'Section', items: [{ id: 'Item 2' }, { id: 'Item 3' }] },
579-
];
568+
dashboard.items = [{ id: '0' }, { id: '1' }, { title: 'Section', items: [{ id: '2' }, { id: '3' }] }];
580569
await nextFrame();
581570

582571
/* prettier-ignore */
@@ -650,7 +639,7 @@ describe('dashboard', () => {
650639
it('should focus a new widget when items are replaced', async () => {
651640
getElementFromCell(dashboard, 0, 0)!.focus();
652641
await nextFrame();
653-
dashboard.items = [{ id: 'Item 100' }];
642+
dashboard.items = [{ id: '100' }];
654643
await renderAndFocusRestore();
655644
expect(document.activeElement).to.equal(getElementFromCell(dashboard, 0, 0)!);
656645
});

‎packages/dashboard/test/helpers.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ export function setMinimumRowHeight(dashboard: HTMLElement, height?: number): vo
135135
* cells of the grid match the expected IDs.
136136
*
137137
* For example, the following layout would expect a grid with two columns
138-
* and three rows, where the first row has one element with ID "item-0" spanning
139-
* two columns, and the second row has two elements with IDs "item-1" and "item-2"
138+
* and three rows, where the first row has one element with ID "0" spanning
139+
* two columns, and the second row has two elements with IDs "1" and "2"
140140
* where the first one spans two rows, and the last cell in the third row has
141-
* an element with ID "item-3":
141+
* an element with ID "3":
142142
*
143143
* ```
144144
* [
@@ -165,8 +165,7 @@ export function expectLayout(dashboard: HTMLElement, layout: Array<Array<number
165165
if (!element) {
166166
actualRow.push(null);
167167
} else {
168-
// TODO: Just use a number for all test item IDs
169-
actualRow.push(parseInt(element.id.replace('item-', '').replace('Item ', ''), 10));
168+
actualRow.push(parseInt(element.id));
170169
}
171170
});
172171
});

0 commit comments

Comments
 (0)