|
1 | 1 | import { Selector, ClientFunction } from 'testcafe'; |
2 | 2 | import { createScreenshotsComparer } from 'devextreme-screenshot-comparer'; |
| 3 | +import Button from 'devextreme-testcafe-models/button'; |
3 | 4 | import DataGrid from 'devextreme-testcafe-models/dataGrid'; |
4 | 5 | import CommandCell from 'devextreme-testcafe-models/dataGrid/commandCell'; |
5 | 6 | import { ClassNames } from 'devextreme-testcafe-models/dataGrid/classNames'; |
@@ -6576,3 +6577,66 @@ test('The last cell should be focused after changing the page size (T1063530)', |
6576 | 6577 | })(); |
6577 | 6578 | }); |
6578 | 6579 | }); |
| 6580 | + |
| 6581 | +test('Focus should be set to the grid to allow keyboard navigation when the focus method is called (T1308919)', async (t) => { |
| 6582 | + // arrange |
| 6583 | + const button = new Button('#otherContainer'); |
| 6584 | + const dataGrid = new DataGrid('#container'); |
| 6585 | + const firstDataCell = dataGrid.getDataCell(0, 0); |
| 6586 | + const firstRow = dataGrid.getDataRow(0); |
| 6587 | + const secondRow = dataGrid.getDataRow(1); |
| 6588 | + |
| 6589 | + // assert |
| 6590 | + await t.expect(dataGrid.isReady()).ok(); |
| 6591 | + |
| 6592 | + // act |
| 6593 | + await dataGrid.apiFocus(firstDataCell.element); |
| 6594 | + |
| 6595 | + // assert |
| 6596 | + await t |
| 6597 | + .expect(firstDataCell.isFocused).ok() |
| 6598 | + .expect(firstRow.isFocusedRow).ok(); |
| 6599 | + |
| 6600 | + // act |
| 6601 | + await button.focus(); |
| 6602 | + |
| 6603 | + // assert |
| 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'); |
| 6611 | + |
| 6612 | + // act |
| 6613 | + await t.pressKey('down'); |
| 6614 | + |
| 6615 | + // assert |
| 6616 | + await t |
| 6617 | + .expect(secondRow.isFocusedRow) |
| 6618 | + .notOk('grid kbn should not work'); |
| 6619 | + |
| 6620 | + // act |
| 6621 | + await t |
| 6622 | + .pressKey('enter') // trigger button click |
| 6623 | + .pressKey('down'); |
| 6624 | + |
| 6625 | + // assert |
| 6626 | + await t |
| 6627 | + .expect(secondRow.isFocusedRow) |
| 6628 | + .ok('grid is focused, so kbn should work'); |
| 6629 | +}).before(async () => { |
| 6630 | + await createWidget('dxDataGrid', { |
| 6631 | + dataSource: [{ id: 1, name: 'test1' }, { id: 2, name: 'test2' }], |
| 6632 | + keyExpr: 'id', |
| 6633 | + focusedRowEnabled: true, |
| 6634 | + }); |
| 6635 | + await createWidget('dxButton', { |
| 6636 | + text: 'Focus Grid', |
| 6637 | + onClick() { |
| 6638 | + const grid = ($ as any)('#container').dxDataGrid('instance'); |
| 6639 | + grid.focus(); |
| 6640 | + }, |
| 6641 | + }, '#otherContainer'); |
| 6642 | +}); |
0 commit comments