aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/molecules/modals/modal/modal.test.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-10-31 16:00:45 +0100
committerArmand Philippot <git@armandphilippot.com>2023-11-11 18:15:27 +0100
commit3ff4c37a7a2c40340c17f9e6c1754444bce0f839 (patch)
tree551ca3df148d46af2bd27995fa98c01378030644 /src/components/molecules/modals/modal/modal.test.tsx
parent0e52a59917406ad03c174e030c6c1c92ab23449d (diff)
refactor(components): rewrite Modal component
* add an optional close button * add an icon prop
Diffstat (limited to 'src/components/molecules/modals/modal/modal.test.tsx')
-rw-r--r--src/components/molecules/modals/modal/modal.test.tsx48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/components/molecules/modals/modal/modal.test.tsx b/src/components/molecules/modals/modal/modal.test.tsx
new file mode 100644
index 0000000..82b7487
--- /dev/null
+++ b/src/components/molecules/modals/modal/modal.test.tsx
@@ -0,0 +1,48 @@
+import { describe, expect, it } from '@jest/globals';
+import { render, screen as rtlScreen } from '@testing-library/react';
+import { Heading, Icon } from '../../../atoms';
+import { Modal } from './modal';
+
+const children =
+ 'Labore ullam delectus sit modi quam dolores. Ratione id sint aliquid facilis ipsum. Unde necessitatibus provident minus.';
+
+describe('Modal', () => {
+ it('renders the modal contents', () => {
+ render(<Modal>{children}</Modal>);
+
+ expect(rtlScreen.getByText(children)).toBeInTheDocument();
+ });
+
+ it('can render a heading', () => {
+ const heading = 'A custom heading';
+ const level = 2;
+
+ render(
+ <Modal heading={<Heading level={level}>{heading}</Heading>}>
+ {children}
+ </Modal>
+ );
+
+ expect(rtlScreen.getByRole('heading', { level })).toHaveTextContent(
+ heading
+ );
+ });
+
+ it('can render an icon', () => {
+ const label = 'maxime ut eius';
+
+ render(
+ <Modal icon={<Icon aria-label={label} shape="arrow" />}>{children}</Modal>
+ );
+
+ expect(rtlScreen.getByLabelText(label)).toBeInTheDocument();
+ });
+
+ it('can render a close button', () => {
+ const btn = 'consequatur';
+
+ render(<Modal closeBtnLabel={btn}>{children}</Modal>);
+
+ expect(rtlScreen.getByRole('button', { name: btn })).toBeInTheDocument();
+ });
+});