Skip to content

Commit

Permalink
Add test cases for focus trap options
Browse files Browse the repository at this point in the history
  • Loading branch information
megawebmaster committed May 20, 2021
1 parent a0da7f4 commit 6578ac4
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion react-responsive-modal/__tests__/index.test.tsx
@@ -1,5 +1,5 @@
import * as React from 'react';
import { render, fireEvent, waitFor } from '@testing-library/react';
import { fireEvent, render, waitFor } from '@testing-library/react';
import { Modal } from '../src';

describe('modal', () => {
Expand Down Expand Up @@ -441,6 +441,55 @@ describe('modal', () => {
});
});

describe('prop: focusTrapOptions', () => {
describe('default settings', () => {
it('should focus first tabbable element', () => {
const { queryByTestId } = render(
<Modal open onClose={() => null}>
<a href="https://google.com" data-testid="first-item">
modal content
</a>
</Modal>
);
expect(queryByTestId('first-item')).toHaveFocus();
});
});

describe('when focusOn is firstFocusableElement', () => {
it('should focus first tabbable element', () => {
const { queryByTestId } = render(
<Modal
open
onClose={() => null}
focusTrapOptions={{ focusOn: 'firstFocusableElement' }}
>
<a href="https://google.com" data-testid="first-item">
modal content
</a>
</Modal>
);
expect(queryByTestId('first-item')).toHaveFocus();
});
});

describe('when focusOn is modalRoot', () => {
it('should focus modal root', () => {
const { queryByTestId } = render(
<Modal
open
onClose={() => null}
focusTrapOptions={{ focusOn: 'modalRoot' }}
>
<a href="https://google.com" data-testid="first-item">
modal content
</a>
</Modal>
);
expect(queryByTestId('modal')).toHaveFocus();
});
});
});

describe('prop: onEscKeyDown', () => {
it('should be called when esc key is pressed', async () => {
const onEscKeyDown = jest.fn();
Expand Down

0 comments on commit 6578ac4

Please sign in to comment.