Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardoj committed Aug 8, 2023
1 parent b225a48 commit 2618014
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,32 @@ describe('components/Modal', () => {
expect(document.activeElement).toBe(insideElement);
});

test('focus is not trapped after closing modal', () => {
const { rerender } = render(
<>
<a data-testid={'outside'} href={'#outside'}>
Outside
</a>
<Modal visible={true} />
</>
);

const outsideElement = document.querySelector('[data-testid="outside"]');
const onDismissCallback = jest.fn(() => outsideElement.focus());

rerender(
<>
<a data-testid={'outside'} href={'#outside'}>
Outside
</a>
<Modal onDismiss={onDismissCallback} visible={false} />
</>
);

expect(onDismissCallback).toBeCalledTimes(1);
expect(document.activeElement).toBe(outsideElement);
});

test('focus is brought back to the element that triggered modal after closing', () => {
const { rerender } = render(
<>
Expand Down

0 comments on commit 2618014

Please sign in to comment.