Skip to content

Commit

Permalink
test(component): add tests to capture change
Browse files Browse the repository at this point in the history
  • Loading branch information
chanceaclark committed Jan 4, 2023
1 parent 5115650 commit e7f1e23
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/big-design/src/components/StatefulTree/spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { theme } from '@bigcommerce/big-design-theme';
import userEvent from '@testing-library/user-event';
import React from 'react';

import { fireEvent, render } from '@test/utils';
import { fireEvent, render, screen } from '@test/utils';

import { StatefulTree, StatefulTreeProps, TreeNodeProps } from '.';

Expand Down Expand Up @@ -182,3 +183,20 @@ describe('selectable = radio', () => {
}
});
});

test('should focus on TreeItem on arrow down', async () => {
render(getSimpleTree());

const node0 = await screen.findByRole('treeitem', { name: 'Test Node 0' });
const node1 = await screen.findByRole('treeitem', { name: 'Test Node 1' });

await userEvent.tab();

expect(node0).toHaveFocus();
expect(node1).not.toHaveFocus();

await userEvent.keyboard('{ArrowDown}');

expect(node0).not.toHaveFocus();
expect(node1).toHaveFocus();
});
15 changes: 15 additions & 0 deletions packages/big-design/src/components/Tree/spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,18 @@ test('expanding node triggers onExpand', async () => {

expect(onExpand).toHaveBeenCalledWith('0');
});

test('should focus when tabbed on', async () => {
renderDefaultTree({
nodes: [{ id: '0', label: 'Test Node 0' }],
focusable: { focusedNode: '0', onFocus: jest.fn() },
});

const node = await screen.findByRole('treeitem');

expect(node).not.toHaveFocus();

await userEvent.tab();

expect(node).toHaveFocus();
});

0 comments on commit e7f1e23

Please sign in to comment.