11import { Selector , ClientFunction } from 'testcafe' ;
22import { createScreenshotsComparer } from 'devextreme-screenshot-comparer' ;
3+ import Button from 'devextreme-testcafe-models/button' ;
34import DataGrid from 'devextreme-testcafe-models/dataGrid' ;
45import CommandCell from 'devextreme-testcafe-models/dataGrid/commandCell' ;
56import { ClassNames } from 'devextreme-testcafe-models/dataGrid/classNames' ;
@@ -6579,13 +6580,11 @@ test('The last cell should be focused after changing the page size (T1063530)',
65796580
65806581test ( 'Focus should be set to the grid to allow keyboard navigation when the focus method is called (T1308919)' , async ( t ) => {
65816582 // arrange
6583+ const button = new Button ( '#otherContainer' ) ;
65826584 const dataGrid = new DataGrid ( '#container' ) ;
65836585 const firstDataCell = dataGrid . getDataCell ( 0 , 0 ) ;
65846586 const firstRow = dataGrid . getDataRow ( 0 ) ;
65856587 const secondRow = dataGrid . getDataRow ( 1 ) ;
6586- const focusButton = ClientFunction ( ( ) => {
6587- $ ( '#otherContainer button' ) [ 0 ] ?. focus ( ) ;
6588- } ) ;
65896588
65906589 // assert
65916590 await t . expect ( dataGrid . isReady ( ) ) . ok ( ) ;
@@ -6594,39 +6593,50 @@ test('Focus should be set to the grid to allow keyboard navigation when the focu
65946593 await dataGrid . apiFocus ( firstDataCell . element ) ;
65956594
65966595 // assert
6597- await t . expect ( firstDataCell . isFocused ) . ok ( ) ;
6598- await t . expect ( firstRow . isFocusedRow ) . ok ( ) ;
6596+ await t
6597+ . expect ( firstDataCell . isFocused ) . ok ( )
6598+ . expect ( firstRow . isFocusedRow ) . ok ( ) ;
65996599
66006600 // act
6601- await focusButton ( ) ;
6601+ await button . focus ( ) ;
66026602
66036603 // assert
6604- await t . expect ( firstDataCell . isFocused ) . notOk ( ) ;
6605- await t . expect ( firstRow . isFocusedRow ) . ok ( ) ;
6604+ await t
6605+ . expect ( button . isFocused )
6606+ . ok ( )
6607+ . expect ( firstDataCell . isFocused )
6608+ . notOk ( 'focus should be on the button' )
6609+ . expect ( firstRow . isFocusedRow )
6610+ . ok ( 'row should still have the focused-row style' ) ;
66066611
66076612 // act
66086613 await t . pressKey ( 'down' ) ;
66096614
66106615 // assert
6611- await t . expect ( secondRow . isFocusedRow ) . notOk ( ) ; // focus is still on the button
6616+ await t
6617+ . expect ( secondRow . isFocusedRow )
6618+ . notOk ( 'grid kbn should not work' ) ;
66126619
66136620 // act
6614- await dataGrid . apiFocus ( ) ;
6615- await t . pressKey ( 'down' ) ;
6621+ await t
6622+ . pressKey ( 'enter' ) // trigger button click
6623+ . pressKey ( 'down' ) ;
66166624
66176625 // assert
6618- await t . expect ( secondRow . isFocusedRow ) . ok ( ) ;
6626+ await t
6627+ . expect ( secondRow . isFocusedRow )
6628+ . ok ( 'grid is focused, so kbn should work' ) ;
66196629} ) . before ( async ( ) => {
6620- await ClientFunction ( ( ) => {
6621- $ ( '<button>' ) . appendTo ( '#otherContainer' ) ;
6622- } ) ( ) ;
66236630 await createWidget ( 'dxDataGrid' , {
66246631 dataSource : [ { id : 1 , name : 'test1' } , { id : 2 , name : 'test2' } ] ,
66256632 keyExpr : 'id' ,
66266633 focusedRowEnabled : true ,
66276634 } ) ;
6628- } ) . after ( async ( ) => {
6629- await ClientFunction ( ( ) => {
6630- $ ( '#otherContainer button' ) . remove ( ) ;
6631- } ) ( ) ;
6635+ await createWidget ( 'dxButton' , {
6636+ text : 'Focus Grid' ,
6637+ onClick ( ) {
6638+ const grid = ( $ as any ) ( '#container' ) . dxDataGrid ( 'instance' ) ;
6639+ grid . focus ( ) ;
6640+ } ,
6641+ } , '#otherContainer' ) ;
66326642} ) ;
0 commit comments