diff --git a/app/javascript/crayons/Modal/Modal.jsx b/app/javascript/crayons/Modal/Modal.jsx
index dddaa85ee..b214e0f2f 100644
--- a/app/javascript/crayons/Modal/Modal.jsx
+++ b/app/javascript/crayons/Modal/Modal.jsx
@@ -17,6 +17,21 @@ function getAdditionalClassNames({ size, className }) {
return additionalClassNames;
}
+const CloseIcon = () => (
+
+);
+
export const Modal = ({
children,
size = 'default',
@@ -25,44 +40,32 @@ export const Modal = ({
overlay,
onClose,
}) => {
- const Icon = () => (
-
- );
-
return (
-
+
{title.length > 0 && title && (
{title}
)}
{children}
- {overlay &&
}
+ {overlay && (
+
+ )}
);
};
diff --git a/app/javascript/crayons/Modal/__tests__/Modal.test.jsx b/app/javascript/crayons/Modal/__tests__/Modal.test.jsx
new file mode 100644
index 000000000..1af598725
--- /dev/null
+++ b/app/javascript/crayons/Modal/__tests__/Modal.test.jsx
@@ -0,0 +1,77 @@
+import { h } from 'preact';
+import { axe } from 'jest-axe';
+import { render } from '@testing-library/preact';
+import { Modal } from '../Modal';
+
+it('should have no a11y violations', async () => {
+ const { container } = render(
+
This is the modal body content,
+ );
+ const results = await axe(container);
+
+ expect(results).toHaveNoViolations();
+});
+
+it('should close when the close button is clicked', async () => {
+ const onClose = jest.fn();
+ const { getByLabelText } = render(
+
+ This is the modal body content
+ ,
+ );
+
+ const closeButton = getByLabelText('Close', { selector: 'button' });
+
+ closeButton.click();
+
+ expect(onClose).toHaveBeenCalledTimes(1);
+});
+
+it('should render with additional class names', async () => {
+ const { getByTestId } = render(
+
+ This is the modal body content
+ ,
+ );
+
+ const modalContainer = getByTestId('modal-container');
+
+ expect(
+ modalContainer.classList.contains('some-additional-class-name'),
+ ).toEqual(true);
+});
+
+it('should render with an overlay', async () => {
+ const { getByTestId } = render(
+
+ This is the modal body content
+ ,
+ );
+
+ const modalOverlay = getByTestId('modal-overlay');
+
+ expect(modalOverlay).not.toBeNull();
+});
+
+it('should render with a different size modal', async () => {
+ const { getByTestId } = render(
+
+ This is the modal body content
+ ,
+ );
+
+ const modalContainer = getByTestId('modal-container');
+
+ expect(modalContainer.classList.contains('crayons-modal--large')).toEqual(
+ true,
+ );
+});