Skip to content

Commit

Permalink
[EuiDataGrid] Add remaining unit tests for focus logic (elastic#5698)
Browse files Browse the repository at this point in the history
* Add unit tests for useHeaderFocusWorkaround

* Add unit tests for preventTabbing

+ remove unnecessary role=gridcell check - after inspecting our DOM, that role attr is set on the topmost cell wrapper but `data-datagrid-cellcontent` is set on a div below that, so there's no way the parent cell should be inside the cell content

+ swap dataset check for hasAttribute - for some reason Jest/JSDOM was failing to register dataset, but hasAttribute works and should be equivalent

* Add unit tests for createKeyDownHandler

* Add unit tests for notifyCellOfFocusState

* Add unit tests for onFocus

+ change unmount_enzyme helper to run after each file instead of each test, to allow onFocusUpdate tests to retain shared state between each it() block

* Fix failing tests caused by unmount_enzyme change

* Fix comment typo
  • Loading branch information
Constance authored Mar 14, 2022
1 parent 6fe7965 commit fddf0d2
Show file tree
Hide file tree
Showing 6 changed files with 657 additions and 48 deletions.
2 changes: 1 addition & 1 deletion scripts/jest/setup/unmount_enzyme.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jest.mock('enzyme', () => {
};
});

afterEach(() => {
afterAll(() => {
while (mockMountedComponents.length) {
const component = mockMountedComponents.pop();
if (component.length === 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ describe('EuiDataGridHeaderCellWrapper', () => {
expect(headerCell.getAttribute('tabIndex')).toEqual('-1');
};

// Reset focus between tests
beforeEach(() => (document.activeElement as HTMLElement)?.blur());

describe('isFocused context', () => {
describe('when true', () => {
it('focuses the interactive cell children when present', () => {
Expand Down
42 changes: 0 additions & 42 deletions src/components/datagrid/utils/focus.test.ts

This file was deleted.

Loading

0 comments on commit fddf0d2

Please sign in to comment.