-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PC-34260)[PRO] feat: Add title and footer props to Dialog and preven…
…t closing when clicking on an eleemnt on top of the content.
- Loading branch information
1 parent
374b04a
commit 0f2f53d
Showing
4 changed files
with
221 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import * as Dialog from '@radix-ui/react-dialog' | ||
import { render, screen } from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
|
||
import { Button } from 'ui-kit/Button/Button' | ||
import { ButtonVariant } from 'ui-kit/Button/types' | ||
|
||
import { DialogBuilder, DialogBuilderProps } from './DialogBuilder' | ||
|
||
const defaultProps: DialogBuilderProps = { | ||
children: <p>Dialog content</p>, | ||
title: 'Dialog title', | ||
trigger: <Button>Open the dialog</Button>, | ||
footer: ( | ||
<div> | ||
<Dialog.Close asChild> | ||
<Button variant={ButtonVariant.SECONDARY}>Annuler</Button> | ||
</Dialog.Close> | ||
<Dialog.Close asChild> | ||
<Button>Continuer</Button> | ||
</Dialog.Close> | ||
</div> | ||
), | ||
} | ||
|
||
function renderDialogBuilder(props = defaultProps) { | ||
return render(<DialogBuilder {...props}>{props.children}</DialogBuilder>) | ||
} | ||
|
||
describe('DialogBuilder', () => { | ||
it('should open a dialog with a title and a footer', async () => { | ||
renderDialogBuilder() | ||
|
||
await userEvent.click( | ||
screen.getByRole('button', { name: 'Open the dialog' }) | ||
) | ||
expect( | ||
screen.getByRole('heading', { name: 'Dialog title' }) | ||
).toBeInTheDocument() | ||
expect( | ||
screen.getByRole('button', { name: 'Continuer' }) | ||
).toBeInTheDocument() | ||
expect(screen.getByRole('button', { name: 'Annuler' })).toBeInTheDocument() | ||
expect( | ||
screen.getByRole('button', { name: 'Fermer la modale' }) | ||
).toBeInTheDocument() | ||
}) | ||
|
||
it('should close the dialog when clicking the close button', async () => { | ||
renderDialogBuilder() | ||
|
||
await userEvent.click( | ||
screen.getByRole('button', { name: 'Open the dialog' }) | ||
) | ||
|
||
await userEvent.click( | ||
screen.getByRole('button', { name: 'Fermer la modale' }) | ||
) | ||
expect( | ||
screen.queryByRole('heading', { name: 'Dialog title' }) | ||
).not.toBeInTheDocument() | ||
}) | ||
|
||
it('should close the dialog when clicking outside the dialog', async () => { | ||
renderDialogBuilder() | ||
|
||
await userEvent.click( | ||
screen.getByRole('button', { name: 'Open the dialog' }) | ||
) | ||
|
||
await userEvent.click(screen.getByTestId('dialog-overlay')) | ||
expect( | ||
screen.queryByRole('heading', { name: 'Dialog title' }) | ||
).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