Skip to content

Commit

Permalink
[tree view] Cleanup onKeyDown
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Dec 21, 2023
1 parent d7149ef commit 0f66d83
Show file tree
Hide file tree
Showing 2 changed files with 196 additions and 144 deletions.
30 changes: 30 additions & 0 deletions packages/x-tree-view/src/TreeItem/TreeItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,36 @@ describe('<TreeItem />', () => {

expect(getByTestId('one')).not.to.have.attribute('aria-selected');
});

it('should select a node when Enter is pressed and the node is not selected', () => {
const { getByRole, getByTestId } = render(
<TreeView>
<TreeItem nodeId="one" label="one" data-testid="one" />
</TreeView>,
);

act(() => {
getByRole('tree').focus();
});
fireEvent.keyDown(getByRole('tree'), { key: 'Enter' });

expect(getByTestId('one')).to.have.attribute('aria-selected');
});

it('should not un-select a node when Enter is pressed and the node is selected', () => {
const { getByRole, getByTestId } = render(
<TreeView defaultSelected="one">
<TreeItem nodeId="one" label="one" data-testid="one" />
</TreeView>,
);

act(() => {
getByRole('tree').focus();
});
fireEvent.keyDown(getByRole('tree'), { key: 'Enter' });

expect(getByTestId('one')).to.have.attribute('aria-selected');
});
});

describe('mouse', () => {
Expand Down
Loading

0 comments on commit 0f66d83

Please sign in to comment.