Compare commits
1 Commits
frontend-b
...
jwesson/re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3663efb283 |
@@ -1,77 +0,0 @@
|
|||||||
import { getConfig } from '@edx/frontend-platform';
|
|
||||||
|
|
||||||
import urls from 'data/services/lms/urls';
|
|
||||||
|
|
||||||
import messages from './messages';
|
|
||||||
|
|
||||||
const getLearnerHeaderMenu = (
|
|
||||||
formatMessage,
|
|
||||||
courseSearchUrl,
|
|
||||||
authenticatedUser,
|
|
||||||
exploreCoursesClick,
|
|
||||||
) => ({
|
|
||||||
mainMenu: [
|
|
||||||
{
|
|
||||||
type: 'item',
|
|
||||||
href: '/',
|
|
||||||
content: formatMessage(messages.course),
|
|
||||||
isActive: true,
|
|
||||||
},
|
|
||||||
...(getConfig().ENABLE_PROGRAMS ? [{
|
|
||||||
type: 'item',
|
|
||||||
href: `${urls.programsUrl()}`,
|
|
||||||
content: formatMessage(messages.program),
|
|
||||||
}] : []),
|
|
||||||
...(!getConfig().NON_BROWSABLE_COURSES ? [{
|
|
||||||
type: 'item',
|
|
||||||
href: `${urls.baseAppUrl(courseSearchUrl)}`,
|
|
||||||
content: formatMessage(messages.discoverNew),
|
|
||||||
onClick: (e) => {
|
|
||||||
exploreCoursesClick(e);
|
|
||||||
},
|
|
||||||
}]
|
|
||||||
: []),
|
|
||||||
],
|
|
||||||
secondaryMenu: [
|
|
||||||
...(getConfig().SUPPORT_URL ? [{
|
|
||||||
type: 'item',
|
|
||||||
href: `${getConfig().SUPPORT_URL}`,
|
|
||||||
content: formatMessage(messages.help),
|
|
||||||
}] : []),
|
|
||||||
],
|
|
||||||
userMenu: [
|
|
||||||
{
|
|
||||||
heading: '',
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
type: 'item',
|
|
||||||
href: `${getConfig().ACCOUNT_PROFILE_URL}/u/${authenticatedUser?.username}`,
|
|
||||||
content: formatMessage(messages.profile),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'item',
|
|
||||||
href: `${getConfig().ACCOUNT_SETTINGS_URL}`,
|
|
||||||
content: formatMessage(messages.account),
|
|
||||||
},
|
|
||||||
...(getConfig().ORDER_HISTORY_URL ? [{
|
|
||||||
type: 'item',
|
|
||||||
href: getConfig().ORDER_HISTORY_URL,
|
|
||||||
content: formatMessage(messages.orderHistory),
|
|
||||||
}] : []),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
heading: '',
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
type: 'item',
|
|
||||||
href: `${getConfig().LOGOUT_URL}`,
|
|
||||||
content: formatMessage(messages.signOut),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export default getLearnerHeaderMenu;
|
|
||||||
@@ -3,59 +3,7 @@
|
|||||||
exports[`LearnerDashboardHeader render 1`] = `
|
exports[`LearnerDashboardHeader render 1`] = `
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<ConfirmEmailBanner />
|
<ConfirmEmailBanner />
|
||||||
<Header
|
<Header />
|
||||||
mainMenuItems={
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"content": "Courses",
|
|
||||||
"href": "/",
|
|
||||||
"isActive": true,
|
|
||||||
"type": "item",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"content": "Discover New",
|
|
||||||
"href": "http://localhost:18000/course-search-url",
|
|
||||||
"onClick": [Function],
|
|
||||||
"type": "item",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
secondaryMenuItems={[]}
|
|
||||||
userMenuItems={
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"heading": "",
|
|
||||||
"items": [
|
|
||||||
{
|
|
||||||
"content": "Profile",
|
|
||||||
"href": "http://account-profile-url.test/u/undefined",
|
|
||||||
"type": "item",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"content": "Account",
|
|
||||||
"href": "http://account-settings-url.test",
|
|
||||||
"type": "item",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"content": "Order History",
|
|
||||||
"href": "test-url",
|
|
||||||
"type": "item",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"heading": "",
|
|
||||||
"items": [
|
|
||||||
{
|
|
||||||
"content": "Sign Out",
|
|
||||||
"href": "http://localhost:18000/logout",
|
|
||||||
"type": "item",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<MasqueradeBar />
|
<MasqueradeBar />
|
||||||
</Fragment>
|
</Fragment>
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
|
||||||
import track from 'tracking';
|
|
||||||
import { StrictDict } from 'utils';
|
|
||||||
import { linkNames } from 'tracking/constants';
|
|
||||||
|
|
||||||
import getLearnerHeaderMenu from './LearnerDashboardMenu';
|
|
||||||
|
|
||||||
export const state = StrictDict({
|
|
||||||
isOpen: (val) => React.useState(val), // eslint-disable-line
|
|
||||||
});
|
|
||||||
|
|
||||||
export const findCoursesNavClicked = (href) => track.findCourses.findCoursesClicked(href, {
|
|
||||||
linkName: linkNames.learnerHomeNavExplore,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const useLearnerDashboardHeaderMenu = ({
|
|
||||||
courseSearchUrl, authenticatedUser, exploreCoursesClick,
|
|
||||||
}) => {
|
|
||||||
const { formatMessage } = useIntl();
|
|
||||||
return getLearnerHeaderMenu(formatMessage, courseSearchUrl, authenticatedUser, exploreCoursesClick);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default {
|
|
||||||
findCoursesNavClicked,
|
|
||||||
useLearnerDashboardHeaderMenu,
|
|
||||||
};
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
import track from 'tracking';
|
|
||||||
import { linkNames } from 'tracking/constants';
|
|
||||||
|
|
||||||
import { MockUseState } from 'testUtils';
|
|
||||||
|
|
||||||
import * as hooks from './hooks';
|
|
||||||
|
|
||||||
const state = new MockUseState(hooks);
|
|
||||||
|
|
||||||
const {
|
|
||||||
findCoursesNavClicked,
|
|
||||||
useLearnerDashboardHeaderMenu,
|
|
||||||
} = hooks;
|
|
||||||
|
|
||||||
jest.mock('tracking', () => ({
|
|
||||||
findCourses: {
|
|
||||||
findCoursesClicked: jest.fn(),
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
const url = 'http://example.com';
|
|
||||||
|
|
||||||
describe('LearnerDashboardHeader hooks', () => {
|
|
||||||
describe('state values', () => {
|
|
||||||
state.testGetter(state.keys.isOpen);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('findCoursesNavClicked', () => {
|
|
||||||
test('calls tracking with nav link name', () => {
|
|
||||||
findCoursesNavClicked(url);
|
|
||||||
expect(track.findCourses.findCoursesClicked).toHaveBeenCalledWith(url, {
|
|
||||||
linkName: linkNames.learnerHomeNavExplore,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getLearnerDashboardHeaderMenu', () => {
|
|
||||||
test('calls header menu data hook', () => {
|
|
||||||
const courseSearchUrl = '/courses';
|
|
||||||
const authenticatedUser = {
|
|
||||||
username: 'test',
|
|
||||||
};
|
|
||||||
const learnerHomeHeaderMenu = useLearnerDashboardHeaderMenu({ courseSearchUrl, authenticatedUser });
|
|
||||||
expect(learnerHomeHeaderMenu.mainMenu.length).toBe(2);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,43 +1,16 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import MasqueradeBar from 'containers/MasqueradeBar';
|
|
||||||
import { AppContext } from '@edx/frontend-platform/react';
|
|
||||||
import Header from '@edx/frontend-component-header';
|
import Header from '@edx/frontend-component-header';
|
||||||
import { reduxHooks } from 'hooks';
|
import MasqueradeBar from 'containers/MasqueradeBar';
|
||||||
import urls from 'data/services/lms/urls';
|
|
||||||
|
|
||||||
import ConfirmEmailBanner from './ConfirmEmailBanner';
|
import ConfirmEmailBanner from './ConfirmEmailBanner';
|
||||||
|
|
||||||
import { useLearnerDashboardHeaderMenu, findCoursesNavClicked } from './hooks';
|
export const LearnerDashboardHeader = () => (
|
||||||
|
<>
|
||||||
import './index.scss';
|
<ConfirmEmailBanner />
|
||||||
|
<Header />
|
||||||
export const LearnerDashboardHeader = () => {
|
<MasqueradeBar />
|
||||||
const { authenticatedUser } = React.useContext(AppContext);
|
</>
|
||||||
const { courseSearchUrl } = reduxHooks.usePlatformSettingsData();
|
);
|
||||||
|
|
||||||
const exploreCoursesClick = () => {
|
|
||||||
findCoursesNavClicked(urls.baseAppUrl(courseSearchUrl));
|
|
||||||
};
|
|
||||||
|
|
||||||
const learnerHomeHeaderMenu = useLearnerDashboardHeaderMenu({
|
|
||||||
courseSearchUrl,
|
|
||||||
authenticatedUser,
|
|
||||||
exploreCoursesClick,
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<ConfirmEmailBanner />
|
|
||||||
<Header
|
|
||||||
mainMenuItems={learnerHomeHeaderMenu.mainMenu}
|
|
||||||
secondaryMenuItems={learnerHomeHeaderMenu.secondaryMenu}
|
|
||||||
userMenuItems={learnerHomeHeaderMenu.userMenu}
|
|
||||||
/>
|
|
||||||
<MasqueradeBar />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
LearnerDashboardHeader.propTypes = {};
|
LearnerDashboardHeader.propTypes = {};
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -1,52 +1,18 @@
|
|||||||
import { mergeConfig } from '@edx/frontend-platform';
|
|
||||||
import { shallow } from '@edx/react-unit-test-utils';
|
import { shallow } from '@edx/react-unit-test-utils';
|
||||||
import Header from '@edx/frontend-component-header';
|
import Header from '@edx/frontend-component-header';
|
||||||
|
|
||||||
import urls from 'data/services/lms/urls';
|
|
||||||
import LearnerDashboardHeader from '.';
|
import LearnerDashboardHeader from '.';
|
||||||
import { findCoursesNavClicked } from './hooks';
|
|
||||||
|
|
||||||
jest.mock('hooks', () => ({
|
|
||||||
reduxHooks: {
|
|
||||||
usePlatformSettingsData: jest.fn(() => ({
|
|
||||||
courseSearchUrl: '/course-search-url',
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
jest.mock('./hooks', () => ({
|
|
||||||
...jest.requireActual('./hooks'),
|
|
||||||
findCoursesNavClicked: jest.fn(),
|
|
||||||
}));
|
|
||||||
jest.mock('containers/MasqueradeBar', () => 'MasqueradeBar');
|
jest.mock('containers/MasqueradeBar', () => 'MasqueradeBar');
|
||||||
jest.mock('./ConfirmEmailBanner', () => 'ConfirmEmailBanner');
|
jest.mock('./ConfirmEmailBanner', () => 'ConfirmEmailBanner');
|
||||||
jest.mock('@edx/frontend-component-header', () => 'Header');
|
jest.mock('@edx/frontend-component-header', () => 'Header');
|
||||||
|
|
||||||
describe('LearnerDashboardHeader', () => {
|
describe('LearnerDashboardHeader', () => {
|
||||||
test('render', () => {
|
test('render', () => {
|
||||||
mergeConfig({ ORDER_HISTORY_URL: 'test-url' });
|
|
||||||
const wrapper = shallow(<LearnerDashboardHeader />);
|
const wrapper = shallow(<LearnerDashboardHeader />);
|
||||||
expect(wrapper.snapshot).toMatchSnapshot();
|
expect(wrapper.snapshot).toMatchSnapshot();
|
||||||
expect(wrapper.instance.findByType('ConfirmEmailBanner')).toHaveLength(1);
|
expect(wrapper.instance.findByType('ConfirmEmailBanner')).toHaveLength(1);
|
||||||
expect(wrapper.instance.findByType('MasqueradeBar')).toHaveLength(1);
|
expect(wrapper.instance.findByType('MasqueradeBar')).toHaveLength(1);
|
||||||
expect(wrapper.instance.findByType(Header)).toHaveLength(1);
|
expect(wrapper.instance.findByType(Header)).toHaveLength(1);
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should display Help link if SUPPORT_URL is set', () => {
|
|
||||||
mergeConfig({ SUPPORT_URL: 'http://localhost:18000/support' });
|
|
||||||
const wrapper = shallow(<LearnerDashboardHeader />);
|
|
||||||
expect(wrapper.instance.findByType(Header)[0].props.secondaryMenuItems.length).toBe(1);
|
|
||||||
});
|
|
||||||
test('should display Programs link if it is enabled by configuration', () => {
|
|
||||||
mergeConfig({ ENABLE_PROGRAMS: true });
|
|
||||||
const wrapper = shallow(<LearnerDashboardHeader />);
|
|
||||||
expect(wrapper.instance.findByType(Header)[0].props.mainMenuItems.length).toBe(3);
|
|
||||||
});
|
|
||||||
test('should not display Discover New tab if it is disabled by configuration', () => {
|
|
||||||
mergeConfig({ NON_BROWSABLE_COURSES: true });
|
|
||||||
const wrapper = shallow(<LearnerDashboardHeader />);
|
|
||||||
expect(wrapper.instance.findByType(Header)[0].props.mainMenuItems.length).toBe(2);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,91 +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.',
|
|
||||||
},
|
|
||||||
dashboardPersonal: {
|
|
||||||
id: 'learnerVariantDashboard.menu.dashboardPersonal.label',
|
|
||||||
defaultMessage: 'Personal',
|
|
||||||
description: 'Link to personal dashboard in user menu',
|
|
||||||
},
|
|
||||||
dashboardSwitch: {
|
|
||||||
id: 'learnerVariantDashboard.menu.dashboardSwitch.label',
|
|
||||||
defaultMessage: 'SWITCH DASHBOARD',
|
|
||||||
description: 'Switch Dashboard header in the user menu',
|
|
||||||
},
|
|
||||||
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.',
|
|
||||||
},
|
|
||||||
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',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default messages;
|
|
||||||
Reference in New Issue
Block a user