Skip to content

Commit

Permalink
correct test name
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyhallett committed Mar 18, 2020
1 parent d2eb0d2 commit ff1ef9e
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions packages/material-ui-lab/src/TreeItem/TreeItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,33 @@ describe('<TreeItem />', () => {
expect(getByTestId('two')).to.have.focus;
});

it('moves focus to a sibling node after conditional rendering', () => {
it('moves focus to a child node', () => {
const { getByTestId } = render(
<TreeView defaultExpanded={['one']}>
<TreeItem nodeId="one" label="one" data-testid="one">
<TreeItem nodeId="two" label="two" data-testid="two" />
</TreeItem>
</TreeView>,
);

expect(getByTestId('one')).to.have.attribute('aria-expanded', 'true');
getByTestId('one').focus();
fireEvent.keyDown(document.activeElement, { key: 'ArrowDown' });
expect(getByTestId('two')).to.have.focus;
});

it('moves focus to a child node works with a dynamic tree', () => {
function TestComponent() {
const [hide, setState] = React.useState(false);

return (
<React.Fragment>
<button type="button" onClick={() => setState(value => !value)}>
Hide
<button
data-testid="button"
type="button"
onClick={() => setState(value => !value)}
>
Toggle Hide
</button>
<TreeView defaultExpanded={['one']}>
{!hide && (
Expand All @@ -457,31 +476,17 @@ describe('<TreeItem />', () => {
);
}

const { getByText, queryByText, getByTestId } = render(<TestComponent />);
const { queryByTestId, getByTestId } = render(<TestComponent />);

expect(getByText('one')).to.not.be.null;
fireEvent.click(getByText('Hide'));
expect(queryByText('one')).to.be.null;
fireEvent.click(getByText('Hide'));
expect(getByText('one')).to.not.be.null;
getByTestId('one').focus();
fireEvent.keyDown(document.activeElement, { key: 'ArrowDown' });

expect(getByTestId('two')).to.have.focus;
});
expect(getByTestId('one')).to.not.be.null;
fireEvent.click(getByTestId('button'));
expect(queryByTestId('one')).to.be.null;
fireEvent.click(getByTestId('button'));
expect(getByTestId('one')).to.not.be.null;

it('moves focus to a child node', () => {
const { getByTestId } = render(
<TreeView defaultExpanded={['one']}>
<TreeItem nodeId="one" label="one" data-testid="one">
<TreeItem nodeId="two" label="two" data-testid="two" />
</TreeItem>
</TreeView>,
);

expect(getByTestId('one')).to.have.attribute('aria-expanded', 'true');
getByTestId('one').focus();
fireEvent.keyDown(document.activeElement, { key: 'ArrowDown' });

expect(getByTestId('two')).to.have.focus;
});

Expand Down

0 comments on commit ff1ef9e

Please sign in to comment.