Skip to content

Commit 2621e67

Browse files
authored
test: make grid-pro date-picker editor tests more reliable (#10071)
1 parent 4110f05 commit 2621e67

File tree

1 file changed

+69
-56
lines changed

1 file changed

+69
-56
lines changed

test/integration/grid-pro-custom-editor.test.js

Lines changed: 69 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { dblclick, flushGrid, getContainerCell } from '@vaadin/grid-pro/test/hel
1515
describe('grid-pro custom editor', () => {
1616
let grid, cell;
1717

18-
function createGrid(path) {
18+
function createGrid(path, autoOpen = false) {
1919
grid = fixtureSync(`
2020
<vaadin-grid-pro>
2121
<vaadin-grid-pro-edit-column path="${path}" editor-type="custom"></vaadin-grid-pro-edit-column>
@@ -25,9 +25,9 @@ describe('grid-pro custom editor', () => {
2525
const column = grid.querySelector(`[path="${path}"]`);
2626
switch (path) {
2727
case 'date':
28-
column.editModeRenderer = (root, column, model) => {
28+
column.editModeRenderer = (root, _, model) => {
2929
root.innerHTML = `
30-
<vaadin-date-picker value="${model.item.date}" ${!column.autoOpen ? 'auto-open-disabled' : ''}></vaadin-date-picker>
30+
<vaadin-date-picker value="${model.item.date}" ${!autoOpen ? 'auto-open-disabled' : ''}></vaadin-date-picker>
3131
`;
3232
};
3333
break;
@@ -99,86 +99,99 @@ describe('grid-pro custom editor', () => {
9999
});
100100

101101
describe('date-picker', () => {
102-
beforeEach(async () => {
103-
grid = createGrid('date');
104-
await nextRender();
105-
await editFirstCell();
106-
});
102+
describe('desktop', () => {
103+
let width, height;
107104

108-
it('should apply the updated date to the cell when exiting on Tab', async () => {
109-
await sendKeys({ type: '1/12/1984' });
110-
await sendKeys({ press: 'Tab' });
105+
before(async () => {
106+
width = window.innerWidth;
107+
height = window.innerHeight;
108+
await setViewport({ width: 800, height: 600 });
109+
});
111110

112-
expect(cell._content.textContent).to.equal('1984-01-12');
113-
});
111+
beforeEach(async () => {
112+
grid = createGrid('date');
113+
await nextRender();
114+
await editFirstCell();
115+
});
114116

115-
it('should apply the updated date to the cell when exiting on Enter', async () => {
116-
await sendKeys({ type: '1/12/1984' });
117-
await sendKeys({ press: 'Enter' });
117+
after(async () => {
118+
await setViewport({ width, height });
119+
});
118120

119-
expect(cell._content.textContent).to.equal('1984-01-12');
120-
});
121+
it('should apply the updated date to the cell when exiting on Tab', async () => {
122+
await sendKeys({ type: '1/12/1984' });
123+
await sendKeys({ press: 'Tab' });
121124

122-
it('should not stop editing on input click when focus is in the overlay', async () => {
123-
// Open the overlay
124-
await sendKeys({ press: 'ArrowDown' });
125+
expect(cell._content.textContent).to.equal('1984-01-12');
126+
});
125127

126-
const input = cell._content.querySelector('input');
127-
await sendMouseToElement({ type: 'click', element: input });
128+
it('should apply the updated date to the cell when exiting on Enter', async () => {
129+
await sendKeys({ type: '1/12/1984' });
130+
await sendKeys({ press: 'Enter' });
128131

129-
expect(cell._content.querySelector('vaadin-date-picker')).to.be.ok;
130-
});
132+
expect(cell._content.textContent).to.equal('1984-01-12');
133+
});
131134

132-
it('should not stop editing when clicking inside the overlay but not on focusable element', async () => {
133-
// Open the overlay
134-
await sendKeys({ press: 'ArrowDown' });
135-
await untilOverlayRendered(cell._content.querySelector('vaadin-date-picker'));
135+
it('should not stop editing on input click when focus is in the overlay', async () => {
136+
// Open the overlay
137+
await sendKeys({ press: 'ArrowDown' });
136138

137-
// Click between toolbar buttons
138-
const overlayContent = document.querySelector('vaadin-date-picker-overlay-content');
139-
const toolbar = overlayContent.shadowRoot.querySelector('[part="toolbar"]');
140-
await sendMouseToElement({ type: 'click', element: toolbar });
141-
await nextRender();
139+
const input = cell._content.querySelector('input');
140+
await sendMouseToElement({ type: 'click', element: input });
142141

143-
expect(cell._content.querySelector('vaadin-date-picker')).to.be.ok;
144-
});
142+
expect(cell._content.querySelector('vaadin-date-picker')).to.be.ok;
143+
});
145144

146-
it('should not stop editing and update value when closing on outside click', async () => {
147-
// Open the overlay
148-
await sendKeys({ press: 'ArrowDown' });
149-
await untilOverlayRendered(cell._content.querySelector('vaadin-date-picker'));
145+
it('should not stop editing when clicking inside the overlay but not on focusable element', async () => {
146+
// Open the overlay
147+
await sendKeys({ press: 'ArrowDown' });
148+
await untilOverlayRendered(cell._content.querySelector('vaadin-date-picker'));
150149

151-
// Move focus back to the input
152-
await sendKeys({ press: 'Shift+Tab' });
150+
// Click between toolbar buttons
151+
const overlayContent = document.querySelector('vaadin-date-picker-overlay-content');
152+
const toolbar = overlayContent.shadowRoot.querySelector('[part="toolbar"]');
153+
await sendMouseToElement({ type: 'click', element: toolbar });
154+
await nextRender();
153155

154-
// Change single digit to avoid calendar scroll
155-
const input = cell._content.querySelector('input');
156-
input.setSelectionRange(3, 4);
156+
expect(cell._content.querySelector('vaadin-date-picker')).to.be.ok;
157+
});
157158

158-
await sendKeys({ type: '2' });
159+
it('should not stop editing and update value when closing on outside click', async () => {
160+
// Open the overlay
161+
await sendKeys({ press: 'ArrowDown' });
162+
await untilOverlayRendered(cell._content.querySelector('vaadin-date-picker'));
159163

160-
await sendMouse({ type: 'click', position: [10, 10] });
161-
await nextRender();
164+
// Move focus back to the input
165+
await sendKeys({ press: 'Shift+Tab' });
162166

163-
const editor = cell._content.querySelector('vaadin-date-picker');
164-
expect(editor).to.be.ok;
165-
expect(editor.value).to.equal('1984-01-12');
167+
// Change single digit to avoid calendar scroll
168+
const input = cell._content.querySelector('input');
169+
input.setSelectionRange(3, 4);
170+
171+
await sendKeys({ type: '2' });
172+
173+
await sendMouse({ type: 'click', position: [10, 10] });
174+
await nextRender();
175+
176+
const editor = cell._content.querySelector('vaadin-date-picker');
177+
expect(editor).to.be.ok;
178+
expect(editor.value).to.equal('1984-01-12');
179+
});
166180
});
167181

168182
describe('mobile', () => {
169183
let width, height;
170184

171-
before(() => {
185+
before(async () => {
172186
width = window.innerWidth;
173187
height = window.innerHeight;
188+
await setViewport({ width: 420, height: 600 });
174189
});
175190

176191
beforeEach(async () => {
177-
await setViewport({ width: 420, height: 1020 });
178-
// Do not set auto-open-disabled on the date-picker
179-
grid.querySelector('vaadin-grid-pro-edit-column').autoOpen = true;
192+
grid = createGrid('date', true);
193+
await nextRender();
180194
cell = getContainerCell(grid.$.items, 0, 0);
181-
await sendMouse({ type: 'click', position: [10, 10] });
182195
});
183196

184197
after(async () => {

0 commit comments

Comments
 (0)