From 5562d8a339ece5be280d5a4b84f02fb422b2a888 Mon Sep 17 00:00:00 2001 From: diana-villalvazo-wgu Date: Tue, 13 May 2025 08:23:20 -0700 Subject: [PATCH] chore: Clean up learnerDashboardHeader files (#614) --- .../LearnerDashboardHeader/BrandLogo.jsx | 27 --------------- .../LearnerDashboardHeader/BrandLogo.test.jsx | 28 --------------- .../__snapshots__/BrandLogo.test.jsx.snap | 27 --------------- .../LearnerDashboardHeader/hooks.js | 26 -------------- .../LearnerDashboardHeader/hooks.test.js | 34 ------------------- src/data/redux/requests/reducer.test.js | 11 ++++++ 6 files changed, 11 insertions(+), 142 deletions(-) delete mode 100644 src/containers/LearnerDashboardHeader/BrandLogo.jsx delete mode 100644 src/containers/LearnerDashboardHeader/BrandLogo.test.jsx delete mode 100644 src/containers/LearnerDashboardHeader/__snapshots__/BrandLogo.test.jsx.snap diff --git a/src/containers/LearnerDashboardHeader/BrandLogo.jsx b/src/containers/LearnerDashboardHeader/BrandLogo.jsx deleted file mode 100644 index d9a79af..0000000 --- a/src/containers/LearnerDashboardHeader/BrandLogo.jsx +++ /dev/null @@ -1,27 +0,0 @@ -import React from 'react'; - -import { useIntl } from '@edx/frontend-platform/i18n'; - -import { reduxHooks } from 'hooks'; - -import { getConfig } from '@edx/frontend-platform'; -import messages from './messages'; - -export const BrandLogo = () => { - const { formatMessage } = useIntl(); - const dashboard = reduxHooks.useEnterpriseDashboardData(); - - return ( - - {formatMessage(messages.logoAltText)} - - ); -}; - -BrandLogo.propTypes = {}; - -export default BrandLogo; diff --git a/src/containers/LearnerDashboardHeader/BrandLogo.test.jsx b/src/containers/LearnerDashboardHeader/BrandLogo.test.jsx deleted file mode 100644 index fad6ce3..0000000 --- a/src/containers/LearnerDashboardHeader/BrandLogo.test.jsx +++ /dev/null @@ -1,28 +0,0 @@ -import { shallow } from '@edx/react-unit-test-utils'; - -import { reduxHooks } from 'hooks'; -import BrandLogo from './BrandLogo'; - -jest.mock('hooks', () => ({ - reduxHooks: { - useEnterpriseDashboardData: jest.fn(), - }, -})); - -describe('BrandLogo', () => { - test('dashboard defined', () => { - reduxHooks.useEnterpriseDashboardData.mockReturnValueOnce({ - url: 'url', - }); - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); - expect(wrapper.instance.findByType('a')[0].props.href).toEqual('url'); - }); - - test('dashboard undefined', () => { - reduxHooks.useEnterpriseDashboardData.mockReturnValueOnce(null); - const wrapper = shallow(); - expect(wrapper.snapshot).toMatchSnapshot(); - expect(wrapper.instance.findByType('a')[0].props.href).toEqual('/'); - }); -}); diff --git a/src/containers/LearnerDashboardHeader/__snapshots__/BrandLogo.test.jsx.snap b/src/containers/LearnerDashboardHeader/__snapshots__/BrandLogo.test.jsx.snap deleted file mode 100644 index f069b0a..0000000 --- a/src/containers/LearnerDashboardHeader/__snapshots__/BrandLogo.test.jsx.snap +++ /dev/null @@ -1,27 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`BrandLogo dashboard defined 1`] = ` - - edX, Inc. Dashboard - -`; - -exports[`BrandLogo dashboard undefined 1`] = ` - - edX, Inc. Dashboard - -`; diff --git a/src/containers/LearnerDashboardHeader/hooks.js b/src/containers/LearnerDashboardHeader/hooks.js index 115322c..5367ab3 100644 --- a/src/containers/LearnerDashboardHeader/hooks.js +++ b/src/containers/LearnerDashboardHeader/hooks.js @@ -1,5 +1,4 @@ import React from 'react'; -import { useWindowSize, breakpoints } from '@openedx/paragon'; import { useIntl } from '@edx/frontend-platform/i18n'; import track from 'tracking'; import { StrictDict } from 'utils'; @@ -7,26 +6,14 @@ import { linkNames } from 'tracking/constants'; import getLearnerHeaderMenu from './LearnerDashboardMenu'; -import * as module from './hooks'; - export const state = StrictDict({ isOpen: (val) => React.useState(val), // eslint-disable-line }); -export const useIsCollapsed = () => { - const { width } = useWindowSize(); - const isCollapsed = React.useMemo(() => (width <= breakpoints.large.minWidth), [width]); - return isCollapsed; -}; - export const findCoursesNavClicked = (href) => track.findCourses.findCoursesClicked(href, { linkName: linkNames.learnerHomeNavExplore, }); -export const findCoursesNavDropdownClicked = (href) => track.findCourses.findCoursesClicked(href, { - linkName: linkNames.learnerHomeNavDropdownExplore, -}); - export const useLearnerDashboardHeaderMenu = ({ courseSearchUrl, authenticatedUser, exploreCoursesClick, }) => { @@ -34,20 +21,7 @@ export const useLearnerDashboardHeaderMenu = ({ return getLearnerHeaderMenu(formatMessage, courseSearchUrl, authenticatedUser, exploreCoursesClick); }; -export const useLearnerDashboardHeaderData = () => { - const [isOpen, setIsOpen] = module.state.isOpen(false); - const toggleIsOpen = () => setIsOpen(!isOpen); - - return { - isOpen, - toggleIsOpen, - }; -}; - export default { - useIsCollapsed, findCoursesNavClicked, - findCoursesNavDropdownClicked, - useLearnerDashboardHeaderData, useLearnerDashboardHeaderMenu, }; diff --git a/src/containers/LearnerDashboardHeader/hooks.test.js b/src/containers/LearnerDashboardHeader/hooks.test.js index 54b84cf..a07a8ef 100644 --- a/src/containers/LearnerDashboardHeader/hooks.test.js +++ b/src/containers/LearnerDashboardHeader/hooks.test.js @@ -1,4 +1,3 @@ -import { useWindowSize, breakpoints } from '@openedx/paragon'; import track from 'tracking'; import { linkNames } from 'tracking/constants'; @@ -9,10 +8,7 @@ import * as hooks from './hooks'; const state = new MockUseState(hooks); const { - useIsCollapsed, findCoursesNavClicked, - findCoursesNavDropdownClicked, - useLearnerDashboardHeaderData, useLearnerDashboardHeaderMenu, } = hooks; @@ -29,17 +25,6 @@ describe('LearnerDashboardHeader hooks', () => { state.testGetter(state.keys.isOpen); }); - describe('useIsCollapsed', () => { - test('large screen is not collapsed', () => { - useWindowSize.mockReturnValueOnce({ width: breakpoints.large.minWidth + 1 }); - expect(useIsCollapsed()).toEqual(false); - }); - test('small screen is collapsed', () => { - useWindowSize.mockReturnValueOnce({ width: breakpoints.large.minWidth - 1 }); - expect(useIsCollapsed()).toEqual(true); - }); - }); - describe('findCoursesNavClicked', () => { test('calls tracking with nav link name', () => { findCoursesNavClicked(url); @@ -59,23 +44,4 @@ describe('LearnerDashboardHeader hooks', () => { expect(learnerHomeHeaderMenu.mainMenu.length).toBe(2); }); }); - - describe('findCoursesNavDropdownClicked', () => { - test('calls tracking with dropdown link name', () => { - findCoursesNavDropdownClicked(url); - expect(track.findCourses.findCoursesClicked).toHaveBeenCalledWith(url, { - linkName: linkNames.learnerHomeNavDropdownExplore, - }); - }); - }); - - describe('useLearnerDashboardHeaderData', () => { - test('default state', () => { - state.mock(); - const out = useLearnerDashboardHeaderData(); - state.expectInitializedWith(state.keys.isOpen, false); - out.toggleIsOpen(); - expect(state.values.isOpen).toEqual(true); - }); - }); }); diff --git a/src/data/redux/requests/reducer.test.js b/src/data/redux/requests/reducer.test.js index 38784bd..8eb39ea 100644 --- a/src/data/redux/requests/reducer.test.js +++ b/src/data/redux/requests/reducer.test.js @@ -47,5 +47,16 @@ describe('requests reducer', () => { }); }); }); + describe('clearRequest', () => { + it('cleanup status and error', () => { + expect(reducer( + testingState, + actions.clearRequest({ requestKey: testKey, error: testValue }), + )).toEqual({ + ...testingState, + [testKey]: {}, + }); + }); + }); }); });