11import { expect } from '@esm-bundle/chai' ;
2- import { enter , esc , fixtureSync , focusin , focusout , isIOS , tab } from '@vaadin/testing-helpers' ;
2+ import { enter , fixtureSync , focusin , focusout , isIOS , tab } from '@vaadin/testing-helpers' ;
33import { sendKeys } from '@web/test-runner-commands' ;
44import sinon from 'sinon' ;
55import '@vaadin/polymer-legacy-adapter/template-renderer.js' ;
@@ -8,7 +8,6 @@ import '../vaadin-grid-pro-edit-column.js';
88import {
99 createItems ,
1010 dblclick ,
11- dragAndDropOver ,
1211 flatMap ,
1312 flushGrid ,
1413 getCellEditor ,
@@ -19,307 +18,6 @@ import {
1918} from './helpers.js' ;
2019
2120describe ( 'edit column' , ( ) => {
22- ( isIOS ? describe . skip : describe ) ( 'keyboard navigation' , ( ) => {
23- let grid , input ;
24-
25- beforeEach ( ( ) => {
26- grid = fixtureSync ( `
27- <vaadin-grid-pro>
28- <vaadin-grid-pro-edit-column path="name">
29- <template class="header">Name</template>
30- <template>[[index]] [[item.name]]</template>
31- <template class="footer"></template>
32- </vaadin-grid-pro-edit-column>
33- <vaadin-grid-pro-edit-column path="age"></vaadin-grid-pro-edit-column>
34- <vaadin-grid-column path="name"></vaadin-grid-column>
35- </vaadin-grid-pro>
36- ` ) ;
37- grid . items = createItems ( ) ;
38- flushGrid ( grid ) ;
39- } ) ;
40-
41- describe ( 'when `singleCellEdit` is true' , ( ) => {
42- beforeEach ( ( ) => {
43- grid . singleCellEdit = true ;
44- } ) ;
45-
46- it ( 'should focus cell next available for editing within a same row in non-edit mode on Tab' , ( ) => {
47- const firstCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
48- dblclick ( firstCell . _content ) ;
49- input = getCellEditor ( firstCell ) ;
50-
51- const secondCell = getContainerCell ( grid . $ . items , 1 , 1 ) ;
52- const spy = sinon . spy ( secondCell , 'focus' ) ;
53- tab ( input ) ;
54- expect ( spy . calledOnce ) . to . be . true ;
55- } ) ;
56-
57- it ( 'should focus previous cell available for editing within a same row in non-edit mode on Shift Tab' , ( ) => {
58- const firstCell = getContainerCell ( grid . $ . items , 1 , 1 ) ;
59- dblclick ( firstCell . _content ) ;
60- input = getCellEditor ( firstCell ) ;
61-
62- const secondCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
63- const spy = sinon . spy ( secondCell , 'focus' ) ;
64- tab ( input , [ 'shift' ] ) ;
65- expect ( spy . calledOnce ) . to . be . true ;
66- } ) ;
67-
68- it ( 'should focus cell next available for editing on the next row in non-edit mode on Tab' , ( ) => {
69- const firstCell = getContainerCell ( grid . $ . items , 1 , 1 ) ;
70- dblclick ( firstCell . _content ) ;
71- input = getCellEditor ( firstCell ) ;
72-
73- const secondCell = getContainerCell ( grid . $ . items , 2 , 0 ) ;
74- const spy = sinon . spy ( secondCell , 'focus' ) ;
75- tab ( input ) ;
76- expect ( spy . calledOnce ) . to . be . true ;
77- } ) ;
78-
79- it ( 'should focus previous cell available for editing on the previous in non-edit mode on Shift Tab' , ( ) => {
80- const firstCell = getContainerCell ( grid . $ . items , 2 , 0 ) ;
81- dblclick ( firstCell . _content ) ;
82- input = getCellEditor ( firstCell ) ;
83-
84- const secondCell = getContainerCell ( grid . $ . items , 1 , 1 ) ;
85- const spy = sinon . spy ( secondCell , 'focus' ) ;
86- tab ( input , [ 'shift' ] ) ;
87- expect ( spy . calledOnce ) . to . be . true ;
88- } ) ;
89-
90- it ( 'should focus editable cell on the next row in non-edit mode on Enter, if `enterNextRow` is true' , ( ) => {
91- grid . enterNextRow = true ;
92- const firstCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
93- enter ( firstCell . _content ) ;
94- input = getCellEditor ( firstCell ) ;
95-
96- const secondCell = getContainerCell ( grid . $ . items , 2 , 0 ) ;
97- const spy = sinon . spy ( secondCell , 'focus' ) ;
98- enter ( input ) ;
99- expect ( spy . calledOnce ) . to . be . true ;
100- } ) ;
101-
102- it ( 'should exit the edit mode for the cell on Enter, if `enterNextRow` is false' , ( ) => {
103- const firstCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
104- dblclick ( firstCell . _content ) ;
105- input = getCellEditor ( firstCell ) ;
106-
107- enter ( input ) ;
108- expect ( getCellEditor ( firstCell ) ) . to . be . not . ok ;
109- } ) ;
110-
111- it ( 'should focus editable cell on the previous row in non-edit mode on Shift Enter, if `enterNextRow` is true' , ( ) => {
112- grid . enterNextRow = true ;
113- const firstCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
114- enter ( firstCell . _content ) ;
115- input = getCellEditor ( firstCell ) ;
116-
117- const secondCell = getContainerCell ( grid . $ . items , 0 , 0 ) ;
118- const spy = sinon . spy ( secondCell , 'focus' ) ;
119- enter ( input , [ 'shift' ] ) ;
120- expect ( spy . calledOnce ) . to . be . true ;
121- } ) ;
122-
123- it ( 'should exit the edit mode for the cell on Shift Enter, if `enterNextRow` is false' , ( ) => {
124- const firstCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
125- dblclick ( firstCell . _content ) ;
126- input = getCellEditor ( firstCell ) ;
127-
128- enter ( input , [ 'shift' ] ) ;
129- expect ( getCellEditor ( firstCell ) ) . to . be . not . ok ;
130- } ) ;
131- } ) ;
132-
133- describe ( 'when `singleCellEdit` is false' , ( ) => {
134- it ( 'should focus cell next available for editing within a same row in edit mode on Tab' , ( ) => {
135- const firstCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
136- dblclick ( firstCell . _content ) ;
137- input = getCellEditor ( firstCell ) ;
138-
139- const secondCell = getContainerCell ( grid . $ . items , 1 , 1 ) ;
140- tab ( input ) ;
141- input = getCellEditor ( secondCell ) ;
142- expect ( input ) . to . be . ok ;
143- } ) ;
144-
145- it ( 'should not focus cell next available for editing on Tab if default prevented for it' , ( ) => {
146- const firstCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
147- dblclick ( firstCell . _content ) ;
148- input = getCellEditor ( firstCell ) ;
149-
150- input . addEventListener ( 'keydown' , ( e ) => e . keyCode === 9 && e . preventDefault ( ) ) ;
151- tab ( input ) ;
152- expect ( getCellEditor ( firstCell ) ) . to . be . ok ;
153- } ) ;
154-
155- it ( 'should not focus cell next available for editing on Tab if `internal-tab` was fired right before it' , ( ) => {
156- const firstCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
157- dblclick ( firstCell . _content ) ;
158- input = getCellEditor ( firstCell ) ;
159-
160- input . dispatchEvent ( new CustomEvent ( 'internal-tab' ) ) ;
161- tab ( input ) ;
162- expect ( getCellEditor ( firstCell ) ) . to . be . ok ;
163- } ) ;
164-
165- it ( 'should be possible to switch edit cell on Tab with delay after `internal-tab` was fired' , ( done ) => {
166- const firstCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
167- dblclick ( firstCell . _content ) ;
168- input = getCellEditor ( firstCell ) ;
169-
170- input . dispatchEvent ( new CustomEvent ( 'internal-tab' ) ) ;
171- const secondCell = getContainerCell ( grid . $ . items , 1 , 1 ) ;
172- requestAnimationFrame ( ( ) => {
173- tab ( input ) ;
174- expect ( getCellEditor ( secondCell ) ) . to . be . ok ;
175- done ( ) ;
176- } ) ;
177- } ) ;
178-
179- it ( 'should focus previous cell available for editing within a same row in edit mode on Shift Tab' , ( ) => {
180- const firstCell = getContainerCell ( grid . $ . items , 1 , 1 ) ;
181- dblclick ( firstCell . _content ) ;
182- input = getCellEditor ( firstCell ) ;
183-
184- const secondCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
185- tab ( input , [ 'shift' ] ) ;
186- input = getCellEditor ( secondCell ) ;
187- expect ( input ) . to . be . ok ;
188- } ) ;
189-
190- it ( 'should focus cell next available for editing on the next row in edit mode on Tab' , ( ) => {
191- const firstCell = getContainerCell ( grid . $ . items , 1 , 1 ) ;
192- dblclick ( firstCell . _content ) ;
193- input = getCellEditor ( firstCell ) ;
194-
195- const secondCell = getContainerCell ( grid . $ . items , 2 , 0 ) ;
196- tab ( input ) ;
197- input = getCellEditor ( secondCell ) ;
198- expect ( input ) . to . be . ok ;
199- } ) ;
200-
201- it ( 'should focus previous cell available for editing on the previous row in edit mode on Shift Tab' , ( ) => {
202- const firstCell = getContainerCell ( grid . $ . items , 2 , 0 ) ;
203- dblclick ( firstCell . _content ) ;
204- input = getCellEditor ( firstCell ) ;
205-
206- const secondCell = getContainerCell ( grid . $ . items , 1 , 1 ) ;
207- tab ( input , [ 'shift' ] ) ;
208- input = getCellEditor ( secondCell ) ;
209- expect ( input ) . to . be . ok ;
210- } ) ;
211-
212- it ( 'should focus editable cell on the next row in edit mode on Enter, if `enterNextRow` is true' , ( ) => {
213- grid . enterNextRow = true ;
214- const firstCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
215- enter ( firstCell . _content ) ;
216- input = getCellEditor ( firstCell ) ;
217-
218- const secondCell = getContainerCell ( grid . $ . items , 2 , 0 ) ;
219- enter ( input ) ;
220- input = getCellEditor ( secondCell ) ;
221- expect ( input ) . to . be . ok ;
222- } ) ;
223-
224- it ( 'should exit the edit mode for the cell on Enter, if `enterNextRow` is false' , ( ) => {
225- const firstCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
226- dblclick ( firstCell . _content ) ;
227- input = getCellEditor ( firstCell ) ;
228-
229- enter ( input ) ;
230- expect ( getCellEditor ( firstCell ) ) . to . be . not . ok ;
231- } ) ;
232-
233- it ( 'should focus editable cell on the previous row in non-edit mode on Shift Enter, if `enterNextRow` is true' , ( ) => {
234- grid . enterNextRow = true ;
235- const firstCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
236- enter ( firstCell . _content ) ;
237- input = getCellEditor ( firstCell ) ;
238-
239- const secondCell = getContainerCell ( grid . $ . items , 0 , 0 ) ;
240- enter ( input , [ 'shift' ] ) ;
241- input = getCellEditor ( secondCell ) ;
242- expect ( input ) . to . be . ok ;
243- } ) ;
244-
245- it ( 'should not re-focus previous cell in edit mode on Enter, if `enterNextRow` is true' , ( ) => {
246- grid . enterNextRow = true ;
247- const firstCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
248- enter ( firstCell . _content ) ;
249- input = getCellEditor ( firstCell ) . inputElement ;
250-
251- const spy = sinon . spy ( firstCell , 'focus' ) ;
252- enter ( input ) ;
253- expect ( spy . called ) . to . be . false ;
254- } ) ;
255-
256- it ( 'should exit the edit mode for the cell on Shift Enter, if `enterNextRow` is false' , ( ) => {
257- const firstCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
258- dblclick ( firstCell . _content ) ;
259- input = getCellEditor ( firstCell ) ;
260-
261- enter ( input , [ 'shift' ] ) ;
262- expect ( getCellEditor ( firstCell ) ) . to . be . not . ok ;
263- } ) ;
264- } ) ;
265-
266- it ( 'should exit the edit mode for the cell when pressing ESC' , ( ) => {
267- const firstCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
268- dblclick ( firstCell . _content ) ;
269- input = getCellEditor ( firstCell ) ;
270-
271- esc ( input ) ;
272- expect ( getCellEditor ( firstCell ) ) . to . be . not . ok ;
273- } ) ;
274-
275- it ( 'should re-focus cell after exit edit mode on ESC' , ( ) => {
276- const firstCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
277- firstCell . focus ( ) ;
278- enter ( firstCell . _content ) ;
279- input = getCellEditor ( firstCell ) ;
280-
281- const focusSpy = sinon . spy ( firstCell , 'focus' ) ;
282- const stopSpy = sinon . spy ( grid , '_stopEdit' ) ;
283- esc ( input ) ;
284-
285- expect ( focusSpy . calledAfter ( stopSpy ) ) . to . be . true ;
286- } ) ;
287-
288- it ( 'should focus correct editable cell after column reordering' , ( ) => {
289- grid . singleCellEdit = true ;
290- grid . columnReorderingAllowed = true ;
291- const headerContent = [
292- getContainerCell ( grid . $ . header , 0 , 0 ) . _content ,
293- getContainerCell ( grid . $ . header , 0 , 1 ) . _content ,
294- ] ;
295- dragAndDropOver ( headerContent [ 0 ] , headerContent [ 1 ] ) ;
296-
297- const firstCell = getContainerCell ( grid . $ . items , 1 , 1 ) ;
298- dblclick ( firstCell . _content ) ;
299- input = getCellEditor ( firstCell ) ;
300-
301- const secondCell = getContainerCell ( grid . $ . items , 1 , 0 ) ;
302- const spy = sinon . spy ( secondCell , 'focus' ) ;
303- tab ( input ) ;
304- expect ( spy . calledOnce ) . to . be . true ;
305- } ) ;
306-
307- it ( 'should focus correct editable cell when column is hidden' , ( ) => {
308- grid . singleCellEdit = true ;
309- const column = grid . querySelector ( 'vaadin-grid-pro-edit-column' ) ;
310- column . hidden = true ;
311-
312- const firstCell = getContainerCell ( grid . $ . items , 1 , 1 ) ;
313- dblclick ( firstCell . _content ) ;
314- input = getCellEditor ( firstCell ) ;
315-
316- const secondCell = getContainerCell ( grid . $ . items , 2 , 1 ) ;
317- const spy = sinon . spy ( secondCell , 'focus' ) ;
318- tab ( input ) ;
319- expect ( spy . calledOnce ) . to . be . true ;
320- } ) ;
321- } ) ;
322-
32321 ( isIOS ? describe . skip : describe ) ( 'select column' , ( ) => {
32422 let grid , textCell , selectCell , checkboxCell ;
32523
0 commit comments