Skip to content

Commit ce1848a

Browse files
authored
Revert "fix: display programs only if the url is configured (#479)" (#504)
2 parents bc449a3 + ee515ad commit ce1848a

File tree

9 files changed

+10
-84
lines changed

9 files changed

+10
-84
lines changed

src/containers/LearnerDashboardHeader/LearnerDashboardMenu.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const getLearnerHeaderMenu = (
99
courseSearchUrl,
1010
authenticatedUser,
1111
exploreCoursesClick,
12-
programsEnabled = false,
1312
) => ({
1413
mainMenu: [
1514
{
@@ -18,11 +17,11 @@ const getLearnerHeaderMenu = (
1817
content: formatMessage(messages.course),
1918
isActive: true,
2019
},
21-
...(programsEnabled ? [{
20+
{
2221
type: 'item',
2322
href: `${urls.programsUrl()}`,
2423
content: formatMessage(messages.program),
25-
}] : []),
24+
},
2625
{
2726
type: 'item',
2827
href: `${urls.baseAppUrl(courseSearchUrl)}`,

src/containers/LearnerDashboardHeader/__snapshots__/index.test.jsx.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ exports[`LearnerDashboardHeader render 1`] = `
1212
"isActive": true,
1313
"type": "item",
1414
},
15+
{
16+
"content": "Programs",
17+
"href": "http://localhost:18000/dashboard/programs",
18+
"type": "item",
19+
},
1520
{
1621
"content": "Discover New",
1722
"href": "http://localhost:18000/course-search-url",

src/containers/LearnerDashboardHeader/hooks.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import track from 'tracking';
55
import { StrictDict } from 'utils';
66
import { linkNames } from 'tracking/constants';
77

8-
import { apiHooks } from 'hooks';
98
import getLearnerHeaderMenu from './LearnerDashboardMenu';
109

1110
import * as module from './hooks';
@@ -31,9 +30,8 @@ export const findCoursesNavDropdownClicked = (href) => track.findCourses.findCou
3130
export const useLearnerDashboardHeaderMenu = ({
3231
courseSearchUrl, authenticatedUser, exploreCoursesClick,
3332
}) => {
34-
const { enabled: programsEnabled } = apiHooks.useProgramsConfig();
3533
const { formatMessage } = useIntl();
36-
return getLearnerHeaderMenu(formatMessage, courseSearchUrl, authenticatedUser, exploreCoursesClick, programsEnabled);
34+
return getLearnerHeaderMenu(formatMessage, courseSearchUrl, authenticatedUser, exploreCoursesClick);
3735
};
3836

3937
export const useLearnerDashboardHeaderData = () => {

src/containers/LearnerDashboardHeader/hooks.test.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ jest.mock('tracking', () => ({
2121
findCoursesClicked: jest.fn(),
2222
},
2323
}));
24-
jest.mock('hooks', () => ({
25-
apiHooks: {
26-
useProgramsConfig: jest.fn(() => ({})),
27-
},
28-
}));
2924

3025
const url = 'http://example.com';
3126

@@ -61,7 +56,7 @@ describe('LearnerDashboardHeader hooks', () => {
6156
username: 'test',
6257
};
6358
const learnerHomeHeaderMenu = useLearnerDashboardHeaderMenu({ courseSearchUrl, authenticatedUser });
64-
expect(learnerHomeHeaderMenu.mainMenu.length).toBe(2);
59+
expect(learnerHomeHeaderMenu.mainMenu.length).toBe(3);
6560
});
6661
});
6762

src/containers/LearnerDashboardHeader/index.test.jsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { shallow } from '@edx/react-unit-test-utils';
33
import Header from '@edx/frontend-component-header';
44

55
import urls from 'data/services/lms/urls';
6-
import { apiHooks } from 'hooks';
76
import LearnerDashboardHeader from '.';
87
import { findCoursesNavClicked } from './hooks';
98

@@ -13,9 +12,6 @@ jest.mock('hooks', () => ({
1312
courseSearchUrl: '/course-search-url',
1413
})),
1514
},
16-
apiHooks: {
17-
useProgramsConfig: jest.fn(() => ({})),
18-
},
1915
}));
2016
jest.mock('./hooks', () => ({
2117
...jest.requireActual('./hooks'),
@@ -33,7 +29,7 @@ describe('LearnerDashboardHeader', () => {
3329
expect(wrapper.instance.findByType('ConfirmEmailBanner')).toHaveLength(1);
3430
expect(wrapper.instance.findByType('MasqueradeBar')).toHaveLength(1);
3531
expect(wrapper.instance.findByType(Header)).toHaveLength(1);
36-
wrapper.instance.findByType(Header)[0].props.mainMenuItems[1].onClick();
32+
wrapper.instance.findByType(Header)[0].props.mainMenuItems[2].onClick();
3733
expect(findCoursesNavClicked).toHaveBeenCalledWith(urls.baseAppUrl('/course-search-url'));
3834
expect(wrapper.instance.findByType(Header)[0].props.secondaryMenuItems.length).toBe(0);
3935
});
@@ -42,11 +38,5 @@ describe('LearnerDashboardHeader', () => {
4238
mergeConfig({ SUPPORT_URL: 'http://localhost:18000/support' });
4339
const wrapper = shallow(<LearnerDashboardHeader />);
4440
expect(wrapper.instance.findByType(Header)[0].props.secondaryMenuItems.length).toBe(1);
45-
expect(wrapper.instance.findByType(Header)[0].props.mainMenuItems.length).toBe(2);
46-
});
47-
test('should display Programs link if the service is configured in the backend', () => {
48-
apiHooks.useProgramsConfig.mockReturnValue({ enabled: true });
49-
const wrapper = shallow(<LearnerDashboardHeader />);
50-
expect(wrapper.instance.findByType(Header)[0].props.mainMenuItems.length).toBe(3);
5141
});
5242
});

src/data/services/lms/api.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ export const initializeList = ({ user } = {}) => get(
2020
stringifyUrl(urls.getInitApiUrl(), { [apiKeys.user]: user }),
2121
);
2222

23-
export const getProgramsConfig = () => get(urls.programsConfigUrl());
24-
2523
export const updateEntitlementEnrollment = ({ uuid, courseId }) => post(
2624
urls.entitlementEnrollment(uuid),
2725
{ [apiKeys.courseRunId]: courseId },
@@ -75,7 +73,6 @@ export const createCreditRequest = ({ providerId, courseId, username }) => post(
7573

7674
export default {
7775
initializeList,
78-
getProgramsConfig,
7976
unenrollFromCourse,
8077
updateEmailSettings,
8178
updateEntitlementEnrollment,

src/data/services/lms/urls.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export const baseAppUrl = (url) => updateUrl(getBaseUrl(), url);
2222
export const learningMfeUrl = (url) => updateUrl(getConfig().LEARNING_BASE_URL, url);
2323

2424
// static view url
25-
const programsConfigUrl = () => baseAppUrl('/config/programs');
2625
const programsUrl = () => baseAppUrl('/dashboard/programs');
2726

2827
export const creditPurchaseUrl = (courseId) => `${getEcommerceUrl()}/credit/checkout/${courseId}/`;
@@ -38,7 +37,6 @@ export default StrictDict({
3837
event,
3938
getInitApiUrl,
4039
learningMfeUrl,
41-
programsConfigUrl,
4240
programsUrl,
4341
updateEmailSettings,
4442
});

src/hooks/api.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22

3-
import { logError } from '@edx/frontend-platform/logging';
43
import { AppContext } from '@edx/frontend-platform/react';
54

65
import { RequestKeys } from 'data/constants/requests';
@@ -32,25 +31,6 @@ export const useInitializeApp = () => {
3231
});
3332
};
3433

35-
export const useProgramsConfig = () => {
36-
const [config, setConfig] = React.useState({});
37-
38-
React.useEffect(() => {
39-
const fetchProgramsConfig = async () => {
40-
try {
41-
const { data } = await api.getProgramsConfig();
42-
setConfig(data);
43-
} catch (error) {
44-
logError(`Error accessing programs configuration ${error}`);
45-
}
46-
};
47-
48-
fetchProgramsConfig();
49-
}, []);
50-
51-
return config;
52-
};
53-
5434
export const useNewEntitlementEnrollment = (cardId) => {
5535
const { uuid } = reduxHooks.useCardEntitlementData(cardId);
5636
const onSuccess = module.useInitializeApp();

src/hooks/api.test.js

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import { logError } from '@edx/frontend-platform/logging';
32
import { AppContext } from '@edx/frontend-platform/react';
43
import { keyStore } from 'utils';
54
import { RequestKeys } from 'data/constants/requests';
@@ -11,24 +10,17 @@ import * as apiHooks from './api';
1110

1211
const reduxKeys = keyStore(reduxHooks);
1312

14-
jest.mock('@edx/frontend-platform/logging', () => ({
15-
logError: jest.fn(),
16-
}));
17-
1813
jest.mock('data/services/lms/utils', () => ({
1914
post: jest.fn((...args) => ({ post: args })),
2015
}));
21-
2216
jest.mock('data/services/lms/api', () => ({
2317
initializeList: jest.fn(),
2418
updateEntitlementEnrollment: jest.fn(),
2519
unenrollFromCourse: jest.fn(),
2620
deleteEntitlementEnrollment: jest.fn(),
2721
updateEmailSettings: jest.fn(),
2822
createCreditRequest: jest.fn(),
29-
getProgramsConfig: jest.fn(),
3023
}));
31-
3224
jest.mock('data/redux/hooks', () => ({
3325
useCardCourseRunData: jest.fn(),
3426
useCardCreditData: jest.fn(),
@@ -118,34 +110,6 @@ describe('api hooks', () => {
118110
});
119111
});
120112

121-
describe('useProgramsConfig', () => {
122-
let mockState;
123-
const setState = jest.fn((newState) => { Object.assign(mockState, newState); });
124-
beforeEach(() => {
125-
mockState = {};
126-
React.useState.mockReturnValue([mockState, setState]);
127-
});
128-
129-
it('should return the programs configuration when the API call is successful', async () => {
130-
api.getProgramsConfig.mockResolvedValue({ data: { enabled: true } });
131-
const config = apiHooks.useProgramsConfig();
132-
const [cb] = React.useEffect.mock.calls[0];
133-
await cb();
134-
expect(setState).toHaveBeenCalled();
135-
expect(config).toEqual({ enabled: true });
136-
});
137-
138-
it('should return an empty object if the api call fails', async () => {
139-
mockState = {};
140-
api.getProgramsConfig.mockRejectedValue(new Error('error test'));
141-
const config = apiHooks.useProgramsConfig();
142-
const [cb] = React.useEffect.mock.calls[0];
143-
await cb();
144-
expect(config).toEqual({});
145-
expect(logError).toHaveBeenCalled();
146-
});
147-
});
148-
149113
describe('entitlement enrollment hooks', () => {
150114
beforeEach(() => {
151115
jest.spyOn(apiHooks, moduleKeys.useInitializeApp).mockReturnValue(initializeApp);

0 commit comments

Comments
 (0)