Skip to content

Commit cb501c6

Browse files
test: add date-time-picker editor to grid-pro integration test (#7864) (#7865)
Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
1 parent e6de490 commit cb501c6

File tree

1 file changed

+88
-38
lines changed

1 file changed

+88
-38
lines changed

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

Lines changed: 88 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { fixtureSync, middleOfNode, nextRender } from '@vaadin/testing-helpers';
33
import { resetMouse, sendKeys, sendMouse } from '@web/test-runner-commands';
44
import '@vaadin/combo-box';
55
import '@vaadin/date-picker';
6+
import '@vaadin/date-time-picker';
67
import '@vaadin/grid-pro';
78
import '@vaadin/grid-pro/vaadin-grid-pro-edit-column.js';
89
import '@vaadin/time-picker';
@@ -15,25 +16,26 @@ describe('grid-pro custom editor', () => {
1516
beforeEach(async () => {
1617
grid = fixtureSync(`
1718
<vaadin-grid-pro>
18-
<vaadin-grid-pro-edit-column path="firstName"></vaadin-grid-pro-edit-column>
19-
<vaadin-grid-pro-edit-column path="lastName"></vaadin-grid-pro-edit-column>
20-
<vaadin-grid-pro-edit-column path="birthday" editor-type="custom"></vaadin-grid-pro-edit-column>
21-
<vaadin-grid-pro-edit-column path="status" editor-type="custom"></vaadin-grid-pro-edit-column>
22-
<vaadin-grid-pro-edit-column path="time" editor-type="custom"></vaadin-grid-pro-edit-column>
19+
<vaadin-grid-pro-edit-column path="date" editor-type="custom" width="50px"></vaadin-grid-pro-edit-column>
20+
<vaadin-grid-pro-edit-column path="status" editor-type="custom" width="50px"></vaadin-grid-pro-edit-column>
21+
<vaadin-grid-pro-edit-column path="time" editor-type="custom" width="50px"></vaadin-grid-pro-edit-column>
22+
<vaadin-grid-pro-edit-column path="datetime" editor-type="custom"></vaadin-grid-pro-edit-column>
2323
</vaadin-gri-pro>
2424
`);
2525

2626
grid.items = [
27-
{ firstName: 'Aria', lastName: 'Bailey', birthday: '1984-01-13', status: 'suspended', time: '09:00' },
28-
{ firstName: 'Aaliyah', lastName: 'Butler', birthday: '1977-07-12', status: 'active', time: '09:30' },
29-
{ firstName: 'Eleanor', lastName: 'Price', birthday: '1976-12-14', status: 'suspended', time: '10:00' },
30-
{ firstName: 'Allison', lastName: 'Torres', birthday: '1972-12-04', status: 'active', time: '10:00' },
31-
{ firstName: 'Madeline', lastName: 'Lewis', birthday: '1978-02-03', status: 'active', time: '10:00' },
32-
];
33-
34-
grid.querySelector('[path="birthday"]').editModeRenderer = (root, _, model) => {
27+
{ date: '1984-01-13', status: 'suspended', time: '09:00' },
28+
{ date: '1977-07-12', status: 'active', time: '09:30' },
29+
{ date: '1976-12-14', status: 'suspended', time: '10:00' },
30+
{ date: '1972-12-04', status: 'active', time: '10:00' },
31+
{ date: '1978-02-03', status: 'active', time: '10:00' },
32+
].map((item) => {
33+
return { ...item, datetime: `${item.date}T${item.time}` };
34+
});
35+
36+
grid.querySelector('[path="date"]').editModeRenderer = (root, _, model) => {
3537
root.innerHTML = `
36-
<vaadin-date-picker value="${model.item.birthday}" auto-open-disabled>
38+
<vaadin-date-picker value="${model.item.date}" auto-open-disabled>
3739
</vaadin-date-picker>
3840
`;
3941
};
@@ -54,6 +56,13 @@ describe('grid-pro custom editor', () => {
5456
`;
5557
};
5658

59+
grid.querySelector('[path="datetime"]').editModeRenderer = (root, _, model) => {
60+
root.innerHTML = `
61+
<vaadin-date-time-picker value="${model.item.datetime}" auto-open-disabled>
62+
</vaadin-date-time-picker>
63+
`;
64+
};
65+
5766
flushGrid(grid);
5867
await nextRender();
5968
});
@@ -66,7 +75,7 @@ describe('grid-pro custom editor', () => {
6675
let cell;
6776

6877
beforeEach(async () => {
69-
cell = getContainerCell(grid.$.items, 0, 2);
78+
cell = getContainerCell(grid.$.items, 0, 0);
7079
cell.focus();
7180

7281
await sendKeys({ press: 'Enter' });
@@ -124,36 +133,30 @@ describe('grid-pro custom editor', () => {
124133
});
125134

126135
describe('combo-box', () => {
127-
it('should apply the updated value to the cell when exiting on Tab', async () => {
128-
const cell = getContainerCell(grid.$.items, 0, 3);
136+
let cell;
137+
138+
beforeEach(async () => {
139+
cell = getContainerCell(grid.$.items, 0, 1);
129140
cell.focus();
130141

131142
await sendKeys({ press: 'Enter' });
143+
});
132144

145+
it('should apply the updated value to the cell when exiting on Tab', async () => {
133146
await sendKeys({ type: 'active' });
134147
await sendKeys({ press: 'Tab' });
135148

136149
expect(cell._content.textContent).to.equal('active');
137150
});
138151

139152
it('should apply the updated value to the cell when exiting on Enter', async () => {
140-
const cell = getContainerCell(grid.$.items, 0, 3);
141-
cell.focus();
142-
143-
await sendKeys({ press: 'Enter' });
144-
145153
await sendKeys({ type: 'active' });
146154
await sendKeys({ press: 'Enter' });
147155

148156
expect(cell._content.textContent).to.equal('active');
149157
});
150158

151159
it('should not stop editing and update value when closing on outside click', async () => {
152-
const cell = getContainerCell(grid.$.items, 0, 3);
153-
cell.focus();
154-
155-
await sendKeys({ press: 'Enter' });
156-
157160
await sendKeys({ press: 'ArrowDown' });
158161
await sendKeys({ type: 'active' });
159162

@@ -166,44 +169,91 @@ describe('grid-pro custom editor', () => {
166169
});
167170

168171
describe('time-picker', () => {
169-
it('should apply the updated time to the cell when exiting on Tab', async () => {
170-
const cell = getContainerCell(grid.$.items, 0, 4);
172+
let cell;
173+
174+
beforeEach(async () => {
175+
cell = getContainerCell(grid.$.items, 0, 2);
171176
cell.focus();
172177

173178
await sendKeys({ press: 'Enter' });
179+
});
174180

181+
it('should apply the updated time to the cell when exiting on Tab', async () => {
175182
await sendKeys({ type: '10:00' });
176183
await sendKeys({ press: 'Tab' });
177184

178185
expect(cell._content.textContent).to.equal('10:00');
179186
});
180187

181188
it('should apply the updated value to the cell when exiting on Enter', async () => {
182-
const cell = getContainerCell(grid.$.items, 0, 4);
183-
cell.focus();
184-
185-
await sendKeys({ press: 'Enter' });
186-
187189
await sendKeys({ type: '10:00' });
188190
await sendKeys({ press: 'Enter' });
189191

190192
expect(cell._content.textContent).to.equal('10:00');
191193
});
192194

193195
it('should not stop editing and update value when closing on outside click', async () => {
194-
const cell = getContainerCell(grid.$.items, 0, 4);
196+
await sendKeys({ press: 'ArrowDown' });
197+
await sendKeys({ type: '10:00' });
198+
199+
await sendMouse({ type: 'click', position: [10, 10] });
200+
201+
const editor = cell._content.querySelector('vaadin-time-picker');
202+
expect(editor).to.be.ok;
203+
expect(editor.value).to.equal('10:00');
204+
});
205+
});
206+
207+
describe('date-time-picker', () => {
208+
let cell;
209+
210+
beforeEach(async () => {
211+
cell = getContainerCell(grid.$.items, 0, 3);
195212
cell.focus();
196213

197214
await sendKeys({ press: 'Enter' });
215+
});
198216

217+
it('should stop editing and update value when closing on date-picker outside click', async () => {
199218
await sendKeys({ press: 'ArrowDown' });
200-
await sendKeys({ type: '10:00' });
219+
await waitForOverlayRender();
220+
221+
// Move focus back to the input
222+
await sendKeys({ down: 'Shift' });
223+
await sendKeys({ press: 'Tab' });
224+
await sendKeys({ up: 'Shift' });
225+
226+
// Change single digit to avoid calendar scroll
227+
const input = cell._content.querySelector('input');
228+
input.setSelectionRange(3, 4);
229+
230+
await sendKeys({ type: '2' });
201231

202232
await sendMouse({ type: 'click', position: [10, 10] });
233+
await nextRender();
203234

204-
const editor = cell._content.querySelector('vaadin-time-picker');
235+
// TODO: closing occurs in `vaadin-overlay-outside-click` listener added on global `focusin`
236+
// in grid-pro. Consider replacing it with `_shouldRemoveFocus()` check on editor `focusout`
237+
// so that we don't stop editing on outside click, to align with the combo-box behavior.
238+
expect(cell._content.querySelector('vaadin-date-time-picker')).to.be.not.ok;
239+
expect(cell._content.textContent).to.equal('1984-01-12T09:00');
240+
});
241+
242+
it('should not stop editing and update value when closing on time-picker outside click', async () => {
243+
// TODO: replace with Tab and add a separate test to not stop editing on Tab
244+
cell._content.querySelector('vaadin-time-picker').focus();
245+
246+
// Open the overlay
247+
await sendKeys({ press: 'ArrowDown' });
248+
249+
// Select first item
250+
await sendKeys({ press: 'ArrowDown' });
251+
252+
await sendMouse({ type: 'click', position: [10, 10] });
253+
254+
const editor = cell._content.querySelector('vaadin-date-time-picker');
205255
expect(editor).to.be.ok;
206-
expect(editor.value).to.equal('10:00');
256+
expect(editor.value).to.equal('1984-01-13T00:00');
207257
});
208258
});
209259
});

0 commit comments

Comments
 (0)