From 300bfd6e693b711efe2c509a2b879c2fd0aef34e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Regadas?= Date: Thu, 13 Apr 2023 11:14:44 +0100 Subject: [PATCH] [MMI] 2642 compliance modal component (#18410) * adds component, styles and storybook file * wip * prettier and adds test * prettier * lint * review fix * lint * updates to IconSize, IconName --- .../compliance-modal.test.js.snap | 93 +++++++++++++++++++ .../compliance-modal/compliance-modal.js | 88 ++++++++++++++++++ .../compliance-modal/compliance-modal.scss | 6 ++ .../compliance-modal.stories.js | 22 +++++ .../compliance-modal/compliance-modal.test.js | 55 +++++++++++ .../institutional/compliance-modal/index.js | 1 + 6 files changed, 265 insertions(+) create mode 100644 ui/components/institutional/compliance-modal/__snapshots__/compliance-modal.test.js.snap create mode 100644 ui/components/institutional/compliance-modal/compliance-modal.js create mode 100644 ui/components/institutional/compliance-modal/compliance-modal.scss create mode 100644 ui/components/institutional/compliance-modal/compliance-modal.stories.js create mode 100644 ui/components/institutional/compliance-modal/compliance-modal.test.js create mode 100644 ui/components/institutional/compliance-modal/index.js diff --git a/ui/components/institutional/compliance-modal/__snapshots__/compliance-modal.test.js.snap b/ui/components/institutional/compliance-modal/__snapshots__/compliance-modal.test.js.snap new file mode 100644 index 000000000..60d85a469 --- /dev/null +++ b/ui/components/institutional/compliance-modal/__snapshots__/compliance-modal.test.js.snap @@ -0,0 +1,93 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ComplianceModal should render the correct content 1`] = ` +
+ +
+`; diff --git a/ui/components/institutional/compliance-modal/compliance-modal.js b/ui/components/institutional/compliance-modal/compliance-modal.js new file mode 100644 index 000000000..5bf2f2497 --- /dev/null +++ b/ui/components/institutional/compliance-modal/compliance-modal.js @@ -0,0 +1,88 @@ +import React from 'react'; +import { useDispatch } from 'react-redux'; +import { useI18nContext } from '../../../hooks/useI18nContext'; +import { hideModal } from '../../../store/actions'; +import Modal from '../../app/modal'; +import Box from '../../ui/box'; +import { Text, ButtonIcon, IconSize, IconName } from '../../component-library'; +import { + AlignItems, + JustifyContent, + TextColor, + DISPLAY, +} from '../../../helpers/constants/design-system'; + +const ComplianceModal = () => { + const dispatch = useDispatch(); + const t = useI18nContext(); + + const handleSubmit = () => { + global.platform.openTab({ + url: 'https://start.compliance.codefi.network/', + }); + }; + + const handleClose = () => dispatch(hideModal()); + + return ( + + + + + Codefi Compliance + + {t('codefiCompliance')} + + + + + + {t('complianceBlurb0')} + + + {t('complianceBlurb1')} + + + {t('complianceBlurpStep0')} + +
    +
  1. {t('complianceBlurbStep1')}
  2. +
  3. {t('complianceBlurbStep2')}
  4. +
  5. {t('complianceBlurbStep3')}
  6. +
  7. {t('complianceBlurbStep4')}
  8. +
  9. {t('complianceBlurbStep5')}
  10. +
+
+
+ ); +}; + +export default ComplianceModal; diff --git a/ui/components/institutional/compliance-modal/compliance-modal.scss b/ui/components/institutional/compliance-modal/compliance-modal.scss new file mode 100644 index 000000000..76570844e --- /dev/null +++ b/ui/components/institutional/compliance-modal/compliance-modal.scss @@ -0,0 +1,6 @@ +.compliance-modal { + ol { + list-style: decimal; + list-style-position: inside; + } +} diff --git a/ui/components/institutional/compliance-modal/compliance-modal.stories.js b/ui/components/institutional/compliance-modal/compliance-modal.stories.js new file mode 100644 index 000000000..5416daeba --- /dev/null +++ b/ui/components/institutional/compliance-modal/compliance-modal.stories.js @@ -0,0 +1,22 @@ +import React from 'react'; +import { Provider } from 'react-redux'; +import configureStore from '../../../store/store'; +import testData from '../../../../.storybook/test-data'; +import ComplianceModal from '.'; + +const store = configureStore(testData); + +export default { + title: 'Components/Institutional/ComplianceModal', + decorators: [(story) => {story()}], + component: ComplianceModal, + argTypes: { + onClick: { + action: 'onClick', + }, + }, +}; + +export const DefaultStory = (args) => ; + +DefaultStory.storyName = 'ComplianceModal'; diff --git a/ui/components/institutional/compliance-modal/compliance-modal.test.js b/ui/components/institutional/compliance-modal/compliance-modal.test.js new file mode 100644 index 000000000..259340edd --- /dev/null +++ b/ui/components/institutional/compliance-modal/compliance-modal.test.js @@ -0,0 +1,55 @@ +import React from 'react'; +import { render, fireEvent } from '@testing-library/react'; +import { useDispatch } from 'react-redux'; +import sinon from 'sinon'; +import { hideModal } from '../../../store/actions'; +import ComplianceModal from '.'; + +jest.mock('react-redux', () => ({ + useDispatch: jest.fn(), +})); + +jest.mock('../../../store/actions', () => ({ + hideModal: jest.fn(), +})); + +describe('ComplianceModal', () => { + let dispatchMock; + + beforeEach(() => { + dispatchMock = jest.fn(); + useDispatch.mockReturnValue(dispatchMock); + }); + + afterEach(() => { + jest.resetAllMocks(); + }); + + it('should render the correct content', () => { + const { container, getByTestId } = render(); + + expect(getByTestId('compliance-info')).toBeInTheDocument(); + expect(getByTestId('compliance-bullets')).toBeInTheDocument(); + expect(container).toMatchSnapshot(); + }); + + it('should close the modal when close button is clicked', () => { + const { getByTestId } = render(); + + fireEvent.click(getByTestId('compliance-modal-close')); + + expect(hideModal).toHaveBeenCalled(); + expect(dispatchMock).toHaveBeenCalledWith(hideModal()); + }); + + it('should open the Compliance page when submit button is clicked', () => { + global.platform = { openTab: sinon.spy() }; + const { container } = render(); + + const btn = container.getElementsByClassName('btn-primary')[0]; + + fireEvent.click(btn); + + expect(global.platform.openTab.called).toBeTruthy(); + }); +}); diff --git a/ui/components/institutional/compliance-modal/index.js b/ui/components/institutional/compliance-modal/index.js new file mode 100644 index 000000000..04582c660 --- /dev/null +++ b/ui/components/institutional/compliance-modal/index.js @@ -0,0 +1 @@ +export { default } from './compliance-modal';