Skip to content

Commit 7a358c7

Browse files
authored
test: update selection tests to not use templates (#5474)
1 parent 4251b17 commit 7a358c7

1 file changed

Lines changed: 58 additions & 81 deletions

File tree

‎packages/grid/test/selection.test.js‎

Lines changed: 58 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { expect } from '@esm-bundle/chai';
22
import { fixtureSync, listenOnce } from '@vaadin/testing-helpers';
33
import sinon from 'sinon';
4-
import '@vaadin/polymer-legacy-adapter/template-renderer.js';
54
import '../vaadin-grid.js';
65
import '../vaadin-grid-selection-column.js';
7-
import '../vaadin-grid-filter.js';
6+
import '../vaadin-grid-filter-column.js';
87
import '../vaadin-grid-column-group.js';
98
import {
109
flushGrid,
@@ -16,25 +15,6 @@ import {
1615
infiniteDataProvider,
1716
} from './helpers.js';
1817

19-
const fixtures = {
20-
renderer: `
21-
<vaadin-grid style="width: 200px; height: 200px;" size="10">
22-
<vaadin-grid-column></vaadin-grid-column>
23-
<vaadin-grid-column></vaadin-grid-column>
24-
</vaadin-grid>
25-
`,
26-
template: `
27-
<vaadin-grid style="width: 200px; height: 200px;" size="10">
28-
<vaadin-grid-column>
29-
<template>foo</template>
30-
</vaadin-grid-column>
31-
<vaadin-grid-column>
32-
<template>bar</template>
33-
</vaadin-grid-column>
34-
</vaadin-grid>
35-
`,
36-
};
37-
3818
describe('selection', () => {
3919
let grid;
4020
let rows;
@@ -50,7 +30,13 @@ describe('selection', () => {
5030

5131
describe('with renderer', () => {
5232
beforeEach(() => {
53-
grid = fixtureSync(fixtures.renderer);
33+
grid = fixtureSync(`
34+
<vaadin-grid style="width: 200px; height: 200px;" size="10">
35+
<vaadin-grid-column></vaadin-grid-column>
36+
<vaadin-grid-column></vaadin-grid-column>
37+
</vaadin-grid>
38+
`);
39+
5440
const cols = grid.children;
5541
cols[0].renderer = (root) => {
5642
root.textContent = 'foo';
@@ -127,54 +113,48 @@ describe('selection', () => {
127113
});
128114
});
129115

130-
['renderer', 'template'].forEach((type) => {
131-
describe(`${type} cells`, () => {
132-
beforeEach(() => {
133-
grid = fixtureSync(fixtures[type]);
134-
if (type === 'renderer') {
135-
const cols = grid.children;
136-
cols[0].renderer = (root) => {
137-
root.textContent = 'foo';
138-
};
139-
cols[1].renderer = (root) => {
140-
root.textContent = 'bar';
141-
};
142-
}
143-
configureGrid();
144-
});
116+
describe('renderer cells', () => {
117+
beforeEach(() => {
118+
grid = fixtureSync(`
119+
<vaadin-grid style="width: 200px; height: 200px;" size="10">
120+
<vaadin-grid-column></vaadin-grid-column>
121+
<vaadin-grid-column></vaadin-grid-column>
122+
</vaadin-grid>
123+
`);
145124

146-
(type === 'template' ? it : it.skip)('should reflect cell instance value', () => {
147-
if (type === 'template') {
148-
const cells = getRowCells(rows[0]);
149-
cells[0]._content.__templateInstance.selected = false;
150-
expect(cells[0]._content.__templateInstance.selected).to.be.false;
151-
expect(grid.selectedItems).to.be.empty;
152-
}
153-
});
125+
const cols = grid.children;
126+
cols[0].renderer = (root) => {
127+
root.textContent = 'foo';
128+
};
129+
cols[1].renderer = (root) => {
130+
root.textContent = 'bar';
131+
};
154132

155-
it('should bind to cells', () => {
156-
const cells = getRowCells(rows[0]);
157-
let cell = cells[0];
158-
let model = cell._content.__templateInstance ?? grid.__getRowModel(cell.parentElement);
159-
expect(model.selected).to.be.true;
133+
configureGrid();
134+
});
160135

161-
cell = cells[1];
162-
model = cell._content.__templateInstance ?? grid.__getRowModel(cell.parentElement);
163-
expect(model.selected).to.be.true;
136+
it('should bind to cells', () => {
137+
const cells = getRowCells(rows[0]);
138+
let cell = cells[0];
139+
let model = grid.__getRowModel(cell.parentElement);
140+
expect(model.selected).to.be.true;
164141

165-
cell = getRowCells(rows[1])[0];
166-
model = cell._content.__templateInstance ?? grid.__getRowModel(cell.parentElement);
167-
expect(model.selected).to.be.false;
168-
});
142+
cell = cells[1];
143+
model = grid.__getRowModel(cell.parentElement);
144+
expect(model.selected).to.be.true;
169145

170-
it('should select an equaling item', () => {
171-
grid.itemIdPath = 'value';
172-
const cells = getRowCells(rows[0]);
173-
grid.selectedItems = [{ value: 'foo0' }];
174-
const cell = cells[0];
175-
const model = cell._content.__templateInstance ?? grid.__getRowModel(cell.parentElement);
176-
expect(model.selected).to.be.true;
177-
});
146+
cell = getRowCells(rows[1])[0];
147+
model = grid.__getRowModel(cell.parentElement);
148+
expect(model.selected).to.be.false;
149+
});
150+
151+
it('should select an equaling item', () => {
152+
grid.itemIdPath = 'value';
153+
const cells = getRowCells(rows[0]);
154+
grid.selectedItems = [{ value: 'foo0' }];
155+
const cell = cells[0];
156+
const model = grid.__getRowModel(cell.parentElement);
157+
expect(model.selected).to.be.true;
178158
});
179159
});
180160
});
@@ -192,24 +172,20 @@ describe('multi selection column', () => {
192172
grid = fixtureSync(`
193173
<vaadin-grid style="width: 200px; height: 200px;">
194174
<vaadin-grid-selection-column auto-select></vaadin-grid-selection-column>
195-
<vaadin-grid-selection-column>
196-
<template class="header">header</template>
197-
<template>[[item]]</template>
198-
</vaadin-grid-selection-column>
175+
<vaadin-grid-selection-column header="header"></vaadin-grid-selection-column>
176+
199177
<vaadin-grid-column-group>
200178
<vaadin-grid-selection-column></vaadin-grid-selection-column>
201179
</vaadin-grid-column-group>
202-
<vaadin-grid-column>
203-
<template class="header">
204-
<vaadin-grid-filter path="value" value="[[filter]]">
205-
<input id="filter" slot="filter" value="{{filter::input}}">
206-
</vaadin-grid-filter>
207-
</template>
208-
<template></template>
209-
</vaadin-grid-column>
180+
181+
<vaadin-grid-filter-column path="value"></vaadin-grid-filter-column>
210182
</vaadin-grid>
211183
`);
212184

185+
grid.querySelector('[header="header"]').renderer = (root, _, { item }) => {
186+
root.textContent = item;
187+
};
188+
213189
grid.items = ['foo', 'bar', 'baz'];
214190

215191
flushGrid(grid);
@@ -346,13 +322,13 @@ describe('multi selection column', () => {
346322
expect(selectAllCheckbox.hidden).to.be.false;
347323
});
348324

349-
it('should be possible to override the body template', () => {
325+
it('should be possible to override the body renderer', () => {
350326
const secondCell = getCellContent(getRowCells(rows[0])[1]);
351327

352328
expect(secondCell.innerHTML).to.eql(secondCell.textContent);
353329
});
354330

355-
it('should be possible to override the header template', () => {
331+
it('should be possible to override the header renderer', () => {
356332
const secondCell = getCellContent(getRowCells(headerRows[1])[1]);
357333

358334
expect(secondCell.innerHTML).to.eql('header');
@@ -471,11 +447,12 @@ describe('multi selection column', () => {
471447

472448
firstBodyCheckbox.checked = true;
473449

474-
const filter = grid.querySelector('#filter');
450+
const filter = grid.querySelector('vaadin-grid-filter');
475451
filter.value = 'foo';
476452
filter.dispatchEvent(new CustomEvent('input', { bubbles: true, composed: true }));
477453

478-
filter.parentElement._debouncerFilterChanged.flush();
454+
filter._debouncerFilterChanged.flush();
455+
479456
expect(selectionColumn.selectAll).to.be.true;
480457
});
481458

0 commit comments

Comments
 (0)