Skip to content

Commit

Permalink
Test all root children disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesplease committed Jun 16, 2021
1 parent 05e187e commit 6c58a73
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/tests/mounting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,41 @@ describe('Mounting', () => {
});

describe('two nodes', () => {
it('handles all children being disabled', () => {
let focusStore;

function TestComponent() {
focusStore = useFocusStoreDangerously();

return (
<>
<FocusNode focusId="nodeA" data-testid="nodeA" disabled />
<FocusNode focusId="nodeB" data-testid="nodeB" disabled />
</>
);
}

render(
<FocusRoot>
<TestComponent />
</FocusRoot>
);

const nodeAEl = screen.getByTestId('nodeA');
expect(nodeAEl).not.toHaveClass('isFocused');
expect(nodeAEl).not.toHaveClass('isFocusedLeaf');

const nodeBEl = screen.getByTestId('nodeB');
expect(nodeBEl).not.toHaveClass('isFocused');
expect(nodeBEl).not.toHaveClass('isFocusedLeaf');

const focusState = focusStore.getState();
expect(focusState.focusedNodeId).toEqual('root');
expect(focusState.focusHierarchy).toEqual(['root']);
expect(focusState.activeNodeId).toEqual(null);
expect(Object.values(focusState.nodes)).toHaveLength(3);
});

it('automatically assigns focus to the first node', () => {
let focusStore;

Expand Down

0 comments on commit 6c58a73

Please sign in to comment.