@@ -15,7 +15,7 @@ import { dblclick, flushGrid, getContainerCell } from '@vaadin/grid-pro/test/hel
15
15
describe ( 'grid-pro custom editor' , ( ) => {
16
16
let grid , cell ;
17
17
18
- function createGrid ( path ) {
18
+ function createGrid ( path , autoOpen = false ) {
19
19
grid = fixtureSync ( `
20
20
<vaadin-grid-pro>
21
21
<vaadin-grid-pro-edit-column path="${ path } " editor-type="custom"></vaadin-grid-pro-edit-column>
@@ -25,9 +25,9 @@ describe('grid-pro custom editor', () => {
25
25
const column = grid . querySelector ( `[path="${ path } "]` ) ;
26
26
switch ( path ) {
27
27
case 'date' :
28
- column . editModeRenderer = ( root , column , model ) => {
28
+ column . editModeRenderer = ( root , _ , model ) => {
29
29
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>
31
31
` ;
32
32
} ;
33
33
break ;
@@ -99,86 +99,99 @@ describe('grid-pro custom editor', () => {
99
99
} ) ;
100
100
101
101
describe ( 'date-picker' , ( ) => {
102
- beforeEach ( async ( ) => {
103
- grid = createGrid ( 'date' ) ;
104
- await nextRender ( ) ;
105
- await editFirstCell ( ) ;
106
- } ) ;
102
+ describe ( 'desktop' , ( ) => {
103
+ let width , height ;
107
104
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
+ } ) ;
111
110
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
+ } ) ;
114
116
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
+ } ) ;
118
120
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' } ) ;
121
124
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
+ } ) ;
125
127
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' } ) ;
128
131
129
- expect ( cell . _content . querySelector ( 'vaadin-date-picker' ) ) . to . be . ok ;
130
- } ) ;
132
+ expect ( cell . _content . textContent ) . to . equal ( '1984-01-12' ) ;
133
+ } ) ;
131
134
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' } ) ;
136
138
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 } ) ;
142
141
143
- expect ( cell . _content . querySelector ( 'vaadin-date-picker' ) ) . to . be . ok ;
144
- } ) ;
142
+ expect ( cell . _content . querySelector ( 'vaadin-date-picker' ) ) . to . be . ok ;
143
+ } ) ;
145
144
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' ) ) ;
150
149
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 ( ) ;
153
155
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
+ } ) ;
157
158
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' ) ) ;
159
163
160
- await sendMouse ( { type : 'click' , position : [ 10 , 10 ] } ) ;
161
- await nextRender ( ) ;
164
+ // Move focus back to the input
165
+ await sendKeys ( { press : 'Shift+Tab' } ) ;
162
166
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
+ } ) ;
166
180
} ) ;
167
181
168
182
describe ( 'mobile' , ( ) => {
169
183
let width , height ;
170
184
171
- before ( ( ) => {
185
+ before ( async ( ) => {
172
186
width = window . innerWidth ;
173
187
height = window . innerHeight ;
188
+ await setViewport ( { width : 420 , height : 600 } ) ;
174
189
} ) ;
175
190
176
191
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 ( ) ;
180
194
cell = getContainerCell ( grid . $ . items , 0 , 0 ) ;
181
- await sendMouse ( { type : 'click' , position : [ 10 , 10 ] } ) ;
182
195
} ) ;
183
196
184
197
after ( async ( ) => {
0 commit comments