@@ -3,6 +3,7 @@ import { fixtureSync, middleOfNode, nextRender } from '@vaadin/testing-helpers';
3
3
import { resetMouse , sendKeys , sendMouse } from '@web/test-runner-commands' ;
4
4
import '@vaadin/combo-box' ;
5
5
import '@vaadin/date-picker' ;
6
+ import '@vaadin/date-time-picker' ;
6
7
import '@vaadin/grid-pro' ;
7
8
import '@vaadin/grid-pro/vaadin-grid-pro-edit-column.js' ;
8
9
import '@vaadin/time-picker' ;
@@ -15,25 +16,26 @@ describe('grid-pro custom editor', () => {
15
16
beforeEach ( async ( ) => {
16
17
grid = fixtureSync ( `
17
18
<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>
23
23
</vaadin-gri-pro>
24
24
` ) ;
25
25
26
26
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 ) => {
35
37
root . innerHTML = `
36
- <vaadin-date-picker value="${ model . item . birthday } " auto-open-disabled>
38
+ <vaadin-date-picker value="${ model . item . date } " auto-open-disabled>
37
39
</vaadin-date-picker>
38
40
` ;
39
41
} ;
@@ -54,6 +56,13 @@ describe('grid-pro custom editor', () => {
54
56
` ;
55
57
} ;
56
58
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
+
57
66
flushGrid ( grid ) ;
58
67
await nextRender ( ) ;
59
68
} ) ;
@@ -66,7 +75,7 @@ describe('grid-pro custom editor', () => {
66
75
let cell ;
67
76
68
77
beforeEach ( async ( ) => {
69
- cell = getContainerCell ( grid . $ . items , 0 , 2 ) ;
78
+ cell = getContainerCell ( grid . $ . items , 0 , 0 ) ;
70
79
cell . focus ( ) ;
71
80
72
81
await sendKeys ( { press : 'Enter' } ) ;
@@ -124,36 +133,30 @@ describe('grid-pro custom editor', () => {
124
133
} ) ;
125
134
126
135
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 ) ;
129
140
cell . focus ( ) ;
130
141
131
142
await sendKeys ( { press : 'Enter' } ) ;
143
+ } ) ;
132
144
145
+ it ( 'should apply the updated value to the cell when exiting on Tab' , async ( ) => {
133
146
await sendKeys ( { type : 'active' } ) ;
134
147
await sendKeys ( { press : 'Tab' } ) ;
135
148
136
149
expect ( cell . _content . textContent ) . to . equal ( 'active' ) ;
137
150
} ) ;
138
151
139
152
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
-
145
153
await sendKeys ( { type : 'active' } ) ;
146
154
await sendKeys ( { press : 'Enter' } ) ;
147
155
148
156
expect ( cell . _content . textContent ) . to . equal ( 'active' ) ;
149
157
} ) ;
150
158
151
159
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
-
157
160
await sendKeys ( { press : 'ArrowDown' } ) ;
158
161
await sendKeys ( { type : 'active' } ) ;
159
162
@@ -166,44 +169,91 @@ describe('grid-pro custom editor', () => {
166
169
} ) ;
167
170
168
171
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 ) ;
171
176
cell . focus ( ) ;
172
177
173
178
await sendKeys ( { press : 'Enter' } ) ;
179
+ } ) ;
174
180
181
+ it ( 'should apply the updated time to the cell when exiting on Tab' , async ( ) => {
175
182
await sendKeys ( { type : '10:00' } ) ;
176
183
await sendKeys ( { press : 'Tab' } ) ;
177
184
178
185
expect ( cell . _content . textContent ) . to . equal ( '10:00' ) ;
179
186
} ) ;
180
187
181
188
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
-
187
189
await sendKeys ( { type : '10:00' } ) ;
188
190
await sendKeys ( { press : 'Enter' } ) ;
189
191
190
192
expect ( cell . _content . textContent ) . to . equal ( '10:00' ) ;
191
193
} ) ;
192
194
193
195
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 ) ;
195
212
cell . focus ( ) ;
196
213
197
214
await sendKeys ( { press : 'Enter' } ) ;
215
+ } ) ;
198
216
217
+ it ( 'should stop editing and update value when closing on date-picker outside click' , async ( ) => {
199
218
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' } ) ;
201
231
202
232
await sendMouse ( { type : 'click' , position : [ 10 , 10 ] } ) ;
233
+ await nextRender ( ) ;
203
234
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' ) ;
205
255
expect ( editor ) . to . be . ok ;
206
- expect ( editor . value ) . to . equal ( '10 :00' ) ;
256
+ expect ( editor . value ) . to . equal ( '1984-01-13T00 :00' ) ;
207
257
} ) ;
208
258
} ) ;
209
259
} ) ;
0 commit comments