-
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
Showing
7 changed files
with
220 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
|
||
import { render, screen } from '@testing-library/react'; | ||
|
||
import ConfirmDialog, { confirmDialogDataTestIds } from '.'; | ||
import { dialogDataTestIds } from '..'; | ||
|
||
describe('ConfirmDialog', () => { | ||
describe('given the confirm dialog is opened', () => { | ||
it('renders a confirm dialog', () => { | ||
render( | ||
<ConfirmDialog open title="Title"> | ||
Test Content | ||
</ConfirmDialog> | ||
); | ||
|
||
const confirmDialog = screen.getByTestId(confirmDialogDataTestIds.base); | ||
|
||
expect(confirmDialog).toBeVisible(); | ||
}); | ||
}); | ||
|
||
describe('given the dialog is NOT opened', () => { | ||
it('does NOT render a dialog', () => { | ||
render( | ||
<ConfirmDialog open={false} title="Title"> | ||
Test Content | ||
</ConfirmDialog> | ||
); | ||
|
||
expect(screen.queryByTestId(dialogDataTestIds.dialog)).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
|
||
import ElevatedButton from 'components/ElevatedButton'; | ||
|
||
import Dialog from '..'; | ||
|
||
export const confirmDialogDataTestIds = { | ||
base: 'confirm-dialog__base', | ||
positiveButton: 'confirm-dialog__positive-button', | ||
negativeButton: 'confirm-diloa__negative-button', | ||
}; | ||
|
||
interface ConfirmDialogProps { | ||
title: string; | ||
children: React.ReactNode; | ||
open: boolean; | ||
onClose?: () => void; | ||
onConfirm?: () => void; | ||
} | ||
const ConfirmDialog = ({ open, onClose, title, children, onConfirm }: ConfirmDialogProps): JSX.Element => { | ||
if (!open) { | ||
return <></>; | ||
} | ||
|
||
return ( | ||
<div data-test-id={confirmDialogDataTestIds.base}> | ||
<Dialog open={open}> | ||
<h2 className="text-x-regular text-white font-extrabold">{title}</h2> | ||
<div className="py-5 text-regular text-white opacity-70">{children}</div> | ||
<div className="flex justify-end"> | ||
<div className="p-1"> | ||
<ElevatedButton | ||
isFullWidth={false} | ||
className="bg-white bg-opacity-[.18] text-white" | ||
onClick={() => { | ||
onClose?.(); | ||
onConfirm?.(); | ||
}} | ||
data-test-id={confirmDialogDataTestIds.positiveButton} | ||
> | ||
Yes | ||
</ElevatedButton> | ||
</div> | ||
<div className="p-1"> | ||
<ElevatedButton | ||
isFullWidth={false} | ||
className="bg-white text-black-chinese px-5" | ||
onClick={() => onClose?.()} | ||
data-test-id={confirmDialogDataTestIds.negativeButton} | ||
> | ||
Cancel | ||
</ElevatedButton> | ||
</div> | ||
</div> | ||
</Dialog> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ConfirmDialog; |
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,25 @@ | ||
import React from 'react'; | ||
|
||
import { render, screen } from '@testing-library/react'; | ||
|
||
import Dialog, { dialogDataTestIds } from '.'; | ||
|
||
describe('Dialog', () => { | ||
describe('given the dialog is opened', () => { | ||
it('renders a dialog', () => { | ||
render(<Dialog open>Test Content</Dialog>); | ||
|
||
const dialog = screen.getByTestId(dialogDataTestIds.dialog); | ||
|
||
expect(dialog).toBeVisible(); | ||
}); | ||
}); | ||
|
||
describe('given the dialog is NOT opened', () => { | ||
it('does NOT render a dialog', () => { | ||
render(<Dialog open={false}>Test Content</Dialog>); | ||
|
||
expect(screen.queryByTestId(dialogDataTestIds.dialog)).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react'; | ||
|
||
export const dialogDataTestIds = { | ||
dialog: 'dialog__base', | ||
}; | ||
interface DialogProps { | ||
children: React.ReactNode; | ||
open: boolean; | ||
} | ||
const Dialog = (props: DialogProps): JSX.Element => { | ||
const { open } = props; | ||
if (!open) { | ||
return <></>; | ||
} | ||
return ( | ||
<div className="fixed inset-0 z-50 overflow-auto bg-black bg-opacity-50 flex" data-test-id={dialogDataTestIds.dialog}> | ||
<div className="relative p-6 bg-[#1E1E1E] w-full max-w-md m-auto flex-col flex rounded-[14px]"> | ||
<div>{props.children}</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Dialog; |
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