From 044bf0f45a539f4e12cf4ddd7ccef963a7f88afa Mon Sep 17 00:00:00 2001 From: Ben Warzeski Date: Wed, 21 Dec 2022 10:47:43 -0500 Subject: [PATCH] fix: disable reason select if no reason selected (#101) --- .../SelectSessionModal/hooks.test.js | 18 ++++ .../components/ReasonPane.jsx | 3 +- .../components/ReasonPane.test.jsx | 4 + .../__snapshots__/ReasonPane.test.jsx.snap | 92 +++++++++++++++++++ .../UnenrollConfirmModal/hooks/reasons.js | 2 + .../hooks/reasons.test.js | 24 +++++ 6 files changed, 142 insertions(+), 1 deletion(-) diff --git a/src/containers/SelectSessionModal/hooks.test.js b/src/containers/SelectSessionModal/hooks.test.js index 1cb53e7..136c0cb 100644 --- a/src/containers/SelectSessionModal/hooks.test.js +++ b/src/containers/SelectSessionModal/hooks.test.js @@ -4,11 +4,19 @@ import { useIntl } from '@edx/frontend-platform/i18n'; import { MockUseState } from 'testUtils'; import { hooks as appHooks, thunkActions } from 'data/redux'; +import track from 'tracking'; import { LEAVE_OPTION } from './constants'; import messages from './messages'; import * as hooks from './hooks'; +jest.mock('tracking', () => ({ + entitlements: { + newSession: jest.fn(), + switchSession: jest.fn(), + leaveSession: jest.fn(), + }, +})); jest.mock('data/redux', () => ({ hooks: { useCardCourseData: jest.fn(), @@ -57,6 +65,13 @@ const testValue = 'test-value'; const courseId = 'test-course-id'; appHooks.useCardCourseRunData.mockReturnValue({ courseId }); +const newSession = jest.fn(); +const switchSession = jest.fn(); +const leaveSession = jest.fn(); +track.entitlements.newSession.mockReturnValue(newSession); +track.entitlements.switchSession.mockReturnValue(switchSession); +track.entitlements.leaveSession.mockReturnValue(leaveSession); + describe('SelectSessionModal hooks', () => { let out; @@ -116,6 +131,7 @@ describe('SelectSessionModal hooks', () => { state.mockVal(state.keys.selectedSession, LEAVE_OPTION); runHook({}); out.handleSubmit(); + expect(leaveSession).toHaveBeenCalledWith(); expect(dispatch).toHaveBeenCalledWith( thunkActions.app.leaveEntitlementSession(selectedCardId), ); @@ -126,6 +142,7 @@ describe('SelectSessionModal hooks', () => { state.mockVal(state.keys.selectedSession, testValue); runHook({}); out.handleSubmit(); + expect(newSession).toHaveBeenCalledWith(); expect(dispatch).toHaveBeenCalledWith( thunkActions.app.newEntitlementEnrollment(selectedCardId, testValue), ); @@ -136,6 +153,7 @@ describe('SelectSessionModal hooks', () => { state.mockVal(state.keys.selectedSession, testValue); runHook({ enrollment: { isEnrolled: true } }); out.handleSubmit(); + expect(switchSession).toHaveBeenCalledWith(); expect(dispatch).toHaveBeenCalledWith( thunkActions.app.switchEntitlementEnrollment(selectedCardId, testValue), ); diff --git a/src/containers/UnenrollConfirmModal/components/ReasonPane.jsx b/src/containers/UnenrollConfirmModal/components/ReasonPane.jsx index 843767a..9e7054c 100644 --- a/src/containers/UnenrollConfirmModal/components/ReasonPane.jsx +++ b/src/containers/UnenrollConfirmModal/components/ReasonPane.jsx @@ -40,7 +40,7 @@ export const ReasonPane = ({ - @@ -51,6 +51,7 @@ ReasonPane.propTypes = { reason: PropTypes.shape({ value: PropTypes.string, handleSkip: PropTypes.func, + hasReason: PropTypes.bool, selectOption: PropTypes.func, customOption: PropTypes.shape({ value: PropTypes.string, diff --git a/src/containers/UnenrollConfirmModal/components/ReasonPane.test.jsx b/src/containers/UnenrollConfirmModal/components/ReasonPane.test.jsx index ddb5033..4c05895 100644 --- a/src/containers/UnenrollConfirmModal/components/ReasonPane.test.jsx +++ b/src/containers/UnenrollConfirmModal/components/ReasonPane.test.jsx @@ -14,9 +14,13 @@ describe('UnenrollConfirmModal ReasonPane', () => { }, selected: 'props.reason.selected', handleSubmit: jest.fn().mockName('props.reason.handleSubmit'), + hasReason: true, }, }; test('snapshot', () => { expect(shallow()).toMatchSnapshot(); }); + test('snapshot: no reason provided', () => { + expect(shallow()).toMatchSnapshot(); + }); }); diff --git a/src/containers/UnenrollConfirmModal/components/__snapshots__/ReasonPane.test.jsx.snap b/src/containers/UnenrollConfirmModal/components/__snapshots__/ReasonPane.test.jsx.snap index 98a2fe9..3e2bec8 100644 --- a/src/containers/UnenrollConfirmModal/components/__snapshots__/ReasonPane.test.jsx.snap +++ b/src/containers/UnenrollConfirmModal/components/__snapshots__/ReasonPane.test.jsx.snap @@ -82,6 +82,98 @@ exports[`UnenrollConfirmModal ReasonPane snapshot 1`] = ` Skip survey + + +`; + +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 + + + + + + + +