forked from blakeblackshear/frigate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7e5b99
commit f878138
Showing
4 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { h, createRef } from 'preact'; | ||
import RelativeModal from '../RelativeModal'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { fireEvent, render, screen } from '@testing-library/preact'; | ||
|
||
describe('RelativeModal', () => { | ||
test('keeps tab focus', async () => { | ||
const ref = createRef(); | ||
render( | ||
<div> | ||
<label for="outside-input">outside</label> | ||
<input id="outside-input" tabindex="0" /> | ||
<div ref={ref} /> | ||
<RelativeModal relativeTo={ref}> | ||
<input data-testid="modal-input-0" tabindex="0" /> | ||
<input data-testid="modal-input-1" tabindex="0" /> | ||
</RelativeModal> | ||
</div> | ||
); | ||
|
||
const inputs = screen.queryAllByTestId(/modal-input/); | ||
expect(document.activeElement).toBe(inputs[0]); | ||
userEvent.tab(); | ||
expect(document.activeElement).toBe(inputs[1]); | ||
userEvent.tab(); | ||
expect(document.activeElement).toBe(inputs[0]); | ||
}); | ||
|
||
test('pressing ESC dismisses', async () => { | ||
const handleDismiss = jest.fn(); | ||
const ref = createRef(); | ||
render( | ||
<div> | ||
<div ref={ref} /> | ||
<RelativeModal onDismiss={handleDismiss} relativeTo={ref}> | ||
<input data-testid="modal-input-0" tabindex="0" /> | ||
</RelativeModal> | ||
</div> | ||
); | ||
|
||
const dialog = screen.queryByRole('dialog'); | ||
expect(dialog).toBeInTheDocument(); | ||
|
||
fireEvent.keyDown(document.activeElement, { key: 'Escape', code: 'Escape' }); | ||
expect(handleDismiss).toHaveBeenCalled(); | ||
}); | ||
|
||
test('clicking a scrim dismisses', async () => { | ||
const handleDismiss = jest.fn(); | ||
const ref = createRef(); | ||
render( | ||
<div> | ||
<div ref={ref} /> | ||
<RelativeModal onDismiss={handleDismiss} relativeTo={ref}> | ||
<input data-testid="modal-input-0" tabindex="0" /> | ||
</RelativeModal> | ||
</div> | ||
); | ||
|
||
fireEvent.click(screen.queryByTestId('scrim')); | ||
expect(handleDismiss).toHaveBeenCalled(); | ||
}); | ||
}); |