From d6823c85817bf7599a70dba5e81d8cfb40aefade Mon Sep 17 00:00:00 2001 From: Deborah Kaplan Date: Mon, 18 Nov 2024 14:37:40 -0500 Subject: [PATCH] Revert "fix: display programs only if the url is configured (#479)" This reverts commit e8886c9d9d98f65ec31fe5e7fd7de6c3926c2827. --- .../LearnerDashboardMenu.jsx | 5 ++- .../__snapshots__/index.test.jsx.snap | 5 +++ .../LearnerDashboardHeader/hooks.js | 4 +-- .../LearnerDashboardHeader/hooks.test.js | 7 +--- .../LearnerDashboardHeader/index.test.jsx | 12 +------ src/data/services/lms/api.js | 3 -- src/data/services/lms/urls.js | 2 -- src/hooks/api.js | 20 ----------- src/hooks/api.test.js | 36 ------------------- 9 files changed, 10 insertions(+), 84 deletions(-) diff --git a/src/containers/LearnerDashboardHeader/LearnerDashboardMenu.jsx b/src/containers/LearnerDashboardHeader/LearnerDashboardMenu.jsx index 05470194..092bcfe7 100644 --- a/src/containers/LearnerDashboardHeader/LearnerDashboardMenu.jsx +++ b/src/containers/LearnerDashboardHeader/LearnerDashboardMenu.jsx @@ -9,7 +9,6 @@ const getLearnerHeaderMenu = ( courseSearchUrl, authenticatedUser, exploreCoursesClick, - programsEnabled = false, ) => ({ mainMenu: [ { @@ -18,11 +17,11 @@ const getLearnerHeaderMenu = ( content: formatMessage(messages.course), isActive: true, }, - ...(programsEnabled ? [{ + { type: 'item', href: `${urls.programsUrl()}`, content: formatMessage(messages.program), - }] : []), + }, { type: 'item', href: `${urls.baseAppUrl(courseSearchUrl)}`, diff --git a/src/containers/LearnerDashboardHeader/__snapshots__/index.test.jsx.snap b/src/containers/LearnerDashboardHeader/__snapshots__/index.test.jsx.snap index 34bcdc1f..80d09001 100644 --- a/src/containers/LearnerDashboardHeader/__snapshots__/index.test.jsx.snap +++ b/src/containers/LearnerDashboardHeader/__snapshots__/index.test.jsx.snap @@ -12,6 +12,11 @@ exports[`LearnerDashboardHeader render 1`] = ` "isActive": true, "type": "item", }, + { + "content": "Programs", + "href": "http://localhost:18000/dashboard/programs", + "type": "item", + }, { "content": "Discover New", "href": "http://localhost:18000/course-search-url", diff --git a/src/containers/LearnerDashboardHeader/hooks.js b/src/containers/LearnerDashboardHeader/hooks.js index e3eecf8a..115322c1 100644 --- a/src/containers/LearnerDashboardHeader/hooks.js +++ b/src/containers/LearnerDashboardHeader/hooks.js @@ -5,7 +5,6 @@ import track from 'tracking'; import { StrictDict } from 'utils'; import { linkNames } from 'tracking/constants'; -import { apiHooks } from 'hooks'; import getLearnerHeaderMenu from './LearnerDashboardMenu'; import * as module from './hooks'; @@ -31,9 +30,8 @@ export const findCoursesNavDropdownClicked = (href) => track.findCourses.findCou export const useLearnerDashboardHeaderMenu = ({ courseSearchUrl, authenticatedUser, exploreCoursesClick, }) => { - const { enabled: programsEnabled } = apiHooks.useProgramsConfig(); const { formatMessage } = useIntl(); - return getLearnerHeaderMenu(formatMessage, courseSearchUrl, authenticatedUser, exploreCoursesClick, programsEnabled); + return getLearnerHeaderMenu(formatMessage, courseSearchUrl, authenticatedUser, exploreCoursesClick); }; export const useLearnerDashboardHeaderData = () => { diff --git a/src/containers/LearnerDashboardHeader/hooks.test.js b/src/containers/LearnerDashboardHeader/hooks.test.js index e724c491..c9bac080 100644 --- a/src/containers/LearnerDashboardHeader/hooks.test.js +++ b/src/containers/LearnerDashboardHeader/hooks.test.js @@ -21,11 +21,6 @@ jest.mock('tracking', () => ({ findCoursesClicked: jest.fn(), }, })); -jest.mock('hooks', () => ({ - apiHooks: { - useProgramsConfig: jest.fn(() => ({})), - }, -})); const url = 'http://example.com'; @@ -61,7 +56,7 @@ describe('LearnerDashboardHeader hooks', () => { username: 'test', }; const learnerHomeHeaderMenu = useLearnerDashboardHeaderMenu({ courseSearchUrl, authenticatedUser }); - expect(learnerHomeHeaderMenu.mainMenu.length).toBe(2); + expect(learnerHomeHeaderMenu.mainMenu.length).toBe(3); }); }); diff --git a/src/containers/LearnerDashboardHeader/index.test.jsx b/src/containers/LearnerDashboardHeader/index.test.jsx index 4c455eea..4e552925 100644 --- a/src/containers/LearnerDashboardHeader/index.test.jsx +++ b/src/containers/LearnerDashboardHeader/index.test.jsx @@ -3,7 +3,6 @@ import { shallow } from '@edx/react-unit-test-utils'; import Header from '@edx/frontend-component-header'; import urls from 'data/services/lms/urls'; -import { apiHooks } from 'hooks'; import LearnerDashboardHeader from '.'; import { findCoursesNavClicked } from './hooks'; @@ -13,9 +12,6 @@ jest.mock('hooks', () => ({ courseSearchUrl: '/course-search-url', })), }, - apiHooks: { - useProgramsConfig: jest.fn(() => ({})), - }, })); jest.mock('./hooks', () => ({ ...jest.requireActual('./hooks'), @@ -33,7 +29,7 @@ describe('LearnerDashboardHeader', () => { expect(wrapper.instance.findByType('ConfirmEmailBanner')).toHaveLength(1); expect(wrapper.instance.findByType('MasqueradeBar')).toHaveLength(1); expect(wrapper.instance.findByType(Header)).toHaveLength(1); - wrapper.instance.findByType(Header)[0].props.mainMenuItems[1].onClick(); + wrapper.instance.findByType(Header)[0].props.mainMenuItems[2].onClick(); expect(findCoursesNavClicked).toHaveBeenCalledWith(urls.baseAppUrl('/course-search-url')); expect(wrapper.instance.findByType(Header)[0].props.secondaryMenuItems.length).toBe(0); }); @@ -42,11 +38,5 @@ describe('LearnerDashboardHeader', () => { mergeConfig({ SUPPORT_URL: 'http://localhost:18000/support' }); const wrapper = shallow(); expect(wrapper.instance.findByType(Header)[0].props.secondaryMenuItems.length).toBe(1); - expect(wrapper.instance.findByType(Header)[0].props.mainMenuItems.length).toBe(2); - }); - test('should display Programs link if the service is configured in the backend', () => { - apiHooks.useProgramsConfig.mockReturnValue({ enabled: true }); - const wrapper = shallow(); - expect(wrapper.instance.findByType(Header)[0].props.mainMenuItems.length).toBe(3); }); }); diff --git a/src/data/services/lms/api.js b/src/data/services/lms/api.js index 915b52a9..6f9acd56 100644 --- a/src/data/services/lms/api.js +++ b/src/data/services/lms/api.js @@ -20,8 +20,6 @@ export const initializeList = ({ user } = {}) => get( stringifyUrl(urls.getInitApiUrl(), { [apiKeys.user]: user }), ); -export const getProgramsConfig = () => get(urls.programsConfigUrl()); - export const updateEntitlementEnrollment = ({ uuid, courseId }) => post( urls.entitlementEnrollment(uuid), { [apiKeys.courseRunId]: courseId }, @@ -75,7 +73,6 @@ export const createCreditRequest = ({ providerId, courseId, username }) => post( export default { initializeList, - getProgramsConfig, unenrollFromCourse, updateEmailSettings, updateEntitlementEnrollment, diff --git a/src/data/services/lms/urls.js b/src/data/services/lms/urls.js index 789d614c..30c2bbf1 100644 --- a/src/data/services/lms/urls.js +++ b/src/data/services/lms/urls.js @@ -22,7 +22,6 @@ export const baseAppUrl = (url) => updateUrl(getBaseUrl(), url); export const learningMfeUrl = (url) => updateUrl(getConfig().LEARNING_BASE_URL, url); // static view url -const programsConfigUrl = () => baseAppUrl('/config/programs'); const programsUrl = () => baseAppUrl('/dashboard/programs'); export const creditPurchaseUrl = (courseId) => `${getEcommerceUrl()}/credit/checkout/${courseId}/`; @@ -38,7 +37,6 @@ export default StrictDict({ event, getInitApiUrl, learningMfeUrl, - programsConfigUrl, programsUrl, updateEmailSettings, }); diff --git a/src/hooks/api.js b/src/hooks/api.js index 24a844f8..d64a1185 100644 --- a/src/hooks/api.js +++ b/src/hooks/api.js @@ -1,6 +1,5 @@ import React from 'react'; -import { logError } from '@edx/frontend-platform/logging'; import { AppContext } from '@edx/frontend-platform/react'; import { RequestKeys } from 'data/constants/requests'; @@ -32,25 +31,6 @@ export const useInitializeApp = () => { }); }; -export const useProgramsConfig = () => { - const [config, setConfig] = React.useState({}); - - React.useEffect(() => { - const fetchProgramsConfig = async () => { - try { - const { data } = await api.getProgramsConfig(); - setConfig(data); - } catch (error) { - logError(`Error accessing programs configuration ${error}`); - } - }; - - fetchProgramsConfig(); - }, []); - - return config; -}; - export const useNewEntitlementEnrollment = (cardId) => { const { uuid } = reduxHooks.useCardEntitlementData(cardId); const onSuccess = module.useInitializeApp(); diff --git a/src/hooks/api.test.js b/src/hooks/api.test.js index ab18a6df..cd1a5b6b 100644 --- a/src/hooks/api.test.js +++ b/src/hooks/api.test.js @@ -1,5 +1,4 @@ import React from 'react'; -import { logError } from '@edx/frontend-platform/logging'; import { AppContext } from '@edx/frontend-platform/react'; import { keyStore } from 'utils'; import { RequestKeys } from 'data/constants/requests'; @@ -11,14 +10,9 @@ import * as apiHooks from './api'; const reduxKeys = keyStore(reduxHooks); -jest.mock('@edx/frontend-platform/logging', () => ({ - logError: jest.fn(), -})); - jest.mock('data/services/lms/utils', () => ({ post: jest.fn((...args) => ({ post: args })), })); - jest.mock('data/services/lms/api', () => ({ initializeList: jest.fn(), updateEntitlementEnrollment: jest.fn(), @@ -26,9 +20,7 @@ jest.mock('data/services/lms/api', () => ({ deleteEntitlementEnrollment: jest.fn(), updateEmailSettings: jest.fn(), createCreditRequest: jest.fn(), - getProgramsConfig: jest.fn(), })); - jest.mock('data/redux/hooks', () => ({ useCardCourseRunData: jest.fn(), useCardCreditData: jest.fn(), @@ -118,34 +110,6 @@ describe('api hooks', () => { }); }); - describe('useProgramsConfig', () => { - let mockState; - const setState = jest.fn((newState) => { Object.assign(mockState, newState); }); - beforeEach(() => { - mockState = {}; - React.useState.mockReturnValue([mockState, setState]); - }); - - it('should return the programs configuration when the API call is successful', async () => { - api.getProgramsConfig.mockResolvedValue({ data: { enabled: true } }); - const config = apiHooks.useProgramsConfig(); - const [cb] = React.useEffect.mock.calls[0]; - await cb(); - expect(setState).toHaveBeenCalled(); - expect(config).toEqual({ enabled: true }); - }); - - it('should return an empty object if the api call fails', async () => { - mockState = {}; - api.getProgramsConfig.mockRejectedValue(new Error('error test')); - const config = apiHooks.useProgramsConfig(); - const [cb] = React.useEffect.mock.calls[0]; - await cb(); - expect(config).toEqual({}); - expect(logError).toHaveBeenCalled(); - }); - }); - describe('entitlement enrollment hooks', () => { beforeEach(() => { jest.spyOn(apiHooks, moduleKeys.useInitializeApp).mockReturnValue(initializeApp);