11import { createScreenshotsComparer } from 'devextreme-screenshot-comparer' ;
22import DataGrid from 'devextreme-testcafe-models/dataGrid' ;
3+ import { ClientFunction } from 'testcafe' ;
34import { createWidget } from '../../../../helpers/createWidget' ;
45import url from '../../../../helpers/getPageUrl' ;
56import { getData } from '../../helpers/generateDataSourceData' ;
@@ -8,6 +9,47 @@ import { testScreenshot } from '../../../../helpers/themeUtils';
89fixture `Keyboard Navigation.Visual`
910 . page ( url ( __dirname , '../../../container.html' ) ) ;
1011
12+ const KEYBOARD_NAVIGATION_TIMEOUT = 3000 ;
13+
14+ const isKeyboardNavigationInProgress = ClientFunction ( ( ) => {
15+ const dataGrid = ( $ ( '#container' ) as any ) . dxDataGrid ( 'instance' ) ;
16+
17+ return dataGrid
18+ . getController ( 'keyboardNavigation' )
19+ . navigationToCellInProgress ( ) ;
20+ } ) ;
21+
22+ const focusDataCell = async (
23+ t : TestController ,
24+ dataGrid : DataGrid ,
25+ rowIndex : number ,
26+ columnIndex : number ,
27+ ) : Promise < void > => {
28+ const cell = dataGrid . getDataCell ( rowIndex , columnIndex ) ;
29+
30+ await dataGrid . apiFocus ( cell . element ) ;
31+ await t
32+ . expect ( cell . element . focused )
33+ . ok ( { timeout : KEYBOARD_NAVIGATION_TIMEOUT } ) ;
34+ } ;
35+
36+ const expectDataCellFocusState = async (
37+ t : TestController ,
38+ dataGrid : DataGrid ,
39+ rowIndex : number ,
40+ columnIndex : number ,
41+ ) : Promise < void > => {
42+ await t
43+ . expect ( dataGrid . getDataCell ( rowIndex , columnIndex ) . isFocused )
44+ . ok ( { timeout : KEYBOARD_NAVIGATION_TIMEOUT } ) ;
45+ } ;
46+
47+ const waitForKeyboardNavigation = async ( t : TestController ) : Promise < void > => {
48+ await t
49+ . expect ( isKeyboardNavigationInProgress ( ) )
50+ . notOk ( { timeout : KEYBOARD_NAVIGATION_TIMEOUT } ) ;
51+ } ;
52+
1153// Quick navigation through grid cells via Home and End keys
1254test ( 'Focus the last cell in the row that contains focus when pressing the End key' , async ( t ) => {
1355 // arrange
@@ -522,12 +564,11 @@ test('Navigate to last cell in the last row when virtual scrolling is enabled',
522564 . ok ( ) ;
523565
524566 // act
525- await t
526- . click ( dataGrid . getDataCell ( 0 , 0 ) . element )
527- . pressKey ( 'ctrl+end' )
528- . wait ( 100 ) ;
567+ await focusDataCell ( t , dataGrid , 0 , 0 ) ;
568+ await t . pressKey ( 'ctrl+end' ) ;
569+ await waitForKeyboardNavigation ( t ) ;
529570
530- await t . expect ( dataGrid . getDataCell ( 199 , 14 ) . element . focused ) . ok ( ) ;
571+ await expectDataCellFocusState ( t , dataGrid , 199 , 14 ) ;
531572 await testScreenshot ( t , takeScreenshot , 'navigate_to_last_cell_in_last_row_when_virtual_scrolling_is_enabled.png' , { element : dataGrid . element } ) ;
532573
533574 // assert
@@ -566,12 +607,11 @@ test('Navigate to first cell in the first row when virtual scrolling is enabled'
566607 await testScreenshot ( t , takeScreenshot , 'navigate_to_first_cell_in_first_row_when_virtual_scrolling_is_enabled_1.png' , { element : dataGrid . element } ) ;
567608
568609 // act
569- await t
570- . click ( dataGrid . getDataCell ( 199 , 14 ) . element )
571- . pressKey ( 'ctrl+home' )
572- . wait ( 1000 ) ;
610+ await focusDataCell ( t , dataGrid , 199 , 14 ) ;
611+ await t . pressKey ( 'ctrl+home' ) ;
612+ await waitForKeyboardNavigation ( t ) ;
573613
574- await t . expect ( dataGrid . getDataCell ( 0 , 0 ) . element . focused ) . ok ( ) ;
614+ await expectDataCellFocusState ( t , dataGrid , 0 , 0 ) ;
575615 await testScreenshot ( t , takeScreenshot , 'navigate_to_first_cell_in_first_row_when_virtual_scrolling_is_enabled_2.png' , { element : dataGrid . element } ) ;
576616
577617 // assert
@@ -600,15 +640,12 @@ test('Navigate to last cell in the last row when virtual scrolling and columns a
600640 . ok ( ) ;
601641
602642 // act
603- await t
604- . click ( dataGrid . getDataCell ( 0 , 0 ) . element )
605- . pressKey ( 'ctrl+end' )
606- . wait ( 1000 ) ;
643+ await focusDataCell ( t , dataGrid , 0 , 0 ) ;
644+ await t . pressKey ( 'ctrl+end' ) ;
645+ await waitForKeyboardNavigation ( t ) ;
607646
608647 // assert
609- await t
610- . expect ( dataGrid . getDataCell ( 199 , 34 ) . element . focused )
611- . ok ( ) ;
648+ await expectDataCellFocusState ( t , dataGrid , 199 , 34 ) ;
612649
613650 await testScreenshot ( t , takeScreenshot , 'navigate_to_last_cell_in_last_row_when_virtual_scrolling_and_columns_are_enabled.png' , { element : dataGrid . element } ) ;
614651
@@ -645,15 +682,12 @@ test('Navigate to first cell in the first row when virtual scrolling and columns
645682 await testScreenshot ( t , takeScreenshot , 'navigate_to_first_cell_in_first_row_when_virtual_scrolling_and_columns_are_enabled_1.png' , { element : dataGrid . element } ) ;
646683
647684 // act
648- await t
649- . click ( dataGrid . getDataCell ( 199 , 34 ) . element )
650- . pressKey ( 'ctrl+home' )
651- . wait ( 300 ) ;
685+ await focusDataCell ( t , dataGrid , 199 , 34 ) ;
686+ await t . pressKey ( 'ctrl+home' ) ;
687+ await waitForKeyboardNavigation ( t ) ;
652688
653689 // assert
654- await t
655- . expect ( dataGrid . getDataCell ( 0 , 0 ) . element . focused )
656- . ok ( ) ;
690+ await expectDataCellFocusState ( t , dataGrid , 0 , 0 ) ;
657691
658692 await testScreenshot ( t , takeScreenshot , 'navigate_to_first_cell_in_first_row_when_virtual_scrolling_and_columns_are_enabled_2.png' , { element : dataGrid . element } ) ;
659693
@@ -682,28 +716,25 @@ test('Navigate to first cell in the first row when virtual scrolling and columns
682716 . ok ( ) ;
683717
684718 // act
685- await t
686- . click ( dataGrid . getDataCell ( 0 , 1 ) . element )
687- . pressKey ( 'ctrl+end' )
688- . wait ( 1000 ) ;
719+ await focusDataCell ( t , dataGrid , 0 , 1 ) ;
720+ await t . pressKey ( 'ctrl+end' ) ;
721+ await waitForKeyboardNavigation ( t ) ;
689722
690723 // assert
691- await t
692- . expect ( dataGrid . getDataCell ( 199 , 35 ) . isFocused )
693- . ok ( ) ;
724+ await expectDataCellFocusState ( t , dataGrid , 199 , 35 ) ;
694725
695726 // act
696- await t
697- . click ( dataGrid . getDataCell ( 199 , 35 ) . element )
698- . pressKey ( 'ctrl+home' )
699- . wait ( 1000 ) ;
727+ await focusDataCell ( t , dataGrid , 199 , 35 ) ;
728+ await t . pressKey ( 'ctrl+home' ) ;
729+ await waitForKeyboardNavigation ( t ) ;
730+
731+ // assert
732+ await expectDataCellFocusState ( t , dataGrid , 0 , 1 ) ;
700733
701734 await testScreenshot ( t , takeScreenshot , `${ useNative ? 'native' : 'simulated' } _scrolling_-_navigate_to_first_cell_row_dragging__virtual_scrolling__virtual_columns.png` , { element : dataGrid . element } ) ;
702735
703736 // assert
704737 await t
705- . expect ( dataGrid . getDataCell ( 0 , 1 ) . isFocused )
706- . ok ( )
707738 . expect ( compareResults . isValid ( ) )
708739 . ok ( compareResults . errorMessages ( ) ) ;
709740 } ) . before ( async ( ) => createWidget ( 'dxDataGrid' , {
@@ -731,12 +762,11 @@ test('Navigate to first cell in the first row when virtual scrolling and columns
731762 . ok ( ) ;
732763
733764 // act
734- await t
735- . click ( dataGrid . getDataCell ( 0 , 0 ) . element )
736- . pressKey ( 'ctrl+end' )
737- . wait ( 1000 ) ;
765+ await focusDataCell ( t , dataGrid , 0 , 1 ) ;
766+ await t . pressKey ( 'ctrl+end' ) ;
767+ await waitForKeyboardNavigation ( t ) ;
738768
739- await t . expect ( dataGrid . getDataCell ( 199 , 35 ) . isFocused ) . ok ( ) ;
769+ await expectDataCellFocusState ( t , dataGrid , 199 , 34 ) ;
740770 await testScreenshot ( t , takeScreenshot , `${ useNative ? 'native' : 'simulated' } _scrolling_-_navigate_to_last_cell_row_dragging__virtual_scrolling__virtual_columns.png` , { element : dataGrid . element } ) ;
741771
742772 // assert
0 commit comments