-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from ensdomains/fix/bugs-1
Misc bug fixes: 1
- Loading branch information
Showing
7 changed files
with
316 additions
and
248 deletions.
There are no files selected for viewing
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
63 changes: 63 additions & 0 deletions
63
components/src/components/molecules/Backdrop/Backdrop.test.tsx
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 * as React from 'react' | ||
|
||
import { ThemeProvider } from 'styled-components' | ||
|
||
import { cleanup, render, screen, waitFor } from '@/test' | ||
|
||
import { Backdrop } from './Backdrop' | ||
import { lightTheme } from '@/src/tokens' | ||
|
||
window.scroll = jest.fn() | ||
|
||
const Element = ({ | ||
open = true, | ||
className, | ||
testId = 1, | ||
}: { | ||
open?: boolean | ||
className?: string | ||
testId?: number | ||
}) => ( | ||
<ThemeProvider theme={lightTheme}> | ||
<Backdrop className={className} open={open}> | ||
{() => <div data-testid={`inner-data-${testId}`}>test</div>} | ||
</Backdrop> | ||
</ThemeProvider> | ||
) | ||
|
||
describe('<Backdrop />', () => { | ||
afterEach(cleanup) | ||
|
||
it('renders', async () => { | ||
render(<Element />) | ||
await waitFor(() => | ||
expect(screen.getByTestId('inner-data-1')).toBeInTheDocument(), | ||
) | ||
}) | ||
it('should allow multiple backdrops to open without losing the initial state', async () => { | ||
const { rerender: rerenderOne } = render(<Element />) | ||
await waitFor(() => | ||
expect(screen.getByTestId('inner-data-1')).toBeInTheDocument(), | ||
) | ||
expect(document.body.dataset.backdrops).toBe('1') | ||
expect(document.body.style.position).toBe('fixed') | ||
const { rerender: rerenderTwo } = render(<Element testId={2} />) | ||
await waitFor(() => | ||
expect(screen.getByTestId('inner-data-2')).toBeInTheDocument(), | ||
) | ||
expect(document.body.dataset.backdrops).toBe('2') | ||
expect(document.body.style.position).toBe('fixed') | ||
rerenderTwo(<Element open={false} testId={2} />) | ||
await waitFor(() => | ||
expect(screen.queryByTestId('inner-data-2')).not.toBeInTheDocument(), | ||
) | ||
expect(document.body.dataset.backdrops).toBe('1') | ||
expect(document.body.style.position).toBe('fixed') | ||
rerenderOne(<Element open={false} />) | ||
await waitFor(() => | ||
expect(screen.queryByTestId('inner-data-1')).not.toBeInTheDocument(), | ||
) | ||
expect(document.body.dataset.backdrops).toBe('0') | ||
expect(document.body.style.position).toBe('') | ||
}) | ||
}) |
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
Oops, something went wrong.