Skip to content

Commit ca954e1

Browse files
feat: showing course unenroll survey is configurable now (#738)
1 parent 0d2eb96 commit ca954e1

7 files changed

Lines changed: 89 additions & 12 deletions

File tree

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ CAREER_LINK_URL=''
4242
ENABLE_EDX_PERSONAL_DASHBOARD=false
4343
ENABLE_PROGRAMS=false
4444
NON_BROWSABLE_COURSES=false
45+
SHOW_UNENROLL_SURVEY=true
4546
# Fallback in local style files
4647
PARAGON_THEME_URLS={}

.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@ CAREER_LINK_URL=''
4848
ENABLE_EDX_PERSONAL_DASHBOARD=false
4949
ENABLE_PROGRAMS=false
5050
NON_BROWSABLE_COURSES=false
51+
SHOW_UNENROLL_SURVEY=true
5152
# Fallback in local style files
5253
PARAGON_THEME_URLS={}

.env.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ CAREER_LINK_URL=''
4747
ENABLE_EDX_PERSONAL_DASHBOARD=true
4848
ENABLE_PROGRAMS=false
4949
NON_BROWSABLE_COURSES=false
50+
SHOW_UNENROLL_SURVEY=true
5051
PARAGON_THEME_URLS={}

example.env.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,5 @@ module.exports = {
7070
ACCOUNT_PROFILE_URL: 'http://localhost:1995',
7171
CAREER_LINK_URL: '',
7272
EXPERIMENT_08_23_VAN_PAINTED_DOOR: true,
73+
SHOW_UNENROLL_SURVEY: true
7374
};

src/config/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const configuration = {
2121
SEARCH_CATALOG_URL: process.env.SEARCH_CATALOG_URL || null,
2222
ENABLE_PROGRAMS: process.env.ENABLE_PROGRAMS === 'true',
2323
NON_BROWSABLE_COURSES: process.env.NON_BROWSABLE_COURSES === 'true',
24+
SHOW_UNENROLL_SURVEY: process.env.SHOW_UNENROLL_SURVEY === 'true',
2425
};
2526

2627
const features = {};

src/containers/UnenrollConfirmModal/hooks/index.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import React from 'react';
22

33
import { StrictDict } from 'utils';
44

5-
import { useInitializeLearnerHome } from 'data/hooks';
5+
import { useInitializeLearnerHome, useUnenrollFromCourse } from 'data/hooks';
6+
import { configuration } from 'config';
7+
import { useCourseData } from 'hooks';
68
import { useUnenrollReasons } from './reasons';
79
import * as module from '.';
810

@@ -18,13 +20,23 @@ export const modalStates = StrictDict({
1820

1921
export const useUnenrollData = ({ closeModal, cardId }) => {
2022
const [isConfirmed, setIsConfirmed] = module.state.confirmed(false);
21-
const confirm = () => setIsConfirmed(true);
2223
const reason = useUnenrollReasons({ cardId });
2324
const { refetch: refreshList } = useInitializeLearnerHome();
25+
const courseData = useCourseData(cardId);
26+
const courseId = courseData?.courseRun?.courseId;
27+
28+
const { mutate: unenrollFromCourse } = useUnenrollFromCourse();
29+
30+
const confirm = () => {
31+
if (!configuration.SHOW_UNENROLL_SURVEY) {
32+
unenrollFromCourse({ courseId });
33+
}
34+
setIsConfirmed(true);
35+
};
2436

2537
let modalState;
2638
if (isConfirmed) {
27-
modalState = (reason.isSubmitted)
39+
modalState = (reason.isSubmitted || !configuration.SHOW_UNENROLL_SURVEY)
2840
? modalStates.finished : modalStates.reason;
2941
} else {
3042
modalState = modalStates.confirm;

src/containers/UnenrollConfirmModal/hooks/index.test.js

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { MockUseState } from 'testUtils';
2+
import { configuration } from 'config';
23

3-
import { useInitializeLearnerHome } from 'data/hooks';
4+
import { useInitializeLearnerHome, useUnenrollFromCourse } from 'data/hooks';
5+
import { useCourseData } from 'hooks';
46

57
import * as reasons from './reasons';
68
import * as hooks from '.';
@@ -11,12 +13,26 @@ jest.mock('./reasons', () => ({
1113

1214
jest.mock('data/hooks', () => ({
1315
useInitializeLearnerHome: jest.fn(),
16+
useUnenrollFromCourse: jest.fn(),
17+
}));
18+
19+
jest.mock('hooks', () => ({
20+
useCourseData: jest.fn(),
21+
}));
22+
23+
jest.mock('config', () => ({
24+
configuration: {
25+
SHOW_UNENROLL_SURVEY: true,
26+
},
1427
}));
1528

1629
const state = new MockUseState(hooks);
1730
const testValue = 'test-value';
1831
const mockRefreshList = jest.fn();
32+
const unenrollFromCourse = jest.fn();
1933
useInitializeLearnerHome.mockReturnValue({ refetch: mockRefreshList });
34+
useUnenrollFromCourse.mockReturnValue({ mutate: unenrollFromCourse });
35+
useCourseData.mockReturnValue({ courseRun: { courseId: 'test-course-id' } });
2036
let out;
2137

2238
const mockReason = {
@@ -78,22 +94,66 @@ describe('UnenrollConfirmModal hooks', () => {
7894
expect(mockRefreshList).toHaveBeenCalled();
7995
});
8096
});
81-
describe('modalState', () => {
82-
it('returns modalStates.finished if confirmed and submitted', () => {
97+
});
98+
99+
describe('SHOW_UNENROLL_SURVEY configuration tests', () => {
100+
beforeEach(() => {
101+
state.mock();
102+
jest.clearAllMocks();
103+
});
104+
afterEach(() => {
105+
state.restore();
106+
});
107+
108+
describe('when SHOW_UNENROLL_SURVEY is true (default)', () => {
109+
beforeEach(() => {
110+
configuration.SHOW_UNENROLL_SURVEY = true;
111+
});
112+
113+
test('confirm does not call unenrollFromCourse immediately', () => {
114+
out = createUseUnenrollData();
115+
out.confirm();
116+
expect(unenrollFromCourse).not.toHaveBeenCalled();
117+
expect(state.setState.confirmed).toHaveBeenCalledWith(true);
118+
});
119+
120+
test('modalState returns reason when confirmed but not submitted', () => {
121+
state.mockVal(state.keys.confirmed, true);
122+
reasons.useUnenrollReasons.mockReturnValueOnce({ ...mockReason, isSubmitted: false });
123+
out = createUseUnenrollData();
124+
expect(out.modalState).toEqual(hooks.modalStates.reason);
125+
});
126+
127+
test('modalState returns finished when confirmed and submitted', () => {
83128
state.mockVal(state.keys.confirmed, true);
84129
reasons.useUnenrollReasons.mockReturnValueOnce({ ...mockReason, isSubmitted: true });
85130
out = createUseUnenrollData();
86131
expect(out.modalState).toEqual(hooks.modalStates.finished);
87132
});
88-
it('returns modalStates.reason if confirmed and not submitted', () => {
89-
state.mockVal(state.keys.confirmed, true);
133+
});
134+
135+
describe('when SHOW_UNENROLL_SURVEY is false', () => {
136+
beforeEach(() => {
137+
configuration.SHOW_UNENROLL_SURVEY = false;
138+
});
139+
140+
afterEach(() => {
141+
// Reset to default
142+
configuration.SHOW_UNENROLL_SURVEY = true;
143+
});
144+
145+
test('confirm calls unenrollFromCourse immediately', () => {
90146
out = createUseUnenrollData();
91-
expect(out.modalState).toEqual(hooks.modalStates.reason);
147+
out.confirm();
148+
expect(unenrollFromCourse).toHaveBeenCalled();
149+
expect(state.setState.confirmed).toHaveBeenCalledWith(true);
92150
});
93-
it('returns modalStates.confirm if not confirmed', () => {
94-
state.mockVal(state.keys.confirmed, false);
151+
152+
test('modalState returns finished when confirmed regardless of submission status', () => {
153+
state.mockVal(state.keys.confirmed, true);
154+
reasons.useUnenrollReasons.mockReturnValueOnce({ ...mockReason, isSubmitted: false });
95155
out = createUseUnenrollData();
96-
expect(out.modalState).toEqual(hooks.modalStates.confirm);
156+
expect(out.modalState).toEqual(hooks.modalStates.finished);
97157
});
98158
});
99159
});

0 commit comments

Comments
 (0)