-
Notifications
You must be signed in to change notification settings - Fork 5
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 #86 from Gkuzin13/dev
Dev
- Loading branch information
Showing
9 changed files
with
137 additions
and
88 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
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
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 |
---|---|---|
@@ -1,21 +1,58 @@ | ||
import { act, renderHook, screen } from '@testing-library/react'; | ||
import { act, renderHook, screen, within } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { ModalProvider, useModal } from '../modal'; | ||
|
||
describe('modal context', () => { | ||
it('opens dialog with provided content', async () => { | ||
it('opens with provided content', async () => { | ||
const { result } = renderHook(() => useModal(), { wrapper: ModalProvider }); | ||
|
||
await act(async () => { | ||
result.current.open({ title: 'title', description: 'description' }); | ||
result.current.openModal({ | ||
title: 'test title', | ||
description: 'test description', | ||
}); | ||
}); | ||
|
||
expect(result.current.opened).toBe(true); | ||
expect(result.current.content).toEqual({ | ||
title: 'title', | ||
description: 'description', | ||
const content = screen.getByTestId(/dialog-content/); | ||
|
||
expect(content).toBeInTheDocument(); | ||
expect(within(content).getByText(/test title/)).toBeInTheDocument(); | ||
expect(within(content).getByText(/test description/)).toBeInTheDocument(); | ||
}); | ||
|
||
it('closes by clicking close button', async () => { | ||
const { result } = renderHook(() => useModal(), { wrapper: ModalProvider }); | ||
|
||
await act(async () => { | ||
result.current.openModal({ | ||
title: 'test title', | ||
description: 'test description', | ||
}); | ||
}); | ||
|
||
expect(screen.getByTestId(/dialog-content/)).toBeInTheDocument(); | ||
|
||
await userEvent.click(screen.getByTestId(/close-dialog-button/)); | ||
|
||
expect(screen.queryByTestId(/dialog-content/)).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('closes from closeModal', async () => { | ||
const { result } = renderHook(() => useModal(), { wrapper: ModalProvider }); | ||
|
||
await act(async () => { | ||
result.current.openModal({ | ||
title: 'test title', | ||
description: 'test description', | ||
}); | ||
}); | ||
|
||
expect(screen.getByTestId(/dialog-content/)).toBeInTheDocument(); | ||
|
||
await act(async () => { | ||
result.current.closeModal(); | ||
}); | ||
|
||
expect(screen.getByText('title')).toBeInTheDocument(); | ||
expect(screen.getByText('description')).toBeInTheDocument(); | ||
expect(screen.queryByTestId(/dialog-content/)).not.toBeInTheDocument(); | ||
}); | ||
}); |
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