diff --git a/src/containers/SelectSessionModal/__snapshots__/index.test.jsx.snap b/src/containers/SelectSessionModal/__snapshots__/index.test.jsx.snap deleted file mode 100644 index 1afb69c..0000000 --- a/src/containers/SelectSessionModal/__snapshots__/index.test.jsx.snap +++ /dev/null @@ -1,176 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`SelectSessionModal snapshot empty modal with leave option 1`] = ` - -

- test-header -

- - - test-hint - - - - Leave session - - - - - - - -
-`; - -exports[`SelectSessionModal snapshot modal with leave option 1`] = ` - -

- test-header -

- - - test-hint - - - - 1/2/2000 - - - 1/2/2020 - - - 2/3/2000 - - - 2/3/2020 - - - 3/4/2000 - - - 3/4/2020 - - - Leave session - - - - - - - -
-`; - -exports[`SelectSessionModal snapshot modal without leave option 1`] = ` - -

- test-header -

- - - test-hint - - - - 1/2/2000 - - - 1/2/2020 - - - 2/3/2000 - - - 2/3/2020 - - - 3/4/2000 - - - 3/4/2020 - - - - - - - -
-`; diff --git a/src/containers/SelectSessionModal/index.test.jsx b/src/containers/SelectSessionModal/index.test.jsx index 19958d5..c249802 100644 --- a/src/containers/SelectSessionModal/index.test.jsx +++ b/src/containers/SelectSessionModal/index.test.jsx @@ -1,14 +1,19 @@ -import React from 'react'; -import { shallow } from '@edx/react-unit-test-utils'; - +import { render, screen } from '@testing-library/react'; +import { formatMessage } from 'testUtils'; +import { IntlProvider } from '@edx/frontend-platform/i18n'; import hooks from './hooks'; import SelectSessionModal from '.'; +import messages from './messages'; jest.mock('./hooks', () => ({ __esModule: true, default: jest.fn(), })); +jest.unmock('@edx/frontend-platform/i18n'); +jest.unmock('@openedx/paragon'); +jest.unmock('react'); + const hookReturn = { availableSessions: [], showModal: true, @@ -25,29 +30,41 @@ const availableSessions = [ ]; describe('SelectSessionModal', () => { - describe('snapshot', () => { - test('empty modal with leave option ', () => { + describe('renders', () => { + it('empty modal with leave option ', () => { hooks.mockReturnValueOnce({ ...hookReturn, }); - expect(shallow().snapshot).toMatchSnapshot(); + render(); + const sessionOption = screen.queryByDisplayValue(availableSessions[0].courseId); + expect(sessionOption).toBeNull(); + const leaveOption = screen.getByRole('radio', { name: formatMessage(messages.leaveSessionOption) }); + expect(leaveOption).toBeInTheDocument(); }); - test('modal with leave option ', () => { + it('modal with leave option ', () => { hooks.mockReturnValueOnce({ ...hookReturn, - availableSessions: [...availableSessions], + availableSessions, }); - expect(shallow().snapshot).toMatchSnapshot(); + render(); + const sessionOption = screen.getByDisplayValue(availableSessions[0].courseId); + expect(sessionOption).toBeInTheDocument(); + const leaveOption = screen.getByRole('radio', { name: formatMessage(messages.leaveSessionOption) }); + expect(leaveOption).toBeInTheDocument(); }); - test('modal without leave option ', () => { + it('modal without leave option ', () => { hooks.mockReturnValueOnce({ ...hookReturn, availableSessions, showLeaveOption: false, }); - expect(shallow().snapshot).toMatchSnapshot(); + render(); + const sessionOption = screen.getByDisplayValue(availableSessions[0].courseId); + expect(sessionOption).toBeInTheDocument(); + const leaveOption = screen.queryByRole('radio', { name: formatMessage(messages.leaveSessionOption) }); + expect(leaveOption).toBeNull(); }); }); }); diff --git a/src/containers/UnenrollConfirmModal/__snapshots__/index.test.jsx.snap b/src/containers/UnenrollConfirmModal/__snapshots__/index.test.jsx.snap deleted file mode 100644 index 87ad3a8..0000000 --- a/src/containers/UnenrollConfirmModal/__snapshots__/index.test.jsx.snap +++ /dev/null @@ -1,101 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`UnenrollConfirmModal component snapshot: modalStates.confirm 1`] = ` - -
- -
-
-`; - -exports[`UnenrollConfirmModal component snapshot: modalStates.finished, reason given 1`] = ` - -
- -
-
-`; - -exports[`UnenrollConfirmModal component snapshot: modalStates.finished, reason skipped 1`] = ` - -
- -
-
-`; - -exports[`UnenrollConfirmModal component snapshot: modalStates.reason, should be fullscreen with no shadow 1`] = ` - -
- -
-
-`; diff --git a/src/containers/UnenrollConfirmModal/components/ConfirmPane.test.jsx b/src/containers/UnenrollConfirmModal/components/ConfirmPane.test.jsx index 545d149..42d0f0b 100644 --- a/src/containers/UnenrollConfirmModal/components/ConfirmPane.test.jsx +++ b/src/containers/UnenrollConfirmModal/components/ConfirmPane.test.jsx @@ -1,14 +1,34 @@ -import React from 'react'; -import { shallow } from '@edx/react-unit-test-utils'; +import { render, screen } from '@testing-library/react'; +import { formatMessage } from 'testUtils'; +import { IntlProvider } from '@edx/frontend-platform/i18n'; import { ConfirmPane } from './ConfirmPane'; +import messages from './messages'; + +jest.unmock('@edx/frontend-platform/i18n'); +jest.unmock('@openedx/paragon'); +jest.unmock('react'); + +const props = { + handleClose: jest.fn().mockName('props.handleClose'), + handleConfirm: jest.fn().mockName('props.handleConfirm'), +}; describe('UnenrollConfirmModal ConfirmPane', () => { - test('snapshot', () => { - const props = { - handleClose: jest.fn().mockName('props.handleClose'), - handleConfirm: jest.fn().mockName('props.handleConfirm'), - }; - expect(shallow().snapshot).toMatchSnapshot(); + beforeEach(() => { + jest.clearAllMocks(); + render(); + }); + it('renders title', () => { + const header = screen.getByText(formatMessage(messages.confirmHeader)); + expect(header).toBeInTheDocument(); + }); + it('renders cancel button', () => { + const cancelButton = screen.getByRole('button', { name: formatMessage(messages.confirmCancel) }); + expect(cancelButton).toBeInTheDocument(); + }); + it('renders unenroll button', () => { + const unenrollButton = screen.getByRole('button', { name: formatMessage(messages.confirmUnenroll) }); + expect(unenrollButton).toBeInTheDocument(); }); }); diff --git a/src/containers/UnenrollConfirmModal/components/FinishedPane.test.jsx b/src/containers/UnenrollConfirmModal/components/FinishedPane.test.jsx index 1ec5e35..dfbbc5c 100644 --- a/src/containers/UnenrollConfirmModal/components/FinishedPane.test.jsx +++ b/src/containers/UnenrollConfirmModal/components/FinishedPane.test.jsx @@ -1,21 +1,50 @@ -import React from 'react'; -import { shallow } from '@edx/react-unit-test-utils'; +import { render, screen } from '@testing-library/react'; +import { formatMessage } from 'testUtils'; +import { IntlProvider } from '@edx/frontend-platform/i18n'; import { FinishedPane } from './FinishedPane'; +import messages from './messages'; + +jest.unmock('@edx/frontend-platform/i18n'); +jest.unmock('@openedx/paragon'); +jest.unmock('react'); + +const props = { + gaveReason: true, + handleClose: jest.fn().mockName('props.handleClose'), +}; describe('UnenrollConfirmModal FinishedPane', () => { - test('snapshot: gave reason', () => { - const props = { - gaveReason: true, - handleClose: jest.fn().mockName('props.handleClose'), - }; - expect(shallow().snapshot).toMatchSnapshot(); + describe('gave reason', () => { + beforeEach(() => { + jest.clearAllMocks(); + render(); + }); + it('renders heading', () => { + const heading = screen.getByText(formatMessage(messages.finishHeading)); + expect(heading).toBeInTheDocument(); + }); + it('renders return button', () => { + const returnButton = screen.getByRole('button', { name: formatMessage(messages.finishReturn) }); + expect(returnButton).toBeInTheDocument(); + }); + it('Gave reason, display thanks message', () => { + const thanksMsg = screen.getByText((text) => text.includes('Thank you')); + expect(thanksMsg).toBeInTheDocument(); + expect(thanksMsg.innerHTML).toContain(formatMessage(messages.finishThanksText)); + }); }); - test('snapshot: did not give reason', () => { - const props = { - gaveReason: false, - handleClose: jest.fn().mockName('props.handleClose'), - }; - expect(shallow().snapshot).toMatchSnapshot(); + describe('Did not give reason', () => { + it('Does not display thanks message', () => { + const customProps = { + gaveReason: false, + handleClose: jest.fn().mockName('props.handleClose'), + }; + render(); + const thanksMsg = screen.queryByText((text) => text.includes('Thank you')); + expect(thanksMsg).toBeNull(); + const finishMsg = screen.getByText(formatMessage(messages.finishText)); + expect(finishMsg).toBeInTheDocument(); + }); }); }); diff --git a/src/containers/UnenrollConfirmModal/components/ReasonPane.test.jsx b/src/containers/UnenrollConfirmModal/components/ReasonPane.test.jsx index df168dd..0f1170c 100644 --- a/src/containers/UnenrollConfirmModal/components/ReasonPane.test.jsx +++ b/src/containers/UnenrollConfirmModal/components/ReasonPane.test.jsx @@ -1,7 +1,13 @@ -import React from 'react'; -import { shallow } from '@edx/react-unit-test-utils'; +import { render, screen } from '@testing-library/react'; +import { formatMessage } from 'testUtils'; +import { IntlProvider } from '@edx/frontend-platform/i18n'; import { ReasonPane } from './ReasonPane'; +import messages from './messages'; + +jest.unmock('@edx/frontend-platform/i18n'); +jest.unmock('@openedx/paragon'); +jest.unmock('react'); describe('UnenrollConfirmModal ReasonPane', () => { const props = { @@ -17,10 +23,25 @@ describe('UnenrollConfirmModal ReasonPane', () => { hasReason: true, }, }; - test('snapshot', () => { - expect(shallow().snapshot).toMatchSnapshot(); + it('render heading', () => { + render(); + const heading = screen.getByText(formatMessage(messages.reasonHeading)); + expect(heading).toBeInTheDocument(); }); - test('snapshot: no reason provided', () => { - expect(shallow().snapshot).toMatchSnapshot(); + it('render options', () => { + render(); + const radioButtons = screen.getAllByRole('radio'); + expect(radioButtons).toBeDefined(); + expect(radioButtons.length).toBe(10); + }); + it('render skip button', () => { + render(); + const skipButton = screen.getByRole('button', { name: formatMessage(messages.reasonSkip) }); + expect(skipButton).toBeInTheDocument(); + }); + it('render submit button', () => { + render(); + const submitButton = screen.getByRole('button', { name: formatMessage(messages.reasonSubmit) }); + expect(submitButton).toBeInTheDocument(); }); }); diff --git a/src/containers/UnenrollConfirmModal/components/__snapshots__/ConfirmPane.test.jsx.snap b/src/containers/UnenrollConfirmModal/components/__snapshots__/ConfirmPane.test.jsx.snap deleted file mode 100644 index fddac21..0000000 --- a/src/containers/UnenrollConfirmModal/components/__snapshots__/ConfirmPane.test.jsx.snap +++ /dev/null @@ -1,22 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`UnenrollConfirmModal ConfirmPane snapshot 1`] = ` - -

- Unenroll from course? -

- - - - -
-`; diff --git a/src/containers/UnenrollConfirmModal/components/__snapshots__/FinishedPane.test.jsx.snap b/src/containers/UnenrollConfirmModal/components/__snapshots__/FinishedPane.test.jsx.snap deleted file mode 100644 index 88a0dd1..0000000 --- a/src/containers/UnenrollConfirmModal/components/__snapshots__/FinishedPane.test.jsx.snap +++ /dev/null @@ -1,38 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`UnenrollConfirmModal FinishedPane snapshot: did not give reason 1`] = ` - -

- You are unenrolled -

-

- This course will be removed from your dashboard. -

- - - -
-`; - -exports[`UnenrollConfirmModal FinishedPane snapshot: gave reason 1`] = ` - -

- You are unenrolled -

-

- Thank you for sharing your reason for unenrolling. - This course will be removed from your dashboard. -

- - - -
-`; diff --git a/src/containers/UnenrollConfirmModal/components/__snapshots__/ReasonPane.test.jsx.snap b/src/containers/UnenrollConfirmModal/components/__snapshots__/ReasonPane.test.jsx.snap deleted file mode 100644 index 3e2bec8..0000000 --- a/src/containers/UnenrollConfirmModal/components/__snapshots__/ReasonPane.test.jsx.snap +++ /dev/null @@ -1,183 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`UnenrollConfirmModal ReasonPane snapshot 1`] = ` - -

- What's your main reason for unenrolling? -

- - - I don't have the academic or language prerequisites - - - The course material was too hard - - - This won't help me reach my goals - - - Something was broken - - - I don't have the time - - - I just wanted to browse the material - - - I don't have enough support - - - I am not happy with the quality of the content - - - The course material was too easy - - - - - - - - - -
-`; - -exports[`UnenrollConfirmModal ReasonPane snapshot: no reason provided 1`] = ` - -

- What's your main reason for unenrolling? -

- - - I don't have the academic or language prerequisites - - - The course material was too hard - - - This won't help me reach my goals - - - Something was broken - - - I don't have the time - - - I just wanted to browse the material - - - I don't have enough support - - - I am not happy with the quality of the content - - - The course material was too easy - - - - - - - - - -
-`; diff --git a/src/containers/UnenrollConfirmModal/index.test.jsx b/src/containers/UnenrollConfirmModal/index.test.jsx index e0a470b..67f91c1 100644 --- a/src/containers/UnenrollConfirmModal/index.test.jsx +++ b/src/containers/UnenrollConfirmModal/index.test.jsx @@ -1,13 +1,11 @@ -import React from 'react'; -import { shallow } from '@edx/react-unit-test-utils'; +import { render, screen } from '@testing-library/react'; +import { formatMessage } from 'testUtils'; +import { IntlProvider } from '@edx/frontend-platform/i18n'; import { UnenrollConfirmModal } from '.'; import * as hooks from './hooks'; - -jest.mock('./components/ConfirmPane', () => 'ConfirmPane'); -jest.mock('./components/ReasonPane', () => 'ReasonPane'); -jest.mock('./components/FinishedPane', () => 'FinishedPane'); +import messages from './components/messages'; jest.mock('./hooks', () => ({ __esModule: true, @@ -15,6 +13,10 @@ jest.mock('./hooks', () => ({ useUnenrollData: jest.fn(), })); +jest.unmock('@edx/frontend-platform/i18n'); +jest.unmock('@openedx/paragon'); +jest.unmock('react'); + describe('UnenrollConfirmModal component', () => { const hookProps = { confirm: jest.fn().mockName('hooks.confirm'), @@ -33,29 +35,48 @@ describe('UnenrollConfirmModal component', () => { show: true, cardId, }; - test('hooks called with closeModal and cardId', () => { + it('hooks called with closeModal and cardId', () => { hooks.useUnenrollData.mockReturnValueOnce(hookProps); - shallow(); + render(); expect(hooks.useUnenrollData).toHaveBeenCalledWith({ closeModal, cardId }); }); - test('snapshot: modalStates.confirm', () => { + it('modalStates.confirm display correct component and to have class shadow', () => { hooks.useUnenrollData.mockReturnValueOnce(hookProps); - expect(shallow().snapshot).toMatchSnapshot(); + render(); + const confirmHeader = screen.getByText(formatMessage(messages.confirmHeader)); + expect(confirmHeader).toBeInTheDocument(); + const dialogContainer = screen.getByRole('dialog').firstElementChild; + expect(dialogContainer).toHaveClass('shadow'); }); - test('snapshot: modalStates.finished, reason given', () => { + it('modalStates.finished, reason given, display correct component', () => { hooks.useUnenrollData.mockReturnValueOnce({ ...hookProps, modalState: hooks.modalStates.finished }); - expect(shallow().snapshot).toMatchSnapshot(); + render(); + const finishHeading = screen.getByText(formatMessage(messages.finishHeading)); + expect(finishHeading).toBeInTheDocument(); + const thanksMsg = screen.getByText((text) => text.includes('Thank you')); + expect(thanksMsg).toBeInTheDocument(); + expect(thanksMsg.innerHTML).toContain(formatMessage(messages.finishThanksText)); }); - test('snapshot: modalStates.finished, reason skipped', () => { + it('modalStates.finished, reason skipped', () => { hooks.useUnenrollData.mockReturnValueOnce({ ...hookProps, modalState: hooks.modalStates.finished, - isSkipped: true, + reason: { isSkipped: true }, }); - expect(shallow().snapshot).toMatchSnapshot(); + render(); + const finishHeading = screen.getByText(formatMessage(messages.finishHeading)); + expect(finishHeading).toBeInTheDocument(); + const thanksMsg = screen.queryByText((text) => text.includes('Thank you')); + expect(thanksMsg).toBeNull(); + const finishMsg = screen.getByText(formatMessage(messages.finishText)); + expect(finishMsg).toBeInTheDocument(); }); - test('snapshot: modalStates.reason, should be fullscreen with no shadow', () => { + it('modalStates.reason, should display correct component with no shadow', () => { hooks.useUnenrollData.mockReturnValueOnce({ ...hookProps, modalState: hooks.modalStates.reason }); - expect(shallow().snapshot).toMatchSnapshot(); + render(); + const reasonHeading = screen.getByText(formatMessage(messages.reasonHeading)); + expect(reasonHeading).toBeInTheDocument(); + const dialogContainer = screen.getByRole('dialog').firstElementChild; + expect(dialogContainer).not.toHaveClass('shadow'); }); });