From e43a49b43136faf0fed4bded274a4ff606e56e4c Mon Sep 17 00:00:00 2001 From: Kris Hatcher Date: Mon, 5 Jun 2023 11:50:40 -0400 Subject: [PATCH] feat: add career link to user dropdown (#152) Co-authored-by: leangseu-edx <83240113+leangseu-edx@users.noreply.github.com> --- .env | 1 + .env.development | 1 + .env.test | 1 + src/App.jsx | 4 +- src/App.test.jsx | 6 +- src/__snapshots__/App.test.jsx.snap | 6 +- src/config/index.js | 1 + .../AuthenticatedUserDropdown.jsx | 85 -------- .../AuthenticatedUserDropdown.test.jsx | 63 ------ .../BrandLogo.jsx | 0 .../BrandLogo.test.jsx | 0 .../CollapsedHeader/CollapseMenuBody.jsx | 12 +- .../CollapsedHeader/CollapseMenuBody.test.jsx | 0 .../CollapseMenuBody.test.jsx.snap | 0 .../__snapshots__/index.test.jsx.snap | 0 .../CollapsedHeader/index.jsx | 4 +- .../CollapsedHeader/index.test.jsx | 6 +- .../AuthenticatedUserDropdown.jsx | 10 +- .../AuthenticatedUserDropdown.test.jsx | 1 + .../AuthenticatedUserDropdown.test.jsx.snap | 11 ++ .../__snapshots__/index.test.jsx.snap | 0 .../ExpandedHeader/index.jsx | 0 .../ExpandedHeader/index.test.jsx | 0 .../LearnerDashboardHeader/GreetingBanner.jsx | 63 ------ .../GreetingBanner.test.jsx | 29 --- .../AuthenticatedUserDropdown.test.jsx.snap | 143 -------------- .../__snapshots__/BrandLogo.test.jsx.snap | 0 .../GreetingBanner.test.jsx.snap | 181 ------------------ .../__snapshots__/index.test.jsx.snap | 93 +-------- .../LearnerDashboardHeader/hooks.js | 20 +- .../LearnerDashboardHeader/hooks.test.js | 32 +++- .../LearnerDashboardHeader/index.jsx | 96 ++-------- .../LearnerDashboardHeader/index.scss | 46 ++++- .../LearnerDashboardHeader/index.test.jsx | 61 +----- .../LearnerDashboardHeader/messages.js | 75 ++++---- .../__snapshots__/index.test.jsx.snap | 10 - .../LearnerDashboardHeaderVariant/hooks.js | 42 ---- .../hooks.test.js | 69 ------- .../LearnerDashboardHeaderVariant/index.jsx | 22 --- .../LearnerDashboardHeaderVariant/index.scss | 38 ---- .../index.test.jsx | 18 -- .../LearnerDashboardHeaderVariant/messages.js | 71 ------- 42 files changed, 200 insertions(+), 1121 deletions(-) delete mode 100644 src/containers/LearnerDashboardHeader/AuthenticatedUserDropdown.jsx delete mode 100644 src/containers/LearnerDashboardHeader/AuthenticatedUserDropdown.test.jsx rename src/containers/{LearnerDashboardHeaderVariant => LearnerDashboardHeader}/BrandLogo.jsx (100%) rename src/containers/{LearnerDashboardHeaderVariant => LearnerDashboardHeader}/BrandLogo.test.jsx (100%) rename src/containers/{LearnerDashboardHeaderVariant => LearnerDashboardHeader}/CollapsedHeader/CollapseMenuBody.jsx (86%) rename src/containers/{LearnerDashboardHeaderVariant => LearnerDashboardHeader}/CollapsedHeader/CollapseMenuBody.test.jsx (100%) rename src/containers/{LearnerDashboardHeaderVariant => LearnerDashboardHeader}/CollapsedHeader/__snapshots__/CollapseMenuBody.test.jsx.snap (100%) rename src/containers/{LearnerDashboardHeaderVariant => LearnerDashboardHeader}/CollapsedHeader/__snapshots__/index.test.jsx.snap (100%) rename src/containers/{LearnerDashboardHeaderVariant => LearnerDashboardHeader}/CollapsedHeader/index.jsx (88%) rename src/containers/{LearnerDashboardHeaderVariant => LearnerDashboardHeader}/CollapsedHeader/index.test.jsx (82%) rename src/containers/{LearnerDashboardHeaderVariant => LearnerDashboardHeader}/ExpandedHeader/AuthenticatedUserDropdown.jsx (84%) rename src/containers/{LearnerDashboardHeaderVariant => LearnerDashboardHeader}/ExpandedHeader/AuthenticatedUserDropdown.test.jsx (97%) rename src/containers/{LearnerDashboardHeaderVariant => LearnerDashboardHeader}/ExpandedHeader/__snapshots__/AuthenticatedUserDropdown.test.jsx.snap (92%) rename src/containers/{LearnerDashboardHeaderVariant => LearnerDashboardHeader}/ExpandedHeader/__snapshots__/index.test.jsx.snap (100%) rename src/containers/{LearnerDashboardHeaderVariant => LearnerDashboardHeader}/ExpandedHeader/index.jsx (100%) rename src/containers/{LearnerDashboardHeaderVariant => LearnerDashboardHeader}/ExpandedHeader/index.test.jsx (100%) delete mode 100644 src/containers/LearnerDashboardHeader/GreetingBanner.jsx delete mode 100644 src/containers/LearnerDashboardHeader/GreetingBanner.test.jsx delete mode 100644 src/containers/LearnerDashboardHeader/__snapshots__/AuthenticatedUserDropdown.test.jsx.snap rename src/containers/{LearnerDashboardHeaderVariant => LearnerDashboardHeader}/__snapshots__/BrandLogo.test.jsx.snap (100%) delete mode 100644 src/containers/LearnerDashboardHeader/__snapshots__/GreetingBanner.test.jsx.snap delete mode 100644 src/containers/LearnerDashboardHeaderVariant/__snapshots__/index.test.jsx.snap delete mode 100644 src/containers/LearnerDashboardHeaderVariant/hooks.js delete mode 100644 src/containers/LearnerDashboardHeaderVariant/hooks.test.js delete mode 100644 src/containers/LearnerDashboardHeaderVariant/index.jsx delete mode 100644 src/containers/LearnerDashboardHeaderVariant/index.scss delete mode 100644 src/containers/LearnerDashboardHeaderVariant/index.test.jsx delete mode 100644 src/containers/LearnerDashboardHeaderVariant/messages.js diff --git a/.env b/.env index f16685a..603b66a 100644 --- a/.env +++ b/.env @@ -39,3 +39,4 @@ HOTJAR_DEBUG='' ACCOUNT_SETTINGS_URL='' ACCOUNT_PROFILE_URL='' ENABLE_NOTICES='' +CAREER_LINK_URL='' diff --git a/.env.development b/.env.development index 9b319ba..83442cb 100644 --- a/.env.development +++ b/.env.development @@ -46,3 +46,4 @@ HOTJAR_DEBUG='' ACCOUNT_SETTINGS_URL='http://localhost:1997' ACCOUNT_PROFILE_URL='http://localhost:1995' ENABLE_NOTICES='' +CAREER_LINK_URL='' diff --git a/.env.test b/.env.test index 9dd6516..9314c0a 100644 --- a/.env.test +++ b/.env.test @@ -45,3 +45,4 @@ HOTJAR_DEBUG='' ACCOUNT_SETTINGS_URL='http://account-settings-url.test' ACCOUNT_PROFILE_URL='http://account-profile-url.test' ENABLE_NOTICES='' +CAREER_LINK_URL='' diff --git a/src/App.jsx b/src/App.jsx index a6ce7d7..5adba84 100755 --- a/src/App.jsx +++ b/src/App.jsx @@ -23,7 +23,7 @@ import ZendeskFab from 'components/ZendeskFab'; import track from 'tracking'; import fakeData from 'data/services/lms/fakeData/courses'; -import LearnerDashboardHeaderVariant from './containers/LearnerDashboardHeaderVariant'; +import LearnerDashboardHeader from './containers/LearnerDashboardHeader'; import messages from './messages'; @@ -77,7 +77,7 @@ export const App = () => { {formatMessage(messages.pageTitle)}
- +
{hasNetworkFailure ? ( diff --git a/src/App.test.jsx b/src/App.test.jsx index 6734293..bc57ea7 100644 --- a/src/App.test.jsx +++ b/src/App.test.jsx @@ -12,14 +12,14 @@ import { Alert } from '@edx/paragon'; import { RequestKeys } from 'data/constants/requests'; import { reduxHooks } from 'hooks'; import Dashboard from 'containers/Dashboard'; -import LearnerDashboardHeaderVariant from 'containers/LearnerDashboardHeaderVariant'; +import LearnerDashboardHeader from 'containers/LearnerDashboardHeader'; import { App } from './App'; import messages from './messages'; jest.mock('@edx/frontend-component-footer', () => 'Footer'); jest.mock('containers/Dashboard', () => 'Dashboard'); -jest.mock('containers/LearnerDashboardHeaderVariant', () => 'LearnerDashboardHeaderVariant'); +jest.mock('containers/LearnerDashboardHeader', () => 'LearnerDashboardHeader'); jest.mock('components/ZendeskFab', () => 'ZendeskFab'); jest.mock('data/redux', () => ({ selectors: 'redux.selectors', @@ -54,7 +54,7 @@ describe('App router component', () => { expect(el.find(Helmet).find('title').text()).toEqual(useIntl().formatMessage(messages.pageTitle)); }); it('displays learner dashboard header', () => { - expect(el.find(LearnerDashboardHeaderVariant).length).toEqual(1); + expect(el.find(LearnerDashboardHeader).length).toEqual(1); }); it('wraps the page in a browser router', () => { expect(el.find(Router)).toMatchObject(el); diff --git a/src/__snapshots__/App.test.jsx.snap b/src/__snapshots__/App.test.jsx.snap index 443fdba..d819557 100644 --- a/src/__snapshots__/App.test.jsx.snap +++ b/src/__snapshots__/App.test.jsx.snap @@ -11,7 +11,7 @@ exports[`App router component component initialize failure snapshot 1`] = `
- +
- +
@@ -63,7 +63,7 @@ exports[`App router component component refresh failure snapshot 1`] = `
- +
{ - const { formatMessage } = useIntl(); - const { authenticatedUser } = React.useContext(AppContext); - const dashboard = reduxHooks.useEnterpriseDashboardData(); - const { courseSearchUrl } = reduxHooks.usePlatformSettingsData(); - const isCollapsed = useIsCollapsed(); - const { profileImage } = authenticatedUser; - - return ( - - - - {username} - - - - SWITCH DASHBOARD - Personal - {!!dashboard && ( - - {dashboard.label} {formatMessage(messages.dashboard)} - - )} - - - {formatMessage(messages.profile)} - - {isCollapsed && ( - <> - - {formatMessage(messages.viewPrograms)} - - - {formatMessage(messages.exploreCourses)} - - - )} - - {formatMessage(messages.account)} - - {getConfig().ORDER_HISTORY_URL && ( - - {formatMessage(messages.orderHistory)} - - )} - - {formatMessage(messages.help)} - - - - {formatMessage(messages.signOut)} - - - - ); -}; - -AuthenticatedUserDropdown.propTypes = { - username: PropTypes.string.isRequired, -}; - -export default AuthenticatedUserDropdown; diff --git a/src/containers/LearnerDashboardHeader/AuthenticatedUserDropdown.test.jsx b/src/containers/LearnerDashboardHeader/AuthenticatedUserDropdown.test.jsx deleted file mode 100644 index 9343b0a..0000000 --- a/src/containers/LearnerDashboardHeader/AuthenticatedUserDropdown.test.jsx +++ /dev/null @@ -1,63 +0,0 @@ -import { shallow } from 'enzyme'; -import { getConfig } from '@edx/frontend-platform'; - -import { reduxHooks } from 'hooks'; -import { AuthenticatedUserDropdown } from './AuthenticatedUserDropdown'; -import { useIsCollapsed } from './hooks'; - -jest.mock('@edx/frontend-platform', () => ({ - getConfig: jest.fn(), -})); -jest.mock('@edx/frontend-platform/react', () => ({ - AppContext: { - authenticatedUser: { - profileImage: 'profileImage', - }, - }, -})); -jest.mock('hooks', () => ({ - reduxHooks: { - useEnterpriseDashboardData: jest.fn(), - usePlatformSettingsData: jest.fn(() => ({ - courseSearchUrl: 'test-course-search-url', - })), - }, -})); -jest.mock('containers/LearnerDashboardHeader/hooks', () => ({ - useIsCollapsed: jest.fn(), - findCoursesNavDropdownClicked: (href) => jest.fn().mockName(`findCoursesNavDropdownClicked('${href}')`), -})); - -const config = { - ACCOUNT_PROFILE_URL: 'http://account-profile-url.test', - ACCOUNT_SETTINGS_URL: 'http://account-settings-url.test', - LOGOUT_URL: 'http://logout-url.test', - ORDER_HISTORY_URL: 'http://order-history-url.test', - SUPPORT_URL: 'http://localhost:18000/support', -}; -getConfig.mockReturnValue(config); - -describe('AuthenticatedUserDropdown', () => { - const props = { - username: 'username', - }; - const defaultDashboardData = { - label: 'label', - url: 'url', - }; - - describe('snapshots', () => { - test('with enterprise dashboard', () => { - reduxHooks.useEnterpriseDashboardData.mockReturnValueOnce(defaultDashboardData); - useIsCollapsed.mockReturnValueOnce(true); - const wrapper = shallow(); - expect(wrapper).toMatchSnapshot(); - }); - test('without enterprise dashboard and expanded', () => { - reduxHooks.useEnterpriseDashboardData.mockReturnValueOnce(null); - useIsCollapsed.mockReturnValueOnce(false); - const wrapper = shallow(); - expect(wrapper).toMatchSnapshot(); - }); - }); -}); diff --git a/src/containers/LearnerDashboardHeaderVariant/BrandLogo.jsx b/src/containers/LearnerDashboardHeader/BrandLogo.jsx similarity index 100% rename from src/containers/LearnerDashboardHeaderVariant/BrandLogo.jsx rename to src/containers/LearnerDashboardHeader/BrandLogo.jsx diff --git a/src/containers/LearnerDashboardHeaderVariant/BrandLogo.test.jsx b/src/containers/LearnerDashboardHeader/BrandLogo.test.jsx similarity index 100% rename from src/containers/LearnerDashboardHeaderVariant/BrandLogo.test.jsx rename to src/containers/LearnerDashboardHeader/BrandLogo.test.jsx diff --git a/src/containers/LearnerDashboardHeaderVariant/CollapsedHeader/CollapseMenuBody.jsx b/src/containers/LearnerDashboardHeader/CollapsedHeader/CollapseMenuBody.jsx similarity index 86% rename from src/containers/LearnerDashboardHeaderVariant/CollapsedHeader/CollapseMenuBody.jsx rename to src/containers/LearnerDashboardHeader/CollapsedHeader/CollapseMenuBody.jsx index 557e279..c2982d4 100644 --- a/src/containers/LearnerDashboardHeaderVariant/CollapsedHeader/CollapseMenuBody.jsx +++ b/src/containers/LearnerDashboardHeader/CollapsedHeader/CollapseMenuBody.jsx @@ -5,7 +5,7 @@ import { getConfig } from '@edx/frontend-platform'; import { useIntl } from '@edx/frontend-platform/i18n'; import { AppContext } from '@edx/frontend-platform/react'; -import { Button } from '@edx/paragon'; +import { Button, Badge } from '@edx/paragon'; import urls from 'data/services/lms/urls'; import { reduxHooks } from 'hooks'; @@ -45,11 +45,19 @@ export const CollapseMenuBody = ({ isOpen }) => { {authenticatedUser && ( <> - {dashboard && ( + {!!dashboard && ( )} + {!dashboard && getConfig().CAREER_LINK_URL && ( + + )} -
- - -
- - -
+ + `; diff --git a/src/containers/LearnerDashboardHeader/hooks.js b/src/containers/LearnerDashboardHeader/hooks.js index 3e683fd..7457d76 100644 --- a/src/containers/LearnerDashboardHeader/hooks.js +++ b/src/containers/LearnerDashboardHeader/hooks.js @@ -1,11 +1,18 @@ import React from 'react'; import { useWindowSize, breakpoints } from '@edx/paragon'; import track from 'tracking'; +import { StrictDict } from 'utils'; import { linkNames } from 'tracking/constants'; +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.maxWidth), [width]); + const isCollapsed = React.useMemo(() => (width <= breakpoints.large.minWidth), [width]); return isCollapsed; }; @@ -17,8 +24,19 @@ export const findCoursesNavDropdownClicked = (href) => track.findCourses.findCou linkName: linkNames.learnerHomeNavDropdownExplore, }); +export const useLearnerDashboardHeaderData = () => { + const [isOpen, setIsOpen] = module.state.isOpen(false); + const toggleIsOpen = () => setIsOpen(!isOpen); + + return { + isOpen, + toggleIsOpen, + }; +}; + export default { useIsCollapsed, findCoursesNavClicked, findCoursesNavDropdownClicked, + useLearnerDashboardHeaderData, }; diff --git a/src/containers/LearnerDashboardHeader/hooks.test.js b/src/containers/LearnerDashboardHeader/hooks.test.js index 79ea527..a039a58 100644 --- a/src/containers/LearnerDashboardHeader/hooks.test.js +++ b/src/containers/LearnerDashboardHeader/hooks.test.js @@ -1,7 +1,19 @@ import { useWindowSize, breakpoints } from '@edx/paragon'; import track from 'tracking'; import { linkNames } from 'tracking/constants'; -import { useIsCollapsed, findCoursesNavClicked, findCoursesNavDropdownClicked } from './hooks'; + +import { MockUseState } from 'testUtils'; + +import * as hooks from './hooks'; + +const state = new MockUseState(hooks); + +const { + useIsCollapsed, + findCoursesNavClicked, + findCoursesNavDropdownClicked, + useLearnerDashboardHeaderData, +} = hooks; jest.mock('tracking', () => ({ findCourses: { @@ -12,13 +24,17 @@ jest.mock('tracking', () => ({ const url = 'http://example.com'; describe('LearnerDashboardHeader hooks', () => { + describe('state values', () => { + state.testGetter(state.keys.isOpen); + }); + describe('useIsCollapsed', () => { test('large screen is not collapsed', () => { - useWindowSize.mockReturnValueOnce({ width: breakpoints.large.maxWidth + 1 }); + useWindowSize.mockReturnValueOnce({ width: breakpoints.large.minWidth + 1 }); expect(useIsCollapsed()).toEqual(false); }); test('small screen is collapsed', () => { - useWindowSize.mockReturnValueOnce({ width: breakpoints.large.maxWidth - 1 }); + useWindowSize.mockReturnValueOnce({ width: breakpoints.large.minWidth - 1 }); expect(useIsCollapsed()).toEqual(true); }); }); @@ -40,4 +56,14 @@ describe('LearnerDashboardHeader hooks', () => { }); }); }); + + 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/containers/LearnerDashboardHeader/index.jsx b/src/containers/LearnerDashboardHeader/index.jsx index 7cebb5c..dfa8dbf 100644 --- a/src/containers/LearnerDashboardHeader/index.jsx +++ b/src/containers/LearnerDashboardHeader/index.jsx @@ -1,92 +1,22 @@ -import React, { useContext } from 'react'; +import React from 'react'; -import { useIntl } from '@edx/frontend-platform/i18n'; -import { AppContext } from '@edx/frontend-platform/react'; -import { Program, Search } from '@edx/paragon/icons'; -import { - Button, Image, IconButton, Icon, -} from '@edx/paragon'; - -import topBanner from 'assets/top_stripe.svg'; import MasqueradeBar from 'containers/MasqueradeBar'; -import urls from 'data/services/lms/urls'; -import { reduxHooks } from 'hooks'; - -import AuthenticatedUserDropdown from './AuthenticatedUserDropdown'; -import GreetingBanner from './GreetingBanner'; import ConfirmEmailBanner from './ConfirmEmailBanner'; -import { useIsCollapsed, findCoursesNavClicked } from './hooks'; -import messages from './messages'; +import CollapsedHeader from './CollapsedHeader'; +import ExpandedHeader from './ExpandedHeader'; + import './index.scss'; -export const UserMenu = () => { - const { authenticatedUser } = useContext(AppContext); - return authenticatedUser ? () : null; -}; +export const LearnerDashboardHeader = () => ( + <> + + + + + +); -export const LearnerDashboardHeader = () => { - const { formatMessage } = useIntl(); - const isCollapsed = useIsCollapsed(); - const { courseSearchUrl } = reduxHooks.usePlatformSettingsData(); - - const exploreCoursesClick = findCoursesNavClicked(courseSearchUrl); - - return ( - <> - -
- {!(isCollapsed) && ( - - )} -
-
- {(!isCollapsed) && ( - - )} -
- {isCollapsed && } -
- {isCollapsed ? ( -
- - -
- ) : ( - <> - - - - )} -
-
- {!isCollapsed && } -
- - - ); -}; - -LearnerDashboardHeader.propTypes = { -}; +LearnerDashboardHeader.propTypes = {}; export default LearnerDashboardHeader; diff --git a/src/containers/LearnerDashboardHeader/index.scss b/src/containers/LearnerDashboardHeader/index.scss index a2210db..d8bd8da 100644 --- a/src/containers/LearnerDashboardHeader/index.scss +++ b/src/containers/LearnerDashboardHeader/index.scss @@ -1,12 +1,38 @@ -.greetings-slash-container-small { - height: 4px; - width: 40px; - transform-origin: center; - transform: rotate(-70deg); +.dropdown-menu-collapse { + width: 100vw; + position: absolute; + left: 0; } -.greetings-slash-container-large { - height: 8px; - width: 120px; - transform-origin: center; - transform: rotate(-70deg); + +.learner-variant-header { + a { + // needed to make the link not resize the header + border-bottom: 2px solid transparent; + } + .course-link { + border-bottom: 2px solid !important; + } + + .course-link:hover { + border-bottom: inherit !important; + } +} + +.nav-small-menu { + > * { + justify-content: flex-start !important; + + border-radius: 0 !important; + border-top: 1px solid #ddd !important; + + &::after { + content: '\00BB'; + padding-left: 10px; + } + } +} + +.logo { + // copy from legacy dashboard + height: 40px; } diff --git a/src/containers/LearnerDashboardHeader/index.test.jsx b/src/containers/LearnerDashboardHeader/index.test.jsx index ca2ec40..cbaf555 100644 --- a/src/containers/LearnerDashboardHeader/index.test.jsx +++ b/src/containers/LearnerDashboardHeader/index.test.jsx @@ -1,59 +1,18 @@ import { shallow } from 'enzyme'; -import { AppContext } from '@edx/frontend-platform/react'; +import LearnerDashboardHeader from '.'; -import LearnerDashboardHeader, { UserMenu } from '.'; - -import { useIsCollapsed } from './hooks'; - -jest.mock('@edx/frontend-platform/react', () => ({ - AppContext: { - authenticatedUser: { - username: 'test-username', - }, - }, -})); -jest.mock('./hooks', () => ({ - useIsCollapsed: jest.fn(), - findCoursesNavClicked: (href) => jest.fn().mockName(`findCoursesNavClicked('${href}')`), -})); -jest.mock('hooks', () => ({ - reduxHooks: { - usePlatformSettingsData: jest.fn(() => ({ - courseSearchUrl: 'test-course-search-url', - })), - }, -})); jest.mock('containers/MasqueradeBar', () => 'MasqueradeBar'); - +jest.mock('./CollapsedHeader', () => 'CollapsedHeader'); jest.mock('./ConfirmEmailBanner', () => 'ConfirmEmailBanner'); -jest.mock('./AuthenticatedUserDropdown', () => 'AuthenticatedUserDropdown'); -jest.mock('./GreetingBanner', () => 'GreetingBanner'); +jest.mock('./ExpandedHeader', () => 'ExpandedHeader'); describe('LearnerDashboardHeader', () => { - describe('snapshots', () => { - test('with collapsed', () => { - useIsCollapsed.mockReturnValueOnce(true); - const wrapper = shallow(); - expect(wrapper).toMatchSnapshot(); - }); - test('without collapsed', () => { - useIsCollapsed.mockReturnValueOnce(false); - const wrapper = shallow(); - expect(wrapper).toMatchSnapshot(); - }); - }); - - describe('UserMenu', () => { - describe('snapshots', () => { - test('with authenticated user', () => { - const wrapper = shallow(); - expect(wrapper).toMatchSnapshot(); - }); - test('without authenticated user', () => { - AppContext.authenticatedUser = null; - const wrapper = shallow(); - expect(wrapper).toMatchSnapshot(); - }); - }); + test('render', () => { + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + expect(wrapper.find('ConfirmEmailBanner')).toHaveLength(1); + expect(wrapper.find('MasqueradeBar')).toHaveLength(1); + expect(wrapper.find('CollapsedHeader')).toHaveLength(1); + expect(wrapper.find('ExpandedHeader')).toHaveLength(1); }); }); diff --git a/src/containers/LearnerDashboardHeader/messages.js b/src/containers/LearnerDashboardHeader/messages.js index 01e02a9..8ac4e04 100644 --- a/src/containers/LearnerDashboardHeader/messages.js +++ b/src/containers/LearnerDashboardHeader/messages.js @@ -2,70 +2,79 @@ import { defineMessages } from '@edx/frontend-platform/i18n'; const messages = defineMessages({ dashboard: { - id: 'leanerDashboard.menu.dashboard.label', + id: 'learnerVariantDashboard.menu.dashboard.label', defaultMessage: 'Dashboard', description: 'The text for the user menu Dashboard navigation link.', }, help: { - id: 'leanerDashboard.help.label', + id: 'learnerVariantDashboard.help.label', defaultMessage: 'Help', description: 'The text for the link to the Help Center', }, profile: { - id: 'leanerDashboard.menu.profile.label', + id: 'learnerVariantDashboard.menu.profile.label', defaultMessage: 'Profile', description: 'The text for the user menu Profile navigation link.', }, viewPrograms: { - id: 'leanerDashboard.menu.viewPrograms.label', + id: 'learnerVariantDashboard.menu.viewPrograms.label', defaultMessage: 'View Programs', description: 'The text for the user menu View Programs navigation link.', }, account: { - id: 'leanerDashboard.menu.account.label', + id: 'learnerVariantDashboard.menu.account.label', defaultMessage: 'Account', description: 'The text for the user menu Account navigation link.', }, orderHistory: { - id: 'leanerDashboard.menu.orderHistory.label', + id: 'learnerVariantDashboard.menu.orderHistory.label', defaultMessage: 'Order History', description: 'The text for the user menu Order History navigation link.', }, signOut: { - id: 'leanerDashboard.menu.signOut.label', + id: 'learnerVariantDashboard.menu.signOut.label', defaultMessage: 'Sign Out', description: 'The label for the user menu Sign Out action.', }, - - goodMorning: { - id: 'greeting.morning', - defaultMessage: 'Good Morning!', - description: 'Good Morning', + course: { + id: 'learnerVariantDashboard.course', + defaultMessage: 'Courses', + description: 'Header link for switching to dashboard page.', }, - goodAfternoon: { - id: 'greeting.afternoon', - defaultMessage: 'Good Afternoon!', - description: 'Good Afternoon', - }, - goodEvening: { - id: 'greeting.evening', - defaultMessage: 'Good Evening!', - description: 'Good Evening', - }, - switchToProgram: { - id: 'leanerDashboard.switchToProgram', - defaultMessage: 'Switch to Programs', + program: { + id: 'learnerVariantDashboard.program', + defaultMessage: 'Programs', description: 'Header link for switching to program page.', }, - exploreCourses: { - id: 'leanerDashboard.exploreCourses', - defaultMessage: 'Explore courses', - description: 'Header link for switching to course page.', + discoverNew: { + id: 'learnerVariantDashboard.discoverNew', + defaultMessage: 'Discover New', + description: 'Header link for switching to discover page.', }, - courseSearchAlt: { - id: 'leanerDashboard.courseSearchAlt', - defaultMessage: 'Course search', - description: 'Alt-text for course search icon button', + logoAltText: { + id: 'learnerVariantDashboard.logoAltText', + defaultMessage: 'edX, Inc. Dashboard', + description: 'Alt text for the edX logo.', + }, + collapseMenuOpenAltText: { + id: 'learnerVariantDashboard.collapseMenuOpenAltText', + defaultMessage: 'Menu', + description: 'Alt text for the collapse menu icon when the menu is open.', + }, + collapseMenuClosedAltText: { + id: 'learnerVariantDashboard.collapseMenuClosedAltText', + defaultMessage: 'Close', + description: 'Alt text for the collapse menu icon when the menu is closed.', + }, + career: { + id: 'leanerDashboard.menu.career.label', + defaultMessage: 'Career', + description: 'The text for the user menu Career navigation link.', + }, + newAlert: { + id: 'header.menu.new.label', + defaultMessage: 'New', + description: 'The text announcing that an item in the user menu is New', }, }); diff --git a/src/containers/LearnerDashboardHeaderVariant/__snapshots__/index.test.jsx.snap b/src/containers/LearnerDashboardHeaderVariant/__snapshots__/index.test.jsx.snap deleted file mode 100644 index 3d86b7b..0000000 --- a/src/containers/LearnerDashboardHeaderVariant/__snapshots__/index.test.jsx.snap +++ /dev/null @@ -1,10 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`LearnerDashboardHeaderVariant render 1`] = ` - - - - - - -`; diff --git a/src/containers/LearnerDashboardHeaderVariant/hooks.js b/src/containers/LearnerDashboardHeaderVariant/hooks.js deleted file mode 100644 index a3f8592..0000000 --- a/src/containers/LearnerDashboardHeaderVariant/hooks.js +++ /dev/null @@ -1,42 +0,0 @@ -import React from 'react'; -import { useWindowSize, breakpoints } from '@edx/paragon'; -import track from 'tracking'; -import { StrictDict } from 'utils'; -import { linkNames } from 'tracking/constants'; - -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 useLearnerDashboardHeaderVariantData = () => { - const [isOpen, setIsOpen] = module.state.isOpen(false); - const toggleIsOpen = () => setIsOpen(!isOpen); - - return { - isOpen, - toggleIsOpen, - }; -}; - -export default { - useIsCollapsed, - findCoursesNavClicked, - findCoursesNavDropdownClicked, - useLearnerDashboardHeaderVariantData, -}; diff --git a/src/containers/LearnerDashboardHeaderVariant/hooks.test.js b/src/containers/LearnerDashboardHeaderVariant/hooks.test.js deleted file mode 100644 index a426dce..0000000 --- a/src/containers/LearnerDashboardHeaderVariant/hooks.test.js +++ /dev/null @@ -1,69 +0,0 @@ -import { useWindowSize, breakpoints } from '@edx/paragon'; -import track from 'tracking'; -import { linkNames } from 'tracking/constants'; - -import { MockUseState } from 'testUtils'; - -import * as hooks from './hooks'; - -const state = new MockUseState(hooks); - -const { - useIsCollapsed, - findCoursesNavClicked, - findCoursesNavDropdownClicked, - useLearnerDashboardHeaderVariantData, -} = hooks; - -jest.mock('tracking', () => ({ - findCourses: { - findCoursesClicked: jest.fn(), - }, -})); - -const url = 'http://example.com'; - -describe('LearnerDashboardHeaderVariant hooks', () => { - describe('state values', () => { - 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); - expect(track.findCourses.findCoursesClicked).toHaveBeenCalledWith(url, { - linkName: linkNames.learnerHomeNavExplore, - }); - }); - }); - - describe('findCoursesNavDropdownClicked', () => { - test('calls tracking with dropdown link name', () => { - findCoursesNavDropdownClicked(url); - expect(track.findCourses.findCoursesClicked).toHaveBeenCalledWith(url, { - linkName: linkNames.learnerHomeNavDropdownExplore, - }); - }); - }); - - describe('useLearnerDashboardHeaderVariantData', () => { - test('default state', () => { - state.mock(); - const out = useLearnerDashboardHeaderVariantData(); - state.expectInitializedWith(state.keys.isOpen, false); - out.toggleIsOpen(); - expect(state.values.isOpen).toEqual(true); - }); - }); -}); diff --git a/src/containers/LearnerDashboardHeaderVariant/index.jsx b/src/containers/LearnerDashboardHeaderVariant/index.jsx deleted file mode 100644 index b8ed23e..0000000 --- a/src/containers/LearnerDashboardHeaderVariant/index.jsx +++ /dev/null @@ -1,22 +0,0 @@ -import React from 'react'; - -import MasqueradeBar from 'containers/MasqueradeBar'; -import ConfirmEmailBanner from 'containers/LearnerDashboardHeader/ConfirmEmailBanner'; - -import CollapsedHeader from './CollapsedHeader'; -import ExpandedHeader from './ExpandedHeader'; - -import './index.scss'; - -export const LearnerDashboardHeaderVariant = () => ( - <> - - - - - -); - -LearnerDashboardHeaderVariant.propTypes = {}; - -export default LearnerDashboardHeaderVariant; diff --git a/src/containers/LearnerDashboardHeaderVariant/index.scss b/src/containers/LearnerDashboardHeaderVariant/index.scss deleted file mode 100644 index d8bd8da..0000000 --- a/src/containers/LearnerDashboardHeaderVariant/index.scss +++ /dev/null @@ -1,38 +0,0 @@ -.dropdown-menu-collapse { - width: 100vw; - position: absolute; - left: 0; -} - -.learner-variant-header { - a { - // needed to make the link not resize the header - border-bottom: 2px solid transparent; - } - .course-link { - border-bottom: 2px solid !important; - } - - .course-link:hover { - border-bottom: inherit !important; - } -} - -.nav-small-menu { - > * { - justify-content: flex-start !important; - - border-radius: 0 !important; - border-top: 1px solid #ddd !important; - - &::after { - content: '\00BB'; - padding-left: 10px; - } - } -} - -.logo { - // copy from legacy dashboard - height: 40px; -} diff --git a/src/containers/LearnerDashboardHeaderVariant/index.test.jsx b/src/containers/LearnerDashboardHeaderVariant/index.test.jsx deleted file mode 100644 index ff97e3b..0000000 --- a/src/containers/LearnerDashboardHeaderVariant/index.test.jsx +++ /dev/null @@ -1,18 +0,0 @@ -import { shallow } from 'enzyme'; -import LearnerDashboardHeaderVariant from '.'; - -jest.mock('containers/LearnerDashboardHeader/ConfirmEmailBanner', () => 'ConfirmEmailBanner'); -jest.mock('containers/MasqueradeBar', () => 'MasqueradeBar'); -jest.mock('./CollapsedHeader', () => 'CollapsedHeader'); -jest.mock('./ExpandedHeader', () => 'ExpandedHeader'); - -describe('LearnerDashboardHeaderVariant', () => { - test('render', () => { - const wrapper = shallow(); - expect(wrapper).toMatchSnapshot(); - expect(wrapper.find('ConfirmEmailBanner')).toHaveLength(1); - expect(wrapper.find('MasqueradeBar')).toHaveLength(1); - expect(wrapper.find('CollapsedHeader')).toHaveLength(1); - expect(wrapper.find('ExpandedHeader')).toHaveLength(1); - }); -}); diff --git a/src/containers/LearnerDashboardHeaderVariant/messages.js b/src/containers/LearnerDashboardHeaderVariant/messages.js deleted file mode 100644 index 70f3bbd..0000000 --- a/src/containers/LearnerDashboardHeaderVariant/messages.js +++ /dev/null @@ -1,71 +0,0 @@ -import { defineMessages } from '@edx/frontend-platform/i18n'; - -const messages = defineMessages({ - dashboard: { - id: 'learnerVariantDashboard.menu.dashboard.label', - defaultMessage: 'Dashboard', - description: 'The text for the user menu Dashboard navigation link.', - }, - help: { - id: 'learnerVariantDashboard.help.label', - defaultMessage: 'Help', - description: 'The text for the link to the Help Center', - }, - profile: { - id: 'learnerVariantDashboard.menu.profile.label', - defaultMessage: 'Profile', - description: 'The text for the user menu Profile navigation link.', - }, - viewPrograms: { - id: 'learnerVariantDashboard.menu.viewPrograms.label', - defaultMessage: 'View Programs', - description: 'The text for the user menu View Programs navigation link.', - }, - account: { - id: 'learnerVariantDashboard.menu.account.label', - defaultMessage: 'Account', - description: 'The text for the user menu Account navigation link.', - }, - orderHistory: { - id: 'learnerVariantDashboard.menu.orderHistory.label', - defaultMessage: 'Order History', - description: 'The text for the user menu Order History navigation link.', - }, - signOut: { - id: 'learnerVariantDashboard.menu.signOut.label', - defaultMessage: 'Sign Out', - description: 'The label for the user menu Sign Out action.', - }, - course: { - id: 'learnerVariantDashboard.course', - defaultMessage: 'Courses', - description: 'Header link for switching to dashboard page.', - }, - program: { - id: 'learnerVariantDashboard.program', - defaultMessage: 'Programs', - description: 'Header link for switching to program page.', - }, - discoverNew: { - id: 'learnerVariantDashboard.discoverNew', - defaultMessage: 'Discover New', - description: 'Header link for switching to discover page.', - }, - logoAltText: { - id: 'learnerVariantDashboard.logoAltText', - defaultMessage: 'edX, Inc. Dashboard', - description: 'Alt text for the edX logo.', - }, - collapseMenuOpenAltText: { - id: 'learnerVariantDashboard.collapseMenuOpenAltText', - defaultMessage: 'Menu', - description: 'Alt text for the collapse menu icon when the menu is open.', - }, - collapseMenuClosedAltText: { - id: 'learnerVariantDashboard.collapseMenuClosedAltText', - defaultMessage: 'Close', - description: 'Alt text for the collapse menu icon when the menu is closed.', - }, -}); - -export default messages;