@@ -15,7 +15,7 @@ import { dblclick, flushGrid, getContainerCell } from '@vaadin/grid-pro/test/hel
1515describe ( '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>
@@ -46,9 +46,9 @@ describe('grid-pro custom editor', () => {
4646 const column = grid . querySelector ( `[path="${ path } "]` ) ;
4747 switch ( path ) {
4848 case 'date' :
49- column . editModeRenderer = ( root , column , model ) => {
49+ column . editModeRenderer = ( root , _ , model ) => {
5050 root . innerHTML = `
51- <vaadin-date-picker value="${ model . item . date } " ${ ! column . autoOpen ? 'auto-open-disabled' : '' } ></vaadin-date-picker>
51+ <vaadin-date-picker value="${ model . item . date } " ${ ! autoOpen ? 'auto-open-disabled' : '' } ></vaadin-date-picker>
5252 ` ;
5353 } ;
5454 break ;
@@ -120,86 +120,99 @@ describe('grid-pro custom editor', () => {
120120 } ) ;
121121
122122 describe ( 'date-picker' , ( ) => {
123- beforeEach ( async ( ) => {
124- grid = createGrid ( 'date' ) ;
125- await nextRender ( ) ;
126- await editFirstCell ( ) ;
127- } ) ;
123+ describe ( 'desktop' , ( ) => {
124+ let width , height ;
128125
129- it ( 'should apply the updated date to the cell when exiting on Tab' , async ( ) => {
130- await sendKeys ( { type : '1/12/1984' } ) ;
131- await sendKeys ( { press : 'Tab' } ) ;
126+ before ( async ( ) => {
127+ width = window . innerWidth ;
128+ height = window . innerHeight ;
129+ await setViewport ( { width : 800 , height : 600 } ) ;
130+ } ) ;
132131
133- expect ( cell . _content . textContent ) . to . equal ( '1984-01-12' ) ;
134- } ) ;
132+ beforeEach ( async ( ) => {
133+ grid = createGrid ( 'date' ) ;
134+ await nextRender ( ) ;
135+ await editFirstCell ( ) ;
136+ } ) ;
135137
136- it ( 'should apply the updated date to the cell when exiting on Enter' , async ( ) => {
137- await sendKeys ( { type : '1/12/1984' } ) ;
138- await sendKeys ( { press : 'Enter' } ) ;
138+ after ( async ( ) => {
139+ await setViewport ( { width , height } ) ;
140+ } ) ;
139141
140- expect ( cell . _content . textContent ) . to . equal ( '1984-01-12' ) ;
141- } ) ;
142+ it ( 'should apply the updated date to the cell when exiting on Tab' , async ( ) => {
143+ await sendKeys ( { type : '1/12/1984' } ) ;
144+ await sendKeys ( { press : 'Tab' } ) ;
142145
143- it ( 'should not stop editing on input click when focus is in the overlay' , async ( ) => {
144- // Open the overlay
145- await sendKeys ( { press : 'ArrowDown' } ) ;
146+ expect ( cell . _content . textContent ) . to . equal ( '1984-01-12' ) ;
147+ } ) ;
146148
147- const input = cell . _content . querySelector ( 'input' ) ;
148- await sendMouseToElement ( { type : 'click' , element : input } ) ;
149+ it ( 'should apply the updated date to the cell when exiting on Enter' , async ( ) => {
150+ await sendKeys ( { type : '1/12/1984' } ) ;
151+ await sendKeys ( { press : 'Enter' } ) ;
149152
150- expect ( cell . _content . querySelector ( 'vaadin-date-picker' ) ) . to . be . ok ;
151- } ) ;
153+ expect ( cell . _content . textContent ) . to . equal ( '1984-01-12' ) ;
154+ } ) ;
152155
153- it ( 'should not stop editing when clicking inside the overlay but not on focusable element' , async ( ) => {
154- // Open the overlay
155- await sendKeys ( { press : 'ArrowDown' } ) ;
156- await untilOverlayRendered ( cell . _content . querySelector ( 'vaadin-date-picker' ) ) ;
156+ it ( 'should not stop editing on input click when focus is in the overlay' , async ( ) => {
157+ // Open the overlay
158+ await sendKeys ( { press : 'ArrowDown' } ) ;
157159
158- // Click between toolbar buttons
159- const overlayContent = document . querySelector ( 'vaadin-date-picker-overlay-content' ) ;
160- const toolbar = overlayContent . shadowRoot . querySelector ( '[part="toolbar"]' ) ;
161- await sendMouseToElement ( { type : 'click' , element : toolbar } ) ;
162- await nextRender ( ) ;
160+ const input = cell . _content . querySelector ( 'input' ) ;
161+ await sendMouseToElement ( { type : 'click' , element : input } ) ;
163162
164- expect ( cell . _content . querySelector ( 'vaadin-date-picker' ) ) . to . be . ok ;
165- } ) ;
163+ expect ( cell . _content . querySelector ( 'vaadin-date-picker' ) ) . to . be . ok ;
164+ } ) ;
166165
167- it ( 'should not stop editing and update value when closing on outside click ' , async ( ) => {
168- // Open the overlay
169- await sendKeys ( { press : 'ArrowDown' } ) ;
170- await untilOverlayRendered ( cell . _content . querySelector ( 'vaadin-date-picker' ) ) ;
166+ it ( 'should not stop editing when clicking inside the overlay but not on focusable element ' , async ( ) => {
167+ // Open the overlay
168+ await sendKeys ( { press : 'ArrowDown' } ) ;
169+ await untilOverlayRendered ( cell . _content . querySelector ( 'vaadin-date-picker' ) ) ;
171170
172- // Move focus back to the input
173- await sendKeys ( { press : 'Shift+Tab' } ) ;
171+ // Click between toolbar buttons
172+ const overlayContent = document . querySelector ( 'vaadin-date-picker-overlay-content' ) ;
173+ const toolbar = overlayContent . shadowRoot . querySelector ( '[part="toolbar"]' ) ;
174+ await sendMouseToElement ( { type : 'click' , element : toolbar } ) ;
175+ await nextRender ( ) ;
174176
175- // Change single digit to avoid calendar scroll
176- const input = cell . _content . querySelector ( 'input' ) ;
177- input . setSelectionRange ( 3 , 4 ) ;
177+ expect ( cell . _content . querySelector ( 'vaadin-date-picker' ) ) . to . be . ok ;
178+ } ) ;
178179
179- await sendKeys ( { type : '2' } ) ;
180+ it ( 'should not stop editing and update value when closing on outside click' , async ( ) => {
181+ // Open the overlay
182+ await sendKeys ( { press : 'ArrowDown' } ) ;
183+ await untilOverlayRendered ( cell . _content . querySelector ( 'vaadin-date-picker' ) ) ;
180184
181- await sendMouse ( { type : 'click' , position : [ 10 , 10 ] } ) ;
182- await nextRender ( ) ;
185+ // Move focus back to the input
186+ await sendKeys ( { press : 'Shift+Tab' } ) ;
183187
184- const editor = cell . _content . querySelector ( 'vaadin-date-picker' ) ;
185- expect ( editor ) . to . be . ok ;
186- expect ( editor . value ) . to . equal ( '1984-01-12' ) ;
188+ // Change single digit to avoid calendar scroll
189+ const input = cell . _content . querySelector ( 'input' ) ;
190+ input . setSelectionRange ( 3 , 4 ) ;
191+
192+ await sendKeys ( { type : '2' } ) ;
193+
194+ await sendMouse ( { type : 'click' , position : [ 10 , 10 ] } ) ;
195+ await nextRender ( ) ;
196+
197+ const editor = cell . _content . querySelector ( 'vaadin-date-picker' ) ;
198+ expect ( editor ) . to . be . ok ;
199+ expect ( editor . value ) . to . equal ( '1984-01-12' ) ;
200+ } ) ;
187201 } ) ;
188202
189203 describe ( 'mobile' , ( ) => {
190204 let width , height ;
191205
192- before ( ( ) => {
206+ before ( async ( ) => {
193207 width = window . innerWidth ;
194208 height = window . innerHeight ;
209+ await setViewport ( { width : 420 , height : 600 } ) ;
195210 } ) ;
196211
197212 beforeEach ( async ( ) => {
198- await setViewport ( { width : 420 , height : 1020 } ) ;
199- // Do not set auto-open-disabled on the date-picker
200- grid . querySelector ( 'vaadin-grid-pro-edit-column' ) . autoOpen = true ;
213+ grid = createGrid ( 'date' , true ) ;
214+ await nextRender ( ) ;
201215 cell = getContainerCell ( grid . $ . items , 0 , 0 ) ;
202- await sendMouse ( { type : 'click' , position : [ 10 , 10 ] } ) ;
203216 } ) ;
204217
205218 after ( async ( ) => {
0 commit comments