From 94e1483cd061f41f4c797c13ff3fa62d9269a33c Mon Sep 17 00:00:00 2001 From: Diana Olarte Date: Tue, 19 Nov 2024 10:25:17 +1100 Subject: [PATCH] fix: display programs tab only if it is configured --- src/config/index.js | 1 + .../LearnerDashboardHeader/LearnerDashboardMenu.jsx | 4 ++-- .../__snapshots__/index.test.jsx.snap | 5 ----- src/containers/LearnerDashboardHeader/hooks.test.js | 2 +- src/containers/LearnerDashboardHeader/index.test.jsx | 7 ++++++- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/config/index.js b/src/config/index.js index a2e2a566..cdc867e7 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -19,6 +19,7 @@ const configuration = { LOGO_URL: process.env.LOGO_URL, ENABLE_EDX_PERSONAL_DASHBOARD: process.env.ENABLE_EDX_PERSONAL_DASHBOARD === 'true', SEARCH_CATALOG_URL: process.env.SEARCH_CATALOG_URL || null, + ENABLE_PROGRAMS: !!process.env.ENABLE_PROGRAMS, }; const features = {}; diff --git a/src/containers/LearnerDashboardHeader/LearnerDashboardMenu.jsx b/src/containers/LearnerDashboardHeader/LearnerDashboardMenu.jsx index 092bcfe7..165d4866 100644 --- a/src/containers/LearnerDashboardHeader/LearnerDashboardMenu.jsx +++ b/src/containers/LearnerDashboardHeader/LearnerDashboardMenu.jsx @@ -17,11 +17,11 @@ const getLearnerHeaderMenu = ( content: formatMessage(messages.course), isActive: true, }, - { + ...(getConfig().ENABLE_PROGRAMS ? [{ 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 80d09001..34bcdc1f 100644 --- a/src/containers/LearnerDashboardHeader/__snapshots__/index.test.jsx.snap +++ b/src/containers/LearnerDashboardHeader/__snapshots__/index.test.jsx.snap @@ -12,11 +12,6 @@ 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.test.js b/src/containers/LearnerDashboardHeader/hooks.test.js index c9bac080..54b84cf5 100644 --- a/src/containers/LearnerDashboardHeader/hooks.test.js +++ b/src/containers/LearnerDashboardHeader/hooks.test.js @@ -56,7 +56,7 @@ describe('LearnerDashboardHeader hooks', () => { username: 'test', }; const learnerHomeHeaderMenu = useLearnerDashboardHeaderMenu({ courseSearchUrl, authenticatedUser }); - expect(learnerHomeHeaderMenu.mainMenu.length).toBe(3); + expect(learnerHomeHeaderMenu.mainMenu.length).toBe(2); }); }); diff --git a/src/containers/LearnerDashboardHeader/index.test.jsx b/src/containers/LearnerDashboardHeader/index.test.jsx index 4e552925..46384f6d 100644 --- a/src/containers/LearnerDashboardHeader/index.test.jsx +++ b/src/containers/LearnerDashboardHeader/index.test.jsx @@ -29,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[2].onClick(); + wrapper.instance.findByType(Header)[0].props.mainMenuItems[1].onClick(); expect(findCoursesNavClicked).toHaveBeenCalledWith(urls.baseAppUrl('/course-search-url')); expect(wrapper.instance.findByType(Header)[0].props.secondaryMenuItems.length).toBe(0); }); @@ -39,4 +39,9 @@ describe('LearnerDashboardHeader', () => { const wrapper = shallow(); expect(wrapper.instance.findByType(Header)[0].props.secondaryMenuItems.length).toBe(1); }); + test('should display Programs link if the service is configured in the backend', () => { + mergeConfig({ ENABLE_PROGRAMS: true }); + const wrapper = shallow(); + expect(wrapper.instance.findByType(Header)[0].props.mainMenuItems.length).toBe(3); + }); });