Compare commits
1 Commits
master
...
jwesson/re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3663efb283 |
5
.env
5
.env
@@ -1,5 +1,4 @@
|
||||
NODE_ENV='production'
|
||||
APP_ID='learner-dashboard'
|
||||
NODE_PATH=./src
|
||||
BASE_URL=''
|
||||
LMS_BASE_URL=''
|
||||
@@ -38,10 +37,8 @@ HOTJAR_VERSION='6'
|
||||
HOTJAR_DEBUG=''
|
||||
ACCOUNT_SETTINGS_URL=''
|
||||
ACCOUNT_PROFILE_URL=''
|
||||
ENABLE_NOTICES=''
|
||||
CAREER_LINK_URL=''
|
||||
ENABLE_EDX_PERSONAL_DASHBOARD=false
|
||||
ENABLE_PROGRAMS=false
|
||||
NON_BROWSABLE_COURSES=false
|
||||
SHOW_UNENROLL_SURVEY=true
|
||||
# Fallback in local style files
|
||||
PARAGON_THEME_URLS={}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
NODE_ENV='development'
|
||||
APP_ID='learner-dashboard'
|
||||
PORT=1996
|
||||
BASE_URL='localhost:1996'
|
||||
LMS_BASE_URL='http://localhost:18000'
|
||||
@@ -44,10 +43,8 @@ HOTJAR_VERSION='6'
|
||||
HOTJAR_DEBUG=''
|
||||
ACCOUNT_SETTINGS_URL='http://localhost:1997'
|
||||
ACCOUNT_PROFILE_URL='http://localhost:1995'
|
||||
ENABLE_NOTICES=''
|
||||
CAREER_LINK_URL=''
|
||||
ENABLE_EDX_PERSONAL_DASHBOARD=false
|
||||
ENABLE_PROGRAMS=false
|
||||
NON_BROWSABLE_COURSES=false
|
||||
SHOW_UNENROLL_SURVEY=true
|
||||
# Fallback in local style files
|
||||
PARAGON_THEME_URLS={}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
NODE_ENV='test'
|
||||
APP_ID='learner-dashboard'
|
||||
PORT=1996
|
||||
BASE_URL='localhost:1996'
|
||||
LMS_BASE_URL='http://localhost:18000'
|
||||
@@ -43,9 +42,8 @@ HOTJAR_VERSION='6'
|
||||
HOTJAR_DEBUG=''
|
||||
ACCOUNT_SETTINGS_URL='http://account-settings-url.test'
|
||||
ACCOUNT_PROFILE_URL='http://account-profile-url.test'
|
||||
ENABLE_NOTICES=''
|
||||
CAREER_LINK_URL=''
|
||||
ENABLE_EDX_PERSONAL_DASHBOARD=true
|
||||
ENABLE_PROGRAMS=false
|
||||
NON_BROWSABLE_COURSES=false
|
||||
SHOW_UNENROLL_SURVEY=true
|
||||
PARAGON_THEME_URLS={}
|
||||
|
||||
1
.github/CODEOWNERS
vendored
Normal file
1
.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1 @@
|
||||
* @openedx/2U-aperture
|
||||
7
.github/workflows/ci.yml
vendored
7
.github/workflows/ci.yml
vendored
@@ -14,10 +14,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Nodejs
|
||||
uses: actions/setup-node@v6
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version-file: '.nvmrc'
|
||||
|
||||
@@ -29,9 +29,6 @@ jobs:
|
||||
|
||||
- name: Lint
|
||||
run: npm run lint
|
||||
|
||||
- name: Type check
|
||||
run: npm run types
|
||||
|
||||
- name: Test
|
||||
run: npm run test
|
||||
|
||||
11
Makefile
11
Makefile
@@ -12,11 +12,6 @@ transifex_temp = ./temp/babel-plugin-formatjs
|
||||
|
||||
NPM_TESTS=build i18n_extract lint test
|
||||
|
||||
# Variables for additional translation sources and imports (define in edx-internal if needed)
|
||||
ATLAS_EXTRA_SOURCES ?=
|
||||
ATLAS_EXTRA_INTL_IMPORTS ?=
|
||||
ATLAS_OPTIONS ?=
|
||||
|
||||
.PHONY: test
|
||||
test: $(addprefix test.npm.,$(NPM_TESTS)) ## validate ci suite
|
||||
|
||||
@@ -52,12 +47,10 @@ pull_translations:
|
||||
&& atlas pull $(ATLAS_OPTIONS) \
|
||||
translations/frontend-platform/src/i18n/messages:frontend-platform \
|
||||
translations/paragon/src/i18n/messages:paragon \
|
||||
translations/frontend-component-header/src/i18n/messages:frontend-component-header \
|
||||
translations/frontend-component-footer/src/i18n/messages:frontend-component-footer \
|
||||
translations/frontend-app-learner-dashboard/src/i18n/messages:frontend-app-learner-dashboard \
|
||||
$(ATLAS_EXTRA_SOURCES)
|
||||
translations/frontend-app-learner-dashboard/src/i18n/messages:frontend-app-learner-dashboard
|
||||
|
||||
$(intl_imports) frontend-platform paragon frontend-component-header frontend-component-footer frontend-app-learner-dashboard $(ATLAS_EXTRA_INTL_IMPORTS)
|
||||
$(intl_imports) frontend-platform paragon frontend-component-footer frontend-app-learner-dashboard
|
||||
|
||||
# This target is used by CI.
|
||||
validate-no-uncommitted-package-lock-changes:
|
||||
|
||||
18
README.rst
18
README.rst
@@ -39,12 +39,22 @@ The parts of this MFE that can be customized in that manner are documented `here
|
||||
Contributing
|
||||
------------
|
||||
|
||||
Contributions are very welcome. Please read `So you want to contribute to Open edX <https://docs.openedx.org/en/latest/developers/quickstarts/so_you_want_to_contribute.html>`_ for details on how to get started as an Open edX contributor.
|
||||
A core goal of this app is to provide a clean experimentation interface. To promote this end, we have provided a
|
||||
silo'ed code directory at ``src/widgets`` in which contributors should add their custom widget components. In order to
|
||||
ensure our ability to maintain the code stability of the app, the code for these widgets should be strictly contained
|
||||
within the bounds of that directory.
|
||||
|
||||
This project is currently accepting all types of contributions — bug fixes, security fixes, maintenance work, or new features.
|
||||
However, if you intend to add a new feature, make sure it has gone through the `Product Review process <https://openedx.atlassian.net/wiki/spaces/COMM/pages/3875962884/How+to+submit+an+open+source+contribution+for+Product+Review>`_.
|
||||
Once written, the widgets can be configured into one of our widget containers at ``src/containers/WidgetContainers``.
|
||||
This can include conditional logic, as well as Optimizely triggers. It is important to note that our integration tests
|
||||
will isolate and ignore these containers, and thus testing your widget is the response of the creator/maintainer of the
|
||||
widget itself.
|
||||
|
||||
When proposing a change, create an issue in this repo to get the discussion started.
|
||||
Some guidelines for writing widgets:
|
||||
|
||||
* Code for the widget should be strictly confined to the ``src/widgets`` directory.
|
||||
* You can load data from the redux store, but should not add or modify fields in that structure.
|
||||
* Network events should be managed in component hooks, though can use our ``data/constants/requests:requestStates`` for
|
||||
ease of tracking the request states.
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
@@ -19,13 +19,11 @@ frontend-platform's getConfig loads configuration in the following sequence:
|
||||
|
||||
module.exports = {
|
||||
NODE_ENV: 'development',
|
||||
APP_ID: 'learner-dashboard',
|
||||
NODE_PATH: './src',
|
||||
PORT: 1996,
|
||||
BASE_URL: 'localhost:1996',
|
||||
LMS_BASE_URL: 'http://localhost:18000',
|
||||
ECOMMERCE_BASE_URL: 'http://localhost:18130',
|
||||
CREDIT_PURCHASE_URL: 'http://localhost:8140',
|
||||
LOGIN_URL: 'http://localhost:18000/login',
|
||||
LOGOUT_URL: 'http://localhost:18000/logout',
|
||||
LOGO_URL: 'https://edx-cdn.org/v3/default/logo.svg',
|
||||
@@ -68,7 +66,7 @@ module.exports = {
|
||||
NEW_RELIC_LICENSE_KEY: '',
|
||||
ACCOUNT_SETTINGS_URL: 'http://localhost:1997',
|
||||
ACCOUNT_PROFILE_URL: 'http://localhost:1995',
|
||||
ENABLE_NOTICES: '',
|
||||
CAREER_LINK_URL: '',
|
||||
EXPERIMENT_08_23_VAN_PAINTED_DOOR: true,
|
||||
SHOW_UNENROLL_SURVEY: true
|
||||
};
|
||||
|
||||
7689
package-lock.json
generated
7689
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
33
package.json
33
package.json
@@ -20,7 +20,7 @@
|
||||
"test": "TZ=GMT fedx-scripts jest --coverage --passWithNoTests",
|
||||
"quality": "npm run lint-fix && npm run test",
|
||||
"watch-tests": "jest --watch",
|
||||
"types": "tsc --noEmit"
|
||||
"snapshot": "fedx-scripts jest --updateSnapshot"
|
||||
},
|
||||
"author": "edX",
|
||||
"license": "AGPL-3.0",
|
||||
@@ -31,19 +31,22 @@
|
||||
"dependencies": {
|
||||
"@edx/brand": "npm:@openedx/brand-openedx@^1.2.2",
|
||||
"@edx/frontend-component-footer": "^14.6.0",
|
||||
"@edx/frontend-component-header": "^8.0.0",
|
||||
"@edx/frontend-component-header": "^6.2.0",
|
||||
"@edx/frontend-enterprise-hotjar": "7.2.0",
|
||||
"@edx/frontend-platform": "^8.3.1",
|
||||
"@edx/openedx-atlas": "^0.7.0",
|
||||
"@edx/react-unit-test-utils": "^4.0.0",
|
||||
"@fortawesome/fontawesome-svg-core": "^1.2.36",
|
||||
"@fortawesome/free-brands-svg-icons": "^5.15.4",
|
||||
"@fortawesome/free-solid-svg-icons": "^5.15.4",
|
||||
"@fortawesome/react-fontawesome": "^0.2.0",
|
||||
"@openedx/frontend-plugin-framework": "^1.7.0",
|
||||
"@openedx/paragon": "^23.4.5",
|
||||
"@tanstack/react-query": "^5.90.16",
|
||||
"@openedx/paragon": "^22.16.0",
|
||||
"@redux-devtools/extension": "3.3.0",
|
||||
"@reduxjs/toolkit": "^2.0.0",
|
||||
"classnames": "^2.3.1",
|
||||
"core-js": "3.48.0",
|
||||
"core-js": "3.42.0",
|
||||
"filesize": "^10.0.0",
|
||||
"font-awesome": "4.7.0",
|
||||
"history": "5.3.0",
|
||||
"lodash": "^4.17.21",
|
||||
@@ -53,25 +56,31 @@
|
||||
"react-dom": "^18.3.1",
|
||||
"react-helmet": "^6.1.0",
|
||||
"react-intl": "6.8.9",
|
||||
"react-router-dom": "6.30.3",
|
||||
"react-share": "^5.2.2",
|
||||
"react-redux": "^7.2.4",
|
||||
"react-router-dom": "6.29.0",
|
||||
"react-share": "^4.4.0",
|
||||
"redux": "4.2.1",
|
||||
"redux-logger": "3.0.6",
|
||||
"redux-thunk": "2.4.2",
|
||||
"regenerator-runtime": "^0.14.0",
|
||||
"reselect": "^4.0.0",
|
||||
"universal-cookie": "^4.0.4",
|
||||
"util": "^0.12.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@edx/browserslist-config": "^1.3.0",
|
||||
"@edx/typescript-config": "^1.1.0",
|
||||
"@openedx/frontend-build": "^14.6.2",
|
||||
"@edx/reactifex": "^2.1.1",
|
||||
"@openedx/frontend-build": "^14.3.3",
|
||||
"@testing-library/jest-dom": "^6.6.3",
|
||||
"@testing-library/react": "^16.2.0",
|
||||
"@testing-library/user-event": "^14.6.1",
|
||||
"copy-webpack-plugin": "^13.0.0",
|
||||
"copy-webpack-plugin": "^12.0.0",
|
||||
"identity-obj-proxy": "^3.0.0",
|
||||
"jest": "^29.7.0",
|
||||
"jest-environment-jsdom": "^29.7.0",
|
||||
"jest-expect-message": "^1.1.3",
|
||||
"jest-when": "^3.6.0",
|
||||
"react-dev-utils": "^12.0.0",
|
||||
"react-test-renderer": "^18.3.1"
|
||||
"react-test-renderer": "^18.3.1",
|
||||
"redux-mock-store": "^1.5.4"
|
||||
}
|
||||
}
|
||||
|
||||
52
src/App.jsx
52
src/App.jsx
@@ -5,29 +5,60 @@ import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
import { logError } from '@edx/frontend-platform/logging';
|
||||
import { initializeHotjar } from '@edx/frontend-enterprise-hotjar';
|
||||
|
||||
import { ErrorPage } from '@edx/frontend-platform/react';
|
||||
import { ErrorPage, AppContext } from '@edx/frontend-platform/react';
|
||||
import { FooterSlot } from '@edx/frontend-component-footer';
|
||||
import { Alert } from '@openedx/paragon';
|
||||
|
||||
import { RequestKeys } from 'data/constants/requests';
|
||||
import store from 'data/store';
|
||||
import {
|
||||
selectors,
|
||||
actions,
|
||||
} from 'data/redux';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import Dashboard from 'containers/Dashboard';
|
||||
|
||||
import AppWrapper from 'containers/AppWrapper';
|
||||
import track from 'tracking';
|
||||
|
||||
import fakeData from 'data/services/lms/fakeData/courses';
|
||||
|
||||
import AppWrapper from 'containers/WidgetContainers/AppWrapper';
|
||||
import LearnerDashboardHeader from 'containers/LearnerDashboardHeader';
|
||||
|
||||
import { getConfig } from '@edx/frontend-platform';
|
||||
import { useInitializeLearnerHome } from 'data/hooks';
|
||||
import { useMasquerade } from 'data/context';
|
||||
import messages from './messages';
|
||||
import './App.scss';
|
||||
|
||||
export const App = () => {
|
||||
const { authenticatedUser } = React.useContext(AppContext);
|
||||
const { formatMessage } = useIntl();
|
||||
const { masqueradeUser } = useMasquerade();
|
||||
const { data, isError } = useInitializeLearnerHome();
|
||||
const hasNetworkFailure = !masqueradeUser && isError;
|
||||
const supportEmail = data?.platformSettings?.supportEmail || undefined;
|
||||
const isFailed = {
|
||||
initialize: reduxHooks.useRequestIsFailed(RequestKeys.initialize),
|
||||
refreshList: reduxHooks.useRequestIsFailed(RequestKeys.refreshList),
|
||||
};
|
||||
const hasNetworkFailure = isFailed.initialize || isFailed.refreshList;
|
||||
const { supportEmail } = reduxHooks.usePlatformSettingsData();
|
||||
const loadData = reduxHooks.useLoadData();
|
||||
|
||||
/* istanbul ignore next */
|
||||
React.useEffect(() => {
|
||||
if (authenticatedUser?.administrator || getConfig().NODE_ENV === 'development') {
|
||||
window.loadEmptyData = () => {
|
||||
loadData({ ...fakeData.globalData, courses: [] });
|
||||
};
|
||||
window.loadMockData = () => {
|
||||
loadData({
|
||||
...fakeData.globalData,
|
||||
courses: [
|
||||
...fakeData.courseRunData,
|
||||
...fakeData.entitlementData,
|
||||
],
|
||||
});
|
||||
};
|
||||
window.store = store;
|
||||
window.selectors = selectors;
|
||||
window.actions = actions;
|
||||
window.track = track;
|
||||
}
|
||||
if (getConfig().HOTJAR_APP_ID) {
|
||||
try {
|
||||
initializeHotjar({
|
||||
@@ -39,7 +70,7 @@ export const App = () => {
|
||||
logError(error);
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
}, [authenticatedUser, loadData]);
|
||||
return (
|
||||
<>
|
||||
<Helmet>
|
||||
@@ -60,6 +91,7 @@ export const App = () => {
|
||||
)}
|
||||
</main>
|
||||
</AppWrapper>
|
||||
<FooterSlot />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
86
src/App.scss
86
src/App.scss
@@ -1,89 +1,13 @@
|
||||
// frontend-app-*/src/index.scss
|
||||
@use "@openedx/paragon/styles/css/core/custom-media-breakpoints" as paragonCustomMediaBreakpoints;
|
||||
@import "~@edx/brand/paragon/fonts";
|
||||
@import "~@edx/brand/paragon/variables";
|
||||
@import "~@openedx/paragon/scss/core/core";
|
||||
@import "~@edx/brand/paragon/overrides";
|
||||
|
||||
$fa-font-path: "~font-awesome/fonts";
|
||||
@import "~font-awesome/scss/font-awesome";
|
||||
|
||||
// Andal Learning Brand Colors - Override Paragon variables
|
||||
:root {
|
||||
--pgn-color-primary: #ff4f00;
|
||||
--pgn-color-primary-100: #ffe6cc;
|
||||
--pgn-color-primary-200: #ffcc99;
|
||||
--pgn-color-primary-300: #ffb366;
|
||||
--pgn-color-primary-400: #ff9933;
|
||||
--pgn-color-primary-500: #ff4f00;
|
||||
--pgn-color-primary-600: #cc3f00;
|
||||
--pgn-color-primary-700: #992f00;
|
||||
--pgn-color-primary-800: #661f00;
|
||||
--pgn-color-primary-900: #330f00;
|
||||
--pgn-color-action-primary: #ff4f00;
|
||||
--pgn-color-action-primary-hover: #cc3f00;
|
||||
--pgn-color-action-primary-focus: #992f00;
|
||||
--pgn-color-action-primary-active: #992f00;
|
||||
}
|
||||
|
||||
// Override all button variants to use Andal orange
|
||||
.btn-primary {
|
||||
background-color: #ff4f00 !important;
|
||||
border-color: #ff4f00 !important;
|
||||
|
||||
&:hover {
|
||||
background-color: #cc3f00 !important;
|
||||
border-color: #cc3f00 !important;
|
||||
}
|
||||
|
||||
&:focus {
|
||||
background-color: #992f00 !important;
|
||||
border-color: #992f00 !important;
|
||||
box-shadow: 0 0 0 2px #ffcc99 !important;
|
||||
}
|
||||
}
|
||||
|
||||
.btn-outline-primary {
|
||||
color: #ff4f00 !important;
|
||||
border-color: #ff4f00 !important;
|
||||
|
||||
&:hover {
|
||||
background-color: #ff4f00 !important;
|
||||
color: #fff !important;
|
||||
}
|
||||
|
||||
&:focus {
|
||||
box-shadow: 0 0 0 2px #ffcc99 !important;
|
||||
}
|
||||
}
|
||||
|
||||
.btn-brand {
|
||||
background-color: #ff4f00 !important;
|
||||
border-color: #ff4f00 !important;
|
||||
color: #fff !important;
|
||||
|
||||
&:hover {
|
||||
background-color: #cc3f00 !important;
|
||||
border-color: #cc3f00 !important;
|
||||
}
|
||||
|
||||
&:focus {
|
||||
box-shadow: 0 0 0 2px #ffcc99 !important;
|
||||
}
|
||||
}
|
||||
|
||||
// Override link colors
|
||||
a {
|
||||
color: #ff4f00;
|
||||
|
||||
&:hover {
|
||||
color: #cc3f00;
|
||||
}
|
||||
}
|
||||
|
||||
// Override active states
|
||||
.active {
|
||||
background-color: #ff4f00 !important;
|
||||
color: #fff !important;
|
||||
}
|
||||
|
||||
$input-focus-box-shadow: var(--pgn-elevation-form-input-base); // hack to get upgrade to paragon 4.0.0 to work
|
||||
$input-focus-box-shadow: $input-box-shadow; // hack to get upgrade to paragon 4.0.0 to work
|
||||
|
||||
@import "~@edx/frontend-component-header/dist/index";
|
||||
@import "~@edx/frontend-component-footer/dist/_footer";
|
||||
|
||||
157
src/App.test.jsx
157
src/App.test.jsx
@@ -1,131 +1,148 @@
|
||||
import { render, screen, waitFor } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
import { Helmet } from 'react-helmet';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
import { getConfig } from '@edx/frontend-platform';
|
||||
|
||||
import { useInitializeLearnerHome } from 'data/hooks';
|
||||
import { RequestKeys } from 'data/constants/requests';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import Dashboard from 'containers/Dashboard';
|
||||
import LearnerDashboardHeader from 'containers/LearnerDashboardHeader';
|
||||
import AppWrapper from 'containers/WidgetContainers/AppWrapper';
|
||||
import { App } from './App';
|
||||
import messages from './messages';
|
||||
|
||||
jest.mock('data/hooks', () => ({
|
||||
useInitializeLearnerHome: jest.fn(),
|
||||
}));
|
||||
jest.mock('@edx/frontend-component-footer', () => ({ FooterSlot: 'FooterSlot' }));
|
||||
|
||||
jest.mock('data/context', () => ({
|
||||
useMasquerade: jest.fn(() => ({ masqueradeUser: null })),
|
||||
jest.mock('containers/Dashboard', () => 'Dashboard');
|
||||
jest.mock('containers/LearnerDashboardHeader', () => 'LearnerDashboardHeader');
|
||||
jest.mock('containers/WidgetContainers/AppWrapper', () => 'AppWrapper');
|
||||
jest.mock('data/redux', () => ({
|
||||
selectors: 'redux.selectors',
|
||||
actions: 'redux.actions',
|
||||
thunkActions: 'redux.thunkActions',
|
||||
}));
|
||||
|
||||
jest.mock('@edx/frontend-component-footer', () => ({
|
||||
FooterSlot: jest.fn(() => <div>FooterSlot</div>),
|
||||
jest.mock('hooks', () => ({
|
||||
reduxHooks: {
|
||||
useRequestIsFailed: jest.fn(),
|
||||
usePlatformSettingsData: jest.fn(),
|
||||
useLoadData: jest.fn(),
|
||||
},
|
||||
}));
|
||||
jest.mock('containers/Dashboard', () => jest.fn(() => <div>Dashboard</div>));
|
||||
jest.mock('containers/LearnerDashboardHeader', () => jest.fn(() => <div>LearnerDashboardHeader</div>));
|
||||
jest.mock('containers/AppWrapper', () => jest.fn(({ children }) => <div className="AppWrapper">{children}</div>));
|
||||
jest.mock('data/store', () => 'data/store');
|
||||
|
||||
jest.mock('@edx/frontend-platform', () => ({
|
||||
getConfig: jest.fn(() => ({})),
|
||||
}));
|
||||
|
||||
jest.mock('@edx/frontend-platform/react', () => ({
|
||||
...jest.requireActual('@edx/frontend-platform/react'),
|
||||
ErrorPage: () => 'ErrorPage',
|
||||
}));
|
||||
const loadData = jest.fn();
|
||||
reduxHooks.useLoadData.mockReturnValue(loadData);
|
||||
|
||||
const supportEmail = 'test@support.com';
|
||||
useInitializeLearnerHome.mockReturnValue({
|
||||
data: {
|
||||
platformSettings: {
|
||||
supportEmail,
|
||||
},
|
||||
},
|
||||
isError: false,
|
||||
});
|
||||
let el;
|
||||
|
||||
const supportEmail = 'test-support-url';
|
||||
reduxHooks.usePlatformSettingsData.mockReturnValue({ supportEmail });
|
||||
|
||||
describe('App router component', () => {
|
||||
const { formatMessage } = useIntl();
|
||||
describe('component', () => {
|
||||
const runBasicTests = () => {
|
||||
it('displays title in helmet component', async () => {
|
||||
await waitFor(() => expect(document.title).toEqual(messages.pageTitle.defaultMessage));
|
||||
test('snapshot', () => { expect(el.snapshot).toMatchSnapshot(); });
|
||||
it('displays title in helmet component', () => {
|
||||
const control = el.instance
|
||||
.findByType(Helmet)[0]
|
||||
.findByType('title')[0];
|
||||
expect(control.children[0].el).toEqual(formatMessage(messages.pageTitle));
|
||||
});
|
||||
it('displays learner dashboard header', () => {
|
||||
const learnerDashboardHeader = screen.getByText('LearnerDashboardHeader');
|
||||
expect(learnerDashboardHeader).toBeInTheDocument();
|
||||
expect(el.instance.findByType(LearnerDashboardHeader).length).toEqual(1);
|
||||
});
|
||||
it('wraps the header and main components in an AppWrapper widget container', () => {
|
||||
const appWrapper = screen.getByText('LearnerDashboardHeader').parentElement;
|
||||
expect(appWrapper).toHaveClass('AppWrapper');
|
||||
expect(appWrapper.children[1].id).toEqual('main');
|
||||
});
|
||||
it('displays footer slot', () => {
|
||||
const footerSlot = screen.getByText('FooterSlot');
|
||||
expect(footerSlot).toBeInTheDocument();
|
||||
const container = el.instance.findByType(AppWrapper)[0];
|
||||
expect(container.children[0].type).toEqual('LearnerDashboardHeader');
|
||||
expect(container.children[1].type).toEqual('main');
|
||||
});
|
||||
};
|
||||
describe('no network failure', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
beforeAll(() => {
|
||||
reduxHooks.useRequestIsFailed.mockReturnValue(false);
|
||||
getConfig.mockReturnValue({});
|
||||
render(<IntlProvider locale="en"><App /></IntlProvider>);
|
||||
el = shallow(<App />);
|
||||
});
|
||||
runBasicTests();
|
||||
it('loads dashboard', () => {
|
||||
const dashboard = screen.getByText('Dashboard');
|
||||
expect(dashboard).toBeInTheDocument();
|
||||
const main = el.instance.findByType('main')[0];
|
||||
expect(main.children.length).toEqual(1);
|
||||
const dashboard = main.children[0].el;
|
||||
expect(dashboard.type).toEqual('Dashboard');
|
||||
expect(dashboard).toEqual(shallow(<Dashboard />));
|
||||
});
|
||||
});
|
||||
describe('no network failure with optimizely url', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
beforeAll(() => {
|
||||
reduxHooks.useRequestIsFailed.mockReturnValue(false);
|
||||
getConfig.mockReturnValue({ OPTIMIZELY_URL: 'fake.url' });
|
||||
render(<IntlProvider locale="en"><App /></IntlProvider>);
|
||||
el = shallow(<App />);
|
||||
});
|
||||
runBasicTests();
|
||||
it('loads dashboard', () => {
|
||||
const dashboard = screen.getByText('Dashboard');
|
||||
expect(dashboard).toBeInTheDocument();
|
||||
const main = el.instance.findByType('main')[0];
|
||||
expect(main.children.length).toEqual(1);
|
||||
const dashboard = main.children[0].el;
|
||||
expect(dashboard.type).toEqual('Dashboard');
|
||||
expect(dashboard).toEqual(shallow(<Dashboard />));
|
||||
});
|
||||
});
|
||||
describe('no network failure with optimizely project id', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
beforeAll(() => {
|
||||
reduxHooks.useRequestIsFailed.mockReturnValue(false);
|
||||
getConfig.mockReturnValue({ OPTIMIZELY_PROJECT_ID: 'fakeId' });
|
||||
render(<IntlProvider locale="en"><App /></IntlProvider>);
|
||||
el = shallow(<App />);
|
||||
});
|
||||
runBasicTests();
|
||||
it('loads dashboard', () => {
|
||||
const dashboard = screen.getByText('Dashboard');
|
||||
expect(dashboard).toBeInTheDocument();
|
||||
const main = el.instance.findByType('main')[0];
|
||||
expect(main.children.length).toEqual(1);
|
||||
const dashboard = main.children[0].el;
|
||||
expect(dashboard.type).toEqual('Dashboard');
|
||||
expect(dashboard).toEqual(shallow(<Dashboard />));
|
||||
});
|
||||
});
|
||||
describe('initialize failure', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
useInitializeLearnerHome.mockReturnValue({
|
||||
data: null,
|
||||
isError: true,
|
||||
});
|
||||
beforeAll(() => {
|
||||
reduxHooks.useRequestIsFailed.mockImplementation((key) => key === RequestKeys.initialize);
|
||||
getConfig.mockReturnValue({});
|
||||
render(<IntlProvider locale="en" messages={messages}><App /></IntlProvider>);
|
||||
el = shallow(<App />);
|
||||
});
|
||||
runBasicTests();
|
||||
it('loads error page', () => {
|
||||
const alert = screen.getByRole('alert');
|
||||
expect(alert).toBeInTheDocument();
|
||||
const errorPage = screen.getByText('ErrorPage');
|
||||
expect(errorPage).toBeInTheDocument();
|
||||
const main = el.instance.findByType('main')[0];
|
||||
expect(main.children.length).toEqual(1);
|
||||
const alert = main.children[0];
|
||||
expect(alert.type).toEqual('Alert');
|
||||
expect(alert.children.length).toEqual(1);
|
||||
const errorPage = alert.children[0];
|
||||
expect(errorPage.type).toEqual('ErrorPage');
|
||||
expect(errorPage.props.message).toEqual(formatMessage(messages.errorMessage, { supportEmail }));
|
||||
});
|
||||
});
|
||||
describe('refresh failure', () => {
|
||||
beforeEach(() => {
|
||||
beforeAll(() => {
|
||||
reduxHooks.useRequestIsFailed.mockImplementation((key) => key === RequestKeys.refreshList);
|
||||
getConfig.mockReturnValue({});
|
||||
render(<IntlProvider locale="en"><App /></IntlProvider>);
|
||||
el = shallow(<App />);
|
||||
});
|
||||
runBasicTests();
|
||||
it('loads error page', () => {
|
||||
const alert = screen.getByRole('alert');
|
||||
expect(alert).toBeInTheDocument();
|
||||
const errorPage = screen.getByText('ErrorPage');
|
||||
expect(errorPage).toBeInTheDocument();
|
||||
const main = el.instance.findByType('main')[0];
|
||||
expect(main.children.length).toEqual(1);
|
||||
const alert = main.children[0];
|
||||
expect(alert.type).toEqual('Alert');
|
||||
expect(alert.children.length).toEqual(1);
|
||||
const errorPage = alert.children[0];
|
||||
expect(errorPage.type).toEqual('ErrorPage');
|
||||
expect(errorPage.props.message).toEqual(formatMessage(messages.errorMessage, { supportEmail }));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
153
src/__snapshots__/App.test.jsx.snap
Normal file
153
src/__snapshots__/App.test.jsx.snap
Normal file
@@ -0,0 +1,153 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`App router component component initialize failure snapshot 1`] = `
|
||||
<Fragment>
|
||||
<HelmetWrapper
|
||||
defer={true}
|
||||
encodeSpecialCharacters={true}
|
||||
>
|
||||
<title>
|
||||
Learner Home
|
||||
</title>
|
||||
<link
|
||||
rel="shortcut icon"
|
||||
type="image/x-icon"
|
||||
/>
|
||||
</HelmetWrapper>
|
||||
<div>
|
||||
<AppWrapper>
|
||||
<LearnerDashboardHeader />
|
||||
<main
|
||||
id="main"
|
||||
>
|
||||
<Alert
|
||||
variant="danger"
|
||||
>
|
||||
<ErrorPage
|
||||
message="If you experience repeated failures, please email support at test-support-url"
|
||||
/>
|
||||
</Alert>
|
||||
</main>
|
||||
</AppWrapper>
|
||||
<FooterSlot />
|
||||
</div>
|
||||
</Fragment>
|
||||
`;
|
||||
|
||||
exports[`App router component component no network failure snapshot 1`] = `
|
||||
<Fragment>
|
||||
<HelmetWrapper
|
||||
defer={true}
|
||||
encodeSpecialCharacters={true}
|
||||
>
|
||||
<title>
|
||||
Learner Home
|
||||
</title>
|
||||
<link
|
||||
rel="shortcut icon"
|
||||
type="image/x-icon"
|
||||
/>
|
||||
</HelmetWrapper>
|
||||
<div>
|
||||
<AppWrapper>
|
||||
<LearnerDashboardHeader />
|
||||
<main
|
||||
id="main"
|
||||
>
|
||||
<Dashboard />
|
||||
</main>
|
||||
</AppWrapper>
|
||||
<FooterSlot />
|
||||
</div>
|
||||
</Fragment>
|
||||
`;
|
||||
|
||||
exports[`App router component component no network failure with optimizely project id snapshot 1`] = `
|
||||
<Fragment>
|
||||
<HelmetWrapper
|
||||
defer={true}
|
||||
encodeSpecialCharacters={true}
|
||||
>
|
||||
<title>
|
||||
Learner Home
|
||||
</title>
|
||||
<link
|
||||
rel="shortcut icon"
|
||||
type="image/x-icon"
|
||||
/>
|
||||
</HelmetWrapper>
|
||||
<div>
|
||||
<AppWrapper>
|
||||
<LearnerDashboardHeader />
|
||||
<main
|
||||
id="main"
|
||||
>
|
||||
<Dashboard />
|
||||
</main>
|
||||
</AppWrapper>
|
||||
<FooterSlot />
|
||||
</div>
|
||||
</Fragment>
|
||||
`;
|
||||
|
||||
exports[`App router component component no network failure with optimizely url snapshot 1`] = `
|
||||
<Fragment>
|
||||
<HelmetWrapper
|
||||
defer={true}
|
||||
encodeSpecialCharacters={true}
|
||||
>
|
||||
<title>
|
||||
Learner Home
|
||||
</title>
|
||||
<link
|
||||
rel="shortcut icon"
|
||||
type="image/x-icon"
|
||||
/>
|
||||
</HelmetWrapper>
|
||||
<div>
|
||||
<AppWrapper>
|
||||
<LearnerDashboardHeader />
|
||||
<main
|
||||
id="main"
|
||||
>
|
||||
<Dashboard />
|
||||
</main>
|
||||
</AppWrapper>
|
||||
<FooterSlot />
|
||||
</div>
|
||||
</Fragment>
|
||||
`;
|
||||
|
||||
exports[`App router component component refresh failure snapshot 1`] = `
|
||||
<Fragment>
|
||||
<HelmetWrapper
|
||||
defer={true}
|
||||
encodeSpecialCharacters={true}
|
||||
>
|
||||
<title>
|
||||
Learner Home
|
||||
</title>
|
||||
<link
|
||||
rel="shortcut icon"
|
||||
type="image/x-icon"
|
||||
/>
|
||||
</HelmetWrapper>
|
||||
<div>
|
||||
<AppWrapper>
|
||||
<LearnerDashboardHeader />
|
||||
<main
|
||||
id="main"
|
||||
>
|
||||
<Alert
|
||||
variant="danger"
|
||||
>
|
||||
<ErrorPage
|
||||
message="If you experience repeated failures, please email support at test-support-url"
|
||||
/>
|
||||
</Alert>
|
||||
</main>
|
||||
</AppWrapper>
|
||||
<FooterSlot />
|
||||
</div>
|
||||
</Fragment>
|
||||
`;
|
||||
43
src/__snapshots__/index.test.jsx.snap
Normal file
43
src/__snapshots__/index.test.jsx.snap
Normal file
@@ -0,0 +1,43 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`app registry subscribe: APP_INIT_ERROR. snapshot: displays an ErrorPage to root element 1`] = `
|
||||
<UNDEFINED>
|
||||
<ErrorPage
|
||||
message="test-error-message"
|
||||
/>
|
||||
</UNDEFINED>
|
||||
`;
|
||||
|
||||
exports[`app registry subscribe: APP_READY. links App to root element 1`] = `
|
||||
<UNDEFINED>
|
||||
<AppProvider
|
||||
store={
|
||||
{
|
||||
"redux": "store",
|
||||
}
|
||||
}
|
||||
>
|
||||
<NoticesWrapper>
|
||||
<Routes>
|
||||
<Route
|
||||
element={
|
||||
<PageWrap>
|
||||
<App />
|
||||
</PageWrap>
|
||||
}
|
||||
path="/"
|
||||
/>
|
||||
<Route
|
||||
element={
|
||||
<Navigate
|
||||
replace={true}
|
||||
to="/"
|
||||
/>
|
||||
}
|
||||
path="*"
|
||||
/>
|
||||
</Routes>
|
||||
</NoticesWrapper>
|
||||
</AppProvider>
|
||||
</UNDEFINED>
|
||||
`;
|
||||
@@ -1,17 +0,0 @@
|
||||
<svg width="518" height="87" viewBox="0 0 518 87" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M512.654 43.4098C512.654 35.747 509.327 31.2325 503.564 31.2325C497.861 31.2325 494.474 35.747 494.474 43.4098C494.474 51.0726 497.861 55.5871 503.564 55.5871C509.327 55.5871 512.654 51.0726 512.654 43.4098ZM518 56.0029C518 67.111 513.188 72.3978 503.029 72.3978C499.286 72.3978 496.019 71.8632 492.87 70.6751V65.5072C496.019 67.1704 499.049 68.0021 502.198 68.0021C509.148 68.0021 512.654 64.3786 512.654 56.9534V54.3397C510.455 58.1414 507.01 60.0422 502.257 60.0422C498.277 60.0422 495.009 58.5572 492.573 55.5277C490.137 52.4982 488.949 48.4589 488.949 43.4098C488.949 38.3607 490.137 34.3807 492.573 31.3513C495.009 28.3218 498.277 26.7773 502.257 26.7773C507.01 26.7773 510.455 28.6782 512.654 32.4799V27.5496H518V56.0029Z" fill="black"/>
|
||||
<path d="M484.03 50.3004C484.149 55.7653 484.209 59.864 484.209 59.864L478.743 59.9234C478.743 59.9234 478.862 60.7551 478.683 51.0726C478.565 45.4294 478.565 40.6179 478.565 40.6179C478.565 34.4401 476.129 31.4107 471.376 31.4107C465.613 31.4107 462.049 35.3312 462.049 41.6871V60.0422H456.702C456.702 60.0422 456.702 46.7363 456.702 37.1726C456.702 32.5987 453.375 33.0145 453.375 33.0145V27.5496C453.375 27.5496 456.88 27.5496 458.841 29.688C460.564 31.5889 460.623 33.7273 460.623 33.7273C461.811 29.7474 466.802 26.7773 472.03 26.7773C479.456 26.7773 483.911 31.4701 483.911 40.4397C483.911 40.4397 483.911 41.5089 484.03 50.3004Z" fill="black"/>
|
||||
<path d="M443.611 27.5485H448.958C448.958 27.5485 448.661 42.8147 448.779 51.4873C448.779 55.5861 452.166 55.1702 452.166 55.1702V60.2194C452.166 60.2194 443.492 60.0412 443.611 52.2002C443.73 42.6365 443.611 27.5485 443.611 27.5485ZM446.225 14.3613C444.264 14.3613 442.66 15.9652 442.66 17.9254C442.66 19.8857 444.264 21.4895 446.225 21.4895C448.185 21.4895 449.789 19.9451 449.789 17.9254C449.789 15.9058 448.185 14.3613 446.225 14.3613Z" fill="black"/>
|
||||
<path d="M436.376 50.3004C436.495 55.7653 436.554 59.864 436.554 59.864L431.089 59.9234C431.089 59.9234 431.207 60.7551 431.029 51.0726C430.91 45.4294 430.91 40.6179 430.91 40.6179C430.91 34.4401 428.475 31.4107 423.722 31.4107C417.959 31.4107 414.395 35.3312 414.395 41.6871V60.0422H409.048C409.048 60.0422 409.048 46.7363 409.048 37.1726C409.048 32.5987 405.721 33.0145 405.721 33.0145V27.5496C405.721 27.5496 409.226 27.5496 411.186 29.688C412.909 31.5889 412.969 33.7273 412.969 33.7273C414.157 29.7474 419.147 26.7773 424.375 26.7773C431.801 26.7773 436.257 31.4701 436.257 40.4397C436.257 40.4397 436.257 41.5089 436.376 50.3004Z" fill="black"/>
|
||||
<path d="M403.931 32.4208C402.208 32.5396 400.961 32.5396 399 33.49C396.386 34.7969 393.237 37.7076 393.237 42.9349C393.237 49.8849 393.237 60.0426 393.237 60.0426H387.891V27.5499H393.237V32.599C395.257 29.5695 397.337 27.3717 401.911 27.1935C402.684 27.1341 402.446 27.1341 403.931 27.1935V32.4208Z" fill="black"/>
|
||||
<path d="M369.696 43.7068C365.359 43.7068 362.388 44.182 360.725 45.1918C359.061 46.2017 358.23 47.8649 358.23 50.241C358.23 54.0427 360.903 56.4187 365.181 56.4187C371.122 56.4187 374.983 51.8448 374.983 44.8948V43.7068H369.696ZM380.271 51.9636C380.271 56.1811 384.251 55.8247 384.251 55.8247V59.9234C384.251 59.9234 381.221 60.2799 379.142 58.6166C377.241 57.1316 376.112 54.9337 376.112 54.9337C373.676 58.9136 369.042 60.8739 363.755 60.8739C357.101 60.8739 352.883 56.8346 352.883 50.5974C352.883 43.291 357.814 39.5487 367.498 39.5487H374.983V39.0141C374.983 34.0837 372.191 31.2919 366.309 31.2919C363.577 31.2919 360.071 33.3709 360.19 36.935L355.259 37.0538C355.378 28.6782 362.923 26.7773 366.428 26.7773C375.577 26.7773 380.33 31.5889 380.33 41.5089C380.33 41.5089 380.211 47.8055 380.271 51.9636Z" fill="black"/>
|
||||
<path d="M349.423 42.4594V45.073H324.887C325.362 52.4388 329.402 56.3593 336.472 56.3593C340.571 56.3593 344.374 55.4089 348.176 53.3299V58.379C344.374 60.0422 340.274 60.8739 336.175 60.8739C331.006 60.8739 326.848 59.3888 323.818 56.3593C320.788 53.3299 319.303 49.2906 319.303 44.1226C319.303 38.8359 320.729 34.6184 323.58 31.4701C326.491 28.3218 330.353 26.7773 335.224 26.7773C339.621 26.7773 343.067 28.203 345.621 30.9949C348.176 33.7867 349.423 37.6478 349.423 42.4594ZM344.076 40.9149C344.017 35.0342 340.571 31.2919 335.284 31.2919C329.343 31.2919 325.6 34.7966 325.065 40.9149H344.076Z" fill="black"/>
|
||||
<path d="M308.35 14.897H313.696C313.696 14.897 313.875 38.4794 313.875 51.1914C313.875 55.4089 319.459 55.3495 319.459 55.3495L319.4 60.161C319.4 60.161 313.578 60.3392 310.488 56.0029C309.003 53.9832 308.35 51.726 308.35 48.7559C308.35 35.3905 308.35 14.897 308.35 14.897Z" fill="black"/>
|
||||
<path d="M279.439 14.897H284.786C284.786 14.897 284.965 38.4794 284.965 51.1914C284.965 55.4089 290.549 55.3495 290.549 55.3495L290.49 60.161C290.49 60.161 284.667 60.3392 281.578 56.0029C280.093 53.9832 279.439 51.726 279.439 48.7559C279.439 35.3905 279.439 14.897 279.439 14.897Z" fill="black"/>
|
||||
<path d="M261.065 43.7068C256.728 43.7068 253.757 44.182 252.094 45.1918C250.431 46.2017 249.599 47.8649 249.599 50.241C249.599 54.0427 252.272 56.4187 256.55 56.4187C262.491 56.4187 266.352 51.8448 266.352 44.8948V43.7068H261.065ZM271.64 51.9636C271.64 56.1811 275.62 55.8247 275.62 55.8247V59.9234C275.62 59.9234 272.59 60.2799 270.511 58.6166C268.61 57.1316 267.481 54.9337 267.481 54.9337C265.045 58.9136 260.411 60.8739 255.124 60.8739C248.47 60.8739 244.252 56.8346 244.252 50.5974C244.252 43.291 249.183 39.5487 258.867 39.5487H266.352V39.0141C266.352 34.0837 263.56 31.2919 257.678 31.2919C254.946 31.2919 251.44 33.3709 251.559 36.935L246.628 37.0538C246.747 28.6782 254.292 26.7773 257.797 26.7773C266.946 26.7773 271.699 31.5889 271.699 41.5089C271.699 41.5089 271.58 47.8055 271.64 51.9636Z" fill="black"/>
|
||||
<path d="M233.216 32.4799V14.897H238.563C238.563 14.897 238.682 38.42 238.682 50.8943C238.682 55.2901 238.682 59.864 238.682 59.864L233.81 59.9234L233.87 55.4089C231.671 59.27 227.572 60.8738 222.819 60.8738C218.898 60.8738 215.69 59.3294 213.195 56.1811C210.759 53.0328 209.512 48.9341 209.512 43.8256C209.512 38.717 210.759 34.6183 213.195 31.47C215.69 28.3217 218.898 26.7773 222.819 26.7773C227.572 26.7773 231.018 28.6187 233.216 32.4799ZM215.037 43.8256C215.037 51.6666 218.423 56.4187 224.126 56.4187C229.77 56.4187 233.216 51.6666 233.216 43.8256C233.216 35.9845 229.77 31.2324 224.126 31.2324C218.423 31.2324 215.037 35.9845 215.037 43.8256Z" fill="black"/>
|
||||
<path d="M204.591 50.3004C204.71 55.7653 204.769 59.864 204.769 59.864L199.303 59.9234C199.303 59.9234 199.422 60.7551 199.244 51.0726C199.125 45.4294 199.125 40.6179 199.125 40.6179C199.125 34.4401 196.689 31.4107 191.937 31.4107C186.174 31.4107 182.609 35.3312 182.609 41.6871V60.0422H177.262C177.262 60.0422 177.262 46.7363 177.262 37.1726C177.262 32.5987 173.936 33.0145 173.936 33.0145V27.5496C173.936 27.5496 177.441 27.5496 179.401 29.688C181.124 31.5889 181.183 33.7273 181.183 33.7273C182.372 29.7474 187.362 26.7773 192.59 26.7773C200.016 26.7773 204.472 31.4701 204.472 40.4397C204.472 40.4397 204.472 41.5089 204.591 50.3004Z" fill="black"/>
|
||||
<path d="M159.067 43.7068C154.73 43.7068 151.759 44.182 150.096 45.1918C148.432 46.2017 147.601 47.8649 147.601 50.241C147.601 54.0427 150.274 56.4187 154.552 56.4187C160.493 56.4187 164.354 51.8448 164.354 44.8948V43.7068H159.067ZM169.642 51.9636C169.642 56.1811 173.622 55.8247 173.622 55.8247V59.9234C173.622 59.9234 170.592 60.2799 168.513 58.6166C166.612 57.1316 165.483 54.9337 165.483 54.9337C163.047 58.9136 158.413 60.8739 153.126 60.8739C146.472 60.8739 142.254 56.8346 142.254 50.5974C142.254 43.291 147.185 39.5487 156.869 39.5487H164.354V39.0141C164.354 34.0837 161.562 31.2919 155.68 31.2919C152.948 31.2919 149.442 33.3709 149.561 36.935L144.63 37.0538C144.749 28.6782 152.294 26.7773 155.799 26.7773C164.948 26.7773 169.701 31.5889 169.701 41.5089C169.701 41.5089 169.582 47.8055 169.642 51.9636Z" fill="black"/>
|
||||
<path d="M8.40549 86.8917C3.76365 86.8917 0 83.0908 0 78.4008V55.9119C0 51.2229 3.76265 47.421 8.40549 47.421H121.955C121.91 52.4182 121.875 57.4144 121.851 62.4106C121.821 68.5717 121.808 74.7338 121.81 80.8959C124.658 80.8726 127.506 80.8482 130.355 80.8249V86.8907L8.40549 86.8917Z" fill="#FF4F00"/>
|
||||
<path d="M124.912 40.1348H9.02975C4.08481 40.1348 0.0752715 36.3339 0.0752715 31.6439V8.49088C0.0752715 3.80189 4.08481 0 9.02975 0H130.282C130.264 1.47615 130.246 2.95331 130.229 4.42945C129.018 4.43249 127.808 4.43554 126.596 4.43858C125.745 8.73218 124.895 13.0268 124.045 17.3204C122.613 23.2077 121.182 29.0951 119.749 34.9814H124.935C124.927 36.6989 124.919 38.4173 124.912 40.1348Z" fill="#FF4F00"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 8.4 KiB |
@@ -1,27 +1,27 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { Alert } from '@openedx/paragon';
|
||||
|
||||
import Banner from './Banner';
|
||||
|
||||
describe('Banner component', () => {
|
||||
it('renders children content', () => {
|
||||
render(<Banner>Test content</Banner>);
|
||||
expect(screen.getByText('Test content')).toBeInTheDocument();
|
||||
});
|
||||
describe('Banner', () => {
|
||||
const props = {
|
||||
children: 'Hello, world!',
|
||||
};
|
||||
describe('snapshot', () => {
|
||||
test('renders default banner', () => {
|
||||
const wrapper = shallow(<Banner {...props} />);
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
test('renders with variants', () => {
|
||||
const wrapper = shallow(<Banner {...props} variant="success" />);
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
|
||||
it('uses default props correctly', () => {
|
||||
render(<Banner>Test content</Banner>);
|
||||
const banner = screen.getByRole('alert');
|
||||
expect(banner).toHaveClass('mb-0');
|
||||
});
|
||||
|
||||
it('accepts custom variant prop', () => {
|
||||
render(<Banner variant="success">Test content</Banner>);
|
||||
const banner = screen.getByRole('alert');
|
||||
expect(banner).toHaveClass('alert-success');
|
||||
});
|
||||
|
||||
it('accepts custom className prop', () => {
|
||||
render(<Banner className="custom-class">Test content</Banner>);
|
||||
const banner = screen.getByRole('alert');
|
||||
expect(banner).toHaveClass('custom-class');
|
||||
expect(wrapper.instance.findByType(Alert)[0].props.variant).toEqual('success');
|
||||
});
|
||||
test('renders with custom class', () => {
|
||||
const wrapper = shallow(<Banner {...props} className="custom-class" />);
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
25
src/components/NoticesWrapper/api.js
Normal file
25
src/components/NoticesWrapper/api.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { getConfig } from '@edx/frontend-platform';
|
||||
import { getAuthenticatedHttpClient, getAuthenticatedUser } from '@edx/frontend-platform/auth';
|
||||
import { logError, logInfo } from '@edx/frontend-platform/logging';
|
||||
|
||||
export const noticesUrl = `${getConfig().LMS_BASE_URL}/notices/api/v1/unacknowledged`;
|
||||
|
||||
export const getNotices = ({ onLoad, notFoundMessage }) => {
|
||||
const authenticatedUser = getAuthenticatedUser();
|
||||
|
||||
const handleError = async (e) => {
|
||||
// Error probably means that notices is not installed, which is fine.
|
||||
const { customAttributes: { httpErrorStatus } } = e;
|
||||
if (httpErrorStatus === 404) {
|
||||
logInfo(`${e}. ${notFoundMessage}`);
|
||||
} else {
|
||||
logError(e);
|
||||
}
|
||||
};
|
||||
if (authenticatedUser) {
|
||||
return getAuthenticatedHttpClient().get(noticesUrl, {}).then(onLoad).catch(handleError);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
export default { getNotices };
|
||||
65
src/components/NoticesWrapper/api.test.js
Normal file
65
src/components/NoticesWrapper/api.test.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import { getAuthenticatedHttpClient, getAuthenticatedUser } from '@edx/frontend-platform/auth';
|
||||
import { logError, logInfo } from '@edx/frontend-platform/logging';
|
||||
|
||||
import * as api from './api';
|
||||
|
||||
jest.mock('@edx/frontend-platform', () => ({
|
||||
getConfig: jest.fn(() => ({
|
||||
LMS_BASE_URL: 'test-lms-url',
|
||||
})),
|
||||
}));
|
||||
|
||||
jest.mock('@edx/frontend-platform/auth', () => ({
|
||||
getAuthenticatedHttpClient: jest.fn(),
|
||||
getAuthenticatedUser: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('@edx/frontend-platform/logging', () => ({
|
||||
logError: jest.fn(),
|
||||
logInfo: jest.fn(),
|
||||
}));
|
||||
|
||||
const testData = 'test-data';
|
||||
const successfulGet = () => Promise.resolve(testData);
|
||||
const error404 = { customAttributes: { httpErrorStatus: 404 }, test: 'error' };
|
||||
const error404Get = () => Promise.reject(error404);
|
||||
const error500 = { customAttributes: { httpErrorStatus: 500 }, test: 'error' };
|
||||
const error500Get = () => Promise.reject(error500);
|
||||
|
||||
const get = jest.fn().mockImplementation(successfulGet);
|
||||
getAuthenticatedHttpClient.mockReturnValue({ get });
|
||||
const authenticatedUser = { fake: 'user' };
|
||||
getAuthenticatedUser.mockReturnValue(authenticatedUser);
|
||||
|
||||
const onLoad = jest.fn();
|
||||
describe('getNotices api method', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
describe('behavior', () => {
|
||||
describe('not authenticated', () => {
|
||||
it('does not fetch anything', () => {
|
||||
getAuthenticatedUser.mockReturnValueOnce(null);
|
||||
api.getNotices({ onLoad });
|
||||
expect(get).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
describe('authenticated', () => {
|
||||
it('fetches noticesUrl with onLoad behavior', async () => {
|
||||
await api.getNotices({ onLoad });
|
||||
expect(get).toHaveBeenCalledWith(api.noticesUrl, {});
|
||||
expect(onLoad).toHaveBeenCalledWith(testData);
|
||||
});
|
||||
it('calls logInfo if fetch fails with 404', async () => {
|
||||
get.mockImplementation(error404Get);
|
||||
await api.getNotices({ onLoad });
|
||||
expect(logInfo).toHaveBeenCalledWith(`${error404}. ${api.error404Message}`);
|
||||
});
|
||||
it('calls logError if fetch fails with non-404 error', async () => {
|
||||
get.mockImplementation(error500Get);
|
||||
await api.getNotices({ onLoad });
|
||||
expect(logError).toHaveBeenCalledWith(error500);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
40
src/components/NoticesWrapper/hooks.js
Normal file
40
src/components/NoticesWrapper/hooks.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import React from 'react';
|
||||
import { getConfig } from '@edx/frontend-platform';
|
||||
import { useIntl } from 'react-intl';
|
||||
|
||||
import { StrictDict } from 'utils';
|
||||
import { getNotices } from './api';
|
||||
import * as module from './hooks';
|
||||
import messages from './messages';
|
||||
|
||||
/**
|
||||
* This component uses the platform-plugin-notices plugin to function.
|
||||
* If the user has an unacknowledged notice, they will be rerouted off
|
||||
* course home and onto a full-screen notice page. If the plugin is not
|
||||
* installed, or there are no notices, we just passthrough this component.
|
||||
*/
|
||||
export const state = StrictDict({
|
||||
isRedirected: (val) => React.useState(val), // eslint-disable-line
|
||||
});
|
||||
|
||||
export const useNoticesWrapperData = () => {
|
||||
const [isRedirected, setIsRedirected] = module.state.isRedirected();
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
React.useEffect(() => {
|
||||
if (getConfig().ENABLE_NOTICES) {
|
||||
getNotices({
|
||||
onLoad: (data) => {
|
||||
if (data?.data?.results?.length > 0) {
|
||||
setIsRedirected(true);
|
||||
window.location.replace(`${data.data.results[0]}?next=${window.location.href}`);
|
||||
}
|
||||
},
|
||||
notFoundMessage: formatMessage(messages.error404Message),
|
||||
});
|
||||
}
|
||||
}, [setIsRedirected, formatMessage]);
|
||||
return { isRedirected };
|
||||
};
|
||||
|
||||
export default useNoticesWrapperData;
|
||||
89
src/components/NoticesWrapper/hooks.test.js
Normal file
89
src/components/NoticesWrapper/hooks.test.js
Normal file
@@ -0,0 +1,89 @@
|
||||
import React from 'react';
|
||||
|
||||
import { MockUseState } from 'testUtils';
|
||||
|
||||
import { getConfig } from '@edx/frontend-platform';
|
||||
import { getNotices } from './api';
|
||||
import * as hooks from './hooks';
|
||||
|
||||
jest.mock('@edx/frontend-platform', () => ({ getConfig: jest.fn() }));
|
||||
jest.mock('./api', () => ({ getNotices: jest.fn() }));
|
||||
const mockFormatMessage = jest.fn(message => message.defaultMessage || 'translated-string');
|
||||
jest.mock('react-intl', () => ({
|
||||
useIntl: () => ({
|
||||
formatMessage: mockFormatMessage,
|
||||
}),
|
||||
}));
|
||||
|
||||
getConfig.mockReturnValue({ ENABLE_NOTICES: true });
|
||||
const state = new MockUseState(hooks);
|
||||
|
||||
let hook;
|
||||
describe('NoticesWrapper hooks', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
describe('state hooks', () => {
|
||||
state.testGetter(state.keys.isRedirected);
|
||||
});
|
||||
describe('useNoticesWrapperData', () => {
|
||||
beforeEach(() => {
|
||||
state.mock();
|
||||
});
|
||||
describe('behavior', () => {
|
||||
it('initializes state hooks', () => {
|
||||
hooks.useNoticesWrapperData();
|
||||
expect(hooks.state.isRedirected).toHaveBeenCalledWith();
|
||||
});
|
||||
describe('effects', () => {
|
||||
it('does not call notices if not enabled', () => {
|
||||
getConfig.mockReturnValueOnce({ ENABLE_NOTICES: false });
|
||||
hooks.useNoticesWrapperData();
|
||||
const [cb, prereqs] = React.useEffect.mock.calls[0];
|
||||
expect(prereqs).toEqual([state.setState.isRedirected, mockFormatMessage]);
|
||||
cb();
|
||||
expect(getNotices).not.toHaveBeenCalled();
|
||||
});
|
||||
describe('getNotices call (if enabled) onLoad behavior', () => {
|
||||
it('does not redirect if there are no results', () => {
|
||||
hooks.useNoticesWrapperData();
|
||||
expect(React.useEffect).toHaveBeenCalled();
|
||||
const [cb, prereqs] = React.useEffect.mock.calls[0];
|
||||
expect(prereqs).toEqual([state.setState.isRedirected, mockFormatMessage]);
|
||||
cb();
|
||||
expect(getNotices).toHaveBeenCalled();
|
||||
const { onLoad } = getNotices.mock.calls[0][0];
|
||||
onLoad({});
|
||||
expect(state.setState.isRedirected).not.toHaveBeenCalled();
|
||||
onLoad({ data: {} });
|
||||
expect(state.setState.isRedirected).not.toHaveBeenCalled();
|
||||
onLoad({ data: { results: [] } });
|
||||
expect(state.setState.isRedirected).not.toHaveBeenCalled();
|
||||
});
|
||||
it('redirects and set isRedirected if results are returned', () => {
|
||||
delete window.location;
|
||||
window.location = { replace: jest.fn(), href: 'test-old-href' };
|
||||
hooks.useNoticesWrapperData();
|
||||
const [cb, prereqs] = React.useEffect.mock.calls[0];
|
||||
expect(prereqs).toEqual([state.setState.isRedirected, mockFormatMessage]);
|
||||
cb();
|
||||
expect(getNotices).toHaveBeenCalled();
|
||||
const { onLoad } = getNotices.mock.calls[0][0];
|
||||
const target = 'url-target';
|
||||
onLoad({ data: { results: [target] } });
|
||||
expect(state.setState.isRedirected).toHaveBeenCalledWith(true);
|
||||
expect(window.location.replace).toHaveBeenCalledWith(
|
||||
`${target}?next=${window.location.href}`,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('output', () => {
|
||||
it('forwards isRedirected from state call', () => {
|
||||
hook = hooks.useNoticesWrapperData();
|
||||
expect(hook.isRedirected).toEqual(state.stateVals.isRedirected);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
25
src/components/NoticesWrapper/index.jsx
Normal file
25
src/components/NoticesWrapper/index.jsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import useNoticesWrapperData from './hooks';
|
||||
|
||||
/**
|
||||
* This component uses the platform-plugin-notices plugin to function.
|
||||
* If the user has an unacknowledged notice, they will be rerouted off
|
||||
* course home and onto a full-screen notice page. If the plugin is not
|
||||
* installed, or there are no notices, we just passthrough this component.
|
||||
*/
|
||||
const NoticesWrapper = ({ children }) => {
|
||||
const { isRedirected } = useNoticesWrapperData();
|
||||
return (
|
||||
<div>
|
||||
{isRedirected === true ? null : children}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
NoticesWrapper.propTypes = {
|
||||
children: PropTypes.node.isRequired,
|
||||
};
|
||||
|
||||
export default NoticesWrapper;
|
||||
36
src/components/NoticesWrapper/index.test.jsx
Normal file
36
src/components/NoticesWrapper/index.test.jsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import React from 'react';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import useNoticesWrapperData from './hooks';
|
||||
import NoticesWrapper from '.';
|
||||
|
||||
jest.mock('./hooks', () => jest.fn());
|
||||
|
||||
const hookProps = { isRedirected: false };
|
||||
useNoticesWrapperData.mockReturnValue(hookProps);
|
||||
|
||||
let el;
|
||||
const children = [<b key={1}>some</b>, <i key={2}>children</i>];
|
||||
describe('NoticesWrapper component', () => {
|
||||
describe('behavior', () => {
|
||||
it('initializes hooks', () => {
|
||||
el = shallow(<NoticesWrapper>{children}</NoticesWrapper>);
|
||||
expect(useNoticesWrapperData).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
describe('output', () => {
|
||||
it('does not show children if redirected', () => {
|
||||
useNoticesWrapperData.mockReturnValueOnce({ isRedirected: true });
|
||||
el = shallow(<NoticesWrapper>{children}</NoticesWrapper>);
|
||||
expect(el.instance.children.length).toEqual(0);
|
||||
});
|
||||
it('shows children if not redirected', () => {
|
||||
el = shallow(<NoticesWrapper>{children}</NoticesWrapper>);
|
||||
expect(el.instance.children.length).toEqual(2);
|
||||
expect(el.instance.children[0].type).toEqual(shallow(children[0]).type);
|
||||
expect(el.instance.props).toEqual(shallow(children[0]).props);
|
||||
expect(el.instance.children[1].type).toEqual(shallow(children[1]).type);
|
||||
expect(el.instance.props).toEqual(shallow(children[1]).props);
|
||||
});
|
||||
});
|
||||
});
|
||||
11
src/components/NoticesWrapper/messages.js
Normal file
11
src/components/NoticesWrapper/messages.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { defineMessages } from '@edx/frontend-platform/i18n';
|
||||
|
||||
const messages = defineMessages({
|
||||
error404Message: {
|
||||
id: 'learner-dash.notices.error404Message',
|
||||
defaultMessage: 'This probably happened because the notices plugin is not installed on platform.',
|
||||
description: 'Error message when notices API returns 404',
|
||||
},
|
||||
});
|
||||
|
||||
export default messages;
|
||||
31
src/components/__snapshots__/Banner.test.jsx.snap
Normal file
31
src/components/__snapshots__/Banner.test.jsx.snap
Normal file
@@ -0,0 +1,31 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Banner snapshot renders default banner 1`] = `
|
||||
<Alert
|
||||
className="mb-0"
|
||||
icon={[MockFunction icons.Info]}
|
||||
variant="info"
|
||||
>
|
||||
Hello, world!
|
||||
</Alert>
|
||||
`;
|
||||
|
||||
exports[`Banner snapshot renders with custom class 1`] = `
|
||||
<Alert
|
||||
className="custom-class"
|
||||
icon={[MockFunction icons.Info]}
|
||||
variant="info"
|
||||
>
|
||||
Hello, world!
|
||||
</Alert>
|
||||
`;
|
||||
|
||||
exports[`Banner snapshot renders with variants 1`] = `
|
||||
<Alert
|
||||
className="mb-0"
|
||||
icon={[MockFunction icons.Info]}
|
||||
variant="success"
|
||||
>
|
||||
Hello, world!
|
||||
</Alert>
|
||||
`;
|
||||
@@ -1,9 +1,7 @@
|
||||
const configuration = {
|
||||
// BASE_URL: process.env.BASE_URL,
|
||||
APP_ID: process.env.APP_ID,
|
||||
LMS_BASE_URL: process.env.LMS_BASE_URL,
|
||||
ECOMMERCE_BASE_URL: process.env.ECOMMERCE_BASE_URL,
|
||||
CREDIT_PURCHASE_URL: process.env.CREDIT_PURCHASE_URL,
|
||||
// LOGIN_URL: process.env.LOGIN_URL,
|
||||
// LOGOUT_URL: process.env.LOGOUT_URL,
|
||||
// CSRF_TOKEN_API_PATH: process.env.CSRF_TOKEN_API_PATH,
|
||||
@@ -15,13 +13,13 @@ const configuration = {
|
||||
LEARNING_BASE_URL: process.env.LEARNING_BASE_URL,
|
||||
SESSION_COOKIE_DOMAIN: process.env.SESSION_COOKIE_DOMAIN || '',
|
||||
SUPPORT_URL: process.env.SUPPORT_URL || null,
|
||||
ENABLE_NOTICES: process.env.ENABLE_NOTICES || null,
|
||||
CAREER_LINK_URL: process.env.CAREER_LINK_URL || null,
|
||||
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 === 'true',
|
||||
NON_BROWSABLE_COURSES: process.env.NON_BROWSABLE_COURSES === 'true',
|
||||
SHOW_UNENROLL_SURVEY: process.env.SHOW_UNENROLL_SURVEY === 'true',
|
||||
};
|
||||
|
||||
const features = {};
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import AppWrapper from './index';
|
||||
|
||||
describe('AppWrapper', () => {
|
||||
it('should render children without modification', () => {
|
||||
render(
|
||||
<AppWrapper>
|
||||
<div>Test Child</div>
|
||||
</AppWrapper>,
|
||||
);
|
||||
|
||||
expect(screen.getByText('Test Child')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,10 @@
|
||||
@import "@openedx/paragon/scss/core/core";
|
||||
|
||||
.course-card {
|
||||
.card {
|
||||
.pgn__card-wrapper-image-cap.vertical {
|
||||
display: flex;
|
||||
min-height: var(--pgn-size-card-image-vertical-max-height);
|
||||
min-height: $card-image-vertical-max-height;
|
||||
}
|
||||
.pgn__card-image-cap {
|
||||
border-bottom-left-radius: 0 !important;
|
||||
@@ -51,11 +53,11 @@
|
||||
> .alert {
|
||||
border-radius: 0;
|
||||
box-shadow: none;
|
||||
padding: var(--pgn-spacing-spacer-3) var(--pgn-spacing-spacer-4);
|
||||
padding: map-get($spacers, 3) map-get($spacers, 4);
|
||||
|
||||
&:last-of-type {
|
||||
border-bottom-left-radius: var(--pgn-size-alert-border-radius);
|
||||
border-bottom-right-radius: var(--pgn-size-alert-border-radius);
|
||||
border-bottom-left-radius: $alert-border-radius;
|
||||
border-bottom-right-radius: $alert-border-radius;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
111
src/containers/CourseCard/__snapshots__/index.test.jsx.snap
Normal file
111
src/containers/CourseCard/__snapshots__/index.test.jsx.snap
Normal file
@@ -0,0 +1,111 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`CourseCard component snapshot: collapsed 1`] = `
|
||||
<div
|
||||
className="mb-4.5 course-card"
|
||||
data-testid="CourseCard"
|
||||
id="test-card-id"
|
||||
>
|
||||
<Card
|
||||
orientation="vertical"
|
||||
>
|
||||
<div
|
||||
className="d-flex flex-column w-100"
|
||||
>
|
||||
<div>
|
||||
<CourseCardImage
|
||||
cardId="test-card-id"
|
||||
orientation="horizontal"
|
||||
/>
|
||||
<Card.Body>
|
||||
<Card.Header
|
||||
actions={
|
||||
<CourseCardMenu
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
}
|
||||
title={
|
||||
<CourseCardTitle
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<Card.Section
|
||||
className="pt-0"
|
||||
>
|
||||
<CourseCardDetails
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
</Card.Section>
|
||||
<Card.Footer
|
||||
orientation="vertical"
|
||||
>
|
||||
<CourseCardActions
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
</Card.Footer>
|
||||
</Card.Body>
|
||||
</div>
|
||||
<CourseCardBanners
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`CourseCard component snapshot: not collapsed 1`] = `
|
||||
<div
|
||||
className="mb-4.5 course-card"
|
||||
data-testid="CourseCard"
|
||||
id="test-card-id"
|
||||
>
|
||||
<Card
|
||||
orientation="horizontal"
|
||||
>
|
||||
<div
|
||||
className="d-flex flex-column w-100"
|
||||
>
|
||||
<div
|
||||
className="d-flex"
|
||||
>
|
||||
<CourseCardImage
|
||||
cardId="test-card-id"
|
||||
orientation="horizontal"
|
||||
/>
|
||||
<Card.Body>
|
||||
<Card.Header
|
||||
actions={
|
||||
<CourseCardMenu
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
}
|
||||
title={
|
||||
<CourseCardTitle
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<Card.Section
|
||||
className="pt-0"
|
||||
>
|
||||
<CourseCardDetails
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
</Card.Section>
|
||||
<Card.Footer
|
||||
orientation="horizontal"
|
||||
>
|
||||
<CourseCardActions
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
</Card.Footer>
|
||||
</Card.Body>
|
||||
</div>
|
||||
<CourseCardBanners
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
`;
|
||||
@@ -0,0 +1,14 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`ActionButton snapshot is collapsed 1`] = `
|
||||
<Button
|
||||
arbitary="props"
|
||||
size="sm"
|
||||
/>
|
||||
`;
|
||||
|
||||
exports[`ActionButton snapshot is not collapsed 1`] = `
|
||||
<Button
|
||||
arbitary="props"
|
||||
/>
|
||||
`;
|
||||
@@ -1,33 +1,6 @@
|
||||
import { useWindowSize, breakpoints } from '@openedx/paragon';
|
||||
import useIsCollapsed from './hooks';
|
||||
|
||||
jest.mock('@openedx/paragon', () => ({
|
||||
...jest.requireActual('@openedx/paragon'),
|
||||
useWindowSize: jest.fn(),
|
||||
breakpoints: {
|
||||
extraSmall: {
|
||||
minWidth: 0,
|
||||
maxWidth: 575,
|
||||
},
|
||||
small: {
|
||||
minWidth: 576,
|
||||
maxWidth: 767,
|
||||
},
|
||||
medium: {
|
||||
minWidth: 768,
|
||||
maxWidth: 991,
|
||||
},
|
||||
large: {
|
||||
minWidth: 992,
|
||||
maxWidth: 1199,
|
||||
},
|
||||
extraLarge: {
|
||||
minWidth: 1200,
|
||||
maxWidth: 100000,
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
describe('useIsCollapsed', () => {
|
||||
it('returns true only when it is between medium and small', () => {
|
||||
// make sure all three breakpoints gap is large enough for test
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import ActionButton from '.';
|
||||
|
||||
import useIsCollapsed from './hooks';
|
||||
@@ -7,22 +8,18 @@ jest.mock('./hooks', () => jest.fn());
|
||||
|
||||
describe('ActionButton', () => {
|
||||
const props = {
|
||||
className: 'custom-class',
|
||||
children: 'Test',
|
||||
arbitary: 'props',
|
||||
};
|
||||
|
||||
it('is collapsed', async () => {
|
||||
useIsCollapsed.mockReturnValue(true);
|
||||
render(<ActionButton {...props} />);
|
||||
const button = screen.getByRole('button', { name: 'Test' });
|
||||
expect(button).toHaveClass('btn-sm', 'custom-class');
|
||||
});
|
||||
|
||||
it('is not collapsed', () => {
|
||||
useIsCollapsed.mockReturnValue(false);
|
||||
render(<ActionButton {...props} />);
|
||||
const button = screen.getByRole('button', { name: 'Test' });
|
||||
expect(button).toBeInTheDocument();
|
||||
expect(button).not.toHaveClass('size', 'sm');
|
||||
describe('snapshot', () => {
|
||||
test('is collapsed', () => {
|
||||
useIsCollapsed.mockReturnValueOnce(true);
|
||||
const wrapper = shallow(<ActionButton {...props} />);
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
test('is not collapsed', () => {
|
||||
useIsCollapsed.mockReturnValueOnce(false);
|
||||
const wrapper = shallow(<ActionButton {...props} />);
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,29 +1,21 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
import { EXECUTIVE_EDUCATION_COURSE_MODES } from 'data/constants/course';
|
||||
|
||||
import track from 'tracking';
|
||||
import { useCourseData, useCourseTrackingEvent } from 'hooks';
|
||||
import { useInitializeLearnerHome } from 'data/hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import useActionDisabledState from '../hooks';
|
||||
import ActionButton from './ActionButton';
|
||||
import messages from './messages';
|
||||
|
||||
export const BeginCourseButton = ({ cardId }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const { data: learnerData } = useInitializeLearnerHome();
|
||||
const courseData = useCourseData(cardId);
|
||||
const homeUrl = courseData?.courseRun?.homeUrl;
|
||||
const execEdTrackingParam = useMemo(() => {
|
||||
const isExecEd2UCourse = EXECUTIVE_EDUCATION_COURSE_MODES.includes(courseData.enrollment.mode);
|
||||
const { authOrgId } = learnerData.enterpriseDashboard || {};
|
||||
return isExecEd2UCourse ? `?org_id=${authOrgId}` : '';
|
||||
}, [courseData.enrollment.mode, learnerData.enterpriseDashboard]);
|
||||
const { homeUrl } = reduxHooks.useCardCourseRunData(cardId);
|
||||
const execEdTrackingParam = reduxHooks.useCardExecEdTrackingParam(cardId);
|
||||
const { disableBeginCourse } = useActionDisabledState(cardId);
|
||||
|
||||
const handleClick = useCourseTrackingEvent(
|
||||
const handleClick = reduxHooks.useTrackCourseEvent(
|
||||
track.course.enterCourseClicked,
|
||||
cardId,
|
||||
homeUrl + execEdTrackingParam,
|
||||
|
||||
@@ -1,90 +1,85 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { reduxHooks } from 'hooks';
|
||||
import track from 'tracking';
|
||||
import { useCourseData, useCourseTrackingEvent } from 'hooks';
|
||||
import useActionDisabledState from '../hooks';
|
||||
import BeginCourseButton from './BeginCourseButton';
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
useCourseData: jest.fn().mockReturnValue({
|
||||
enrollment: { mode: 'executive-education' },
|
||||
courseRun: { homeUrl: 'home-url' },
|
||||
}),
|
||||
useCourseTrackingEvent: jest.fn().mockReturnValue({
|
||||
trackCourseEvent: jest.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
jest.mock('data/hooks', () => ({
|
||||
useInitializeLearnerHome: jest.fn().mockReturnValue({
|
||||
data: {
|
||||
enterpriseDashboard: {
|
||||
authOrgId: 'test-org-id',
|
||||
},
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
jest.mock('tracking', () => ({
|
||||
course: {
|
||||
enterCourseClicked: jest.fn().mockName('segment.enterCourseClicked'),
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
reduxHooks: {
|
||||
useCardCourseRunData: jest.fn(),
|
||||
useCardExecEdTrackingParam: jest.fn(),
|
||||
useTrackCourseEvent: jest.fn(),
|
||||
},
|
||||
}));
|
||||
jest.mock('../hooks', () => jest.fn(() => ({ disableBeginCourse: false })));
|
||||
jest.mock('./ActionButton', () => 'ActionButton');
|
||||
|
||||
jest.mock('./ActionButton/hooks', () => jest.fn(() => false));
|
||||
|
||||
let wrapper;
|
||||
const homeUrl = 'home-url';
|
||||
|
||||
const props = {
|
||||
cardId: 'cardId',
|
||||
};
|
||||
|
||||
const renderComponent = () => render(<IntlProvider locale="en"><BeginCourseButton {...props} /></IntlProvider>);
|
||||
reduxHooks.useCardCourseRunData.mockReturnValue({ homeUrl });
|
||||
const execEdPath = (cardId) => `exec-ed-tracking-path=${cardId}`;
|
||||
reduxHooks.useCardExecEdTrackingParam.mockImplementation(execEdPath);
|
||||
reduxHooks.useTrackCourseEvent.mockImplementation(
|
||||
(eventName, cardId, url) => ({ trackCourseEvent: { eventName, cardId, url } }),
|
||||
);
|
||||
|
||||
describe('BeginCourseButton', () => {
|
||||
const props = {
|
||||
cardId: 'cardId',
|
||||
};
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
describe('initiliaze hooks', () => {
|
||||
describe('behavior', () => {
|
||||
it('initializes course run data with cardId', () => {
|
||||
renderComponent();
|
||||
expect(useCourseData).toHaveBeenCalledWith(props.cardId);
|
||||
wrapper = shallow(<BeginCourseButton {...props} />);
|
||||
expect(reduxHooks.useCardCourseRunData).toHaveBeenCalledWith(props.cardId);
|
||||
});
|
||||
it('loads exec education path param', () => {
|
||||
wrapper = shallow(<BeginCourseButton {...props} />);
|
||||
expect(reduxHooks.useCardExecEdTrackingParam).toHaveBeenCalledWith(props.cardId);
|
||||
});
|
||||
it('loads disabled states for begin action from action hooks', () => {
|
||||
renderComponent();
|
||||
wrapper = shallow(<BeginCourseButton {...props} />);
|
||||
expect(useActionDisabledState).toHaveBeenCalledWith(props.cardId);
|
||||
});
|
||||
});
|
||||
describe('behavior', () => {
|
||||
describe('snapshot', () => {
|
||||
describe('disabled', () => {
|
||||
it('should be disabled', () => {
|
||||
beforeEach(() => {
|
||||
useActionDisabledState.mockReturnValueOnce({ disableBeginCourse: true });
|
||||
renderComponent();
|
||||
const button = screen.getByRole('button', { name: 'Begin Course' });
|
||||
expect(button).toHaveClass('disabled');
|
||||
expect(button).toHaveAttribute('aria-disabled', 'true');
|
||||
wrapper = shallow(<BeginCourseButton {...props} />);
|
||||
});
|
||||
test('snapshot', () => {
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
it('should be disabled', () => {
|
||||
expect(wrapper.instance.props.disabled).toEqual(true);
|
||||
});
|
||||
});
|
||||
describe('enabled', () => {
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(<BeginCourseButton {...props} />);
|
||||
});
|
||||
test('snapshot', () => {
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
it('should be enabled', () => {
|
||||
renderComponent();
|
||||
const button = screen.getByRole('button', { name: 'Begin Course' });
|
||||
expect(button).not.toHaveClass('disabled');
|
||||
expect(button).not.toHaveAttribute('aria-disabled', 'true');
|
||||
expect(wrapper.instance.props.disabled).toEqual(false);
|
||||
});
|
||||
it('should track enter course clicked event on click, with exec ed param', () => {
|
||||
renderComponent();
|
||||
const user = userEvent.setup();
|
||||
const button = screen.getByRole('button', { name: 'Begin Course' });
|
||||
user.click(button);
|
||||
expect(useCourseTrackingEvent).toHaveBeenCalledWith(
|
||||
expect(wrapper.instance.props.onClick).toEqual(reduxHooks.useTrackCourseEvent(
|
||||
track.course.enterCourseClicked,
|
||||
props.cardId,
|
||||
`${homeUrl}?org_id=test-org-id`,
|
||||
);
|
||||
homeUrl + execEdPath(props.cardId),
|
||||
));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,29 +1,21 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
|
||||
import { EXECUTIVE_EDUCATION_COURSE_MODES } from 'data/constants/course';
|
||||
import track from 'tracking';
|
||||
import { useCourseTrackingEvent, useCourseData } from 'hooks';
|
||||
import { useInitializeLearnerHome } from 'data/hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import useActionDisabledState from '../hooks';
|
||||
import ActionButton from './ActionButton';
|
||||
import messages from './messages';
|
||||
|
||||
export const ResumeButton = ({ cardId }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const { data: learnerData } = useInitializeLearnerHome();
|
||||
const courseData = useCourseData(cardId);
|
||||
const resumeUrl = courseData?.courseRun?.resumeUrl;
|
||||
const execEdTrackingParam = useMemo(() => {
|
||||
const isExecEd2UCourse = EXECUTIVE_EDUCATION_COURSE_MODES.includes(courseData.enrollment.mode);
|
||||
const { authOrgId } = learnerData.enterpriseDashboard || {};
|
||||
return isExecEd2UCourse ? `?org_id=${authOrgId}` : '';
|
||||
}, [courseData.enrollment.mode, learnerData.enterpriseDashboard]);
|
||||
const { resumeUrl } = reduxHooks.useCardCourseRunData(cardId);
|
||||
const execEdTrackingParam = reduxHooks.useCardExecEdTrackingParam(cardId);
|
||||
const { disableResumeCourse } = useActionDisabledState(cardId);
|
||||
|
||||
const handleClick = useCourseTrackingEvent(
|
||||
const handleClick = reduxHooks.useTrackCourseEvent(
|
||||
track.course.enterCourseClicked,
|
||||
cardId,
|
||||
resumeUrl + execEdTrackingParam,
|
||||
|
||||
@@ -1,91 +1,83 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import { useCourseTrackingEvent, useCourseData } from 'hooks';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { reduxHooks } from 'hooks';
|
||||
import track from 'tracking';
|
||||
import useActionDisabledState from '../hooks';
|
||||
import ResumeButton from './ResumeButton';
|
||||
|
||||
const authOrgId = 'auth-org-id';
|
||||
jest.mock('data/hooks', () => ({
|
||||
useInitializeLearnerHome: jest.fn().mockReturnValue({
|
||||
data: {
|
||||
enterpriseDashboard: {
|
||||
authOrgId,
|
||||
},
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
useCourseData: jest.fn().mockReturnValue({
|
||||
enrollment: { mode: 'executive-education' },
|
||||
courseRun: { homeUrl: 'home-url' },
|
||||
}),
|
||||
useCourseTrackingEvent: jest.fn().mockReturnValue({
|
||||
trackCourseEvent: jest.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
jest.mock('tracking', () => ({
|
||||
course: {
|
||||
enterCourseClicked: jest.fn().mockName('segment.enterCourseClicked'),
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
reduxHooks: {
|
||||
useCardCourseRunData: jest.fn(),
|
||||
useCardExecEdTrackingParam: jest.fn(),
|
||||
useTrackCourseEvent: jest.fn(),
|
||||
},
|
||||
}));
|
||||
jest.mock('../hooks', () => jest.fn(() => ({ disableResumeCourse: false })));
|
||||
jest.mock('./ActionButton', () => 'ActionButton');
|
||||
|
||||
jest.mock('./ActionButton/hooks', () => jest.fn(() => false));
|
||||
const resumeUrl = 'resume-url';
|
||||
reduxHooks.useCardCourseRunData.mockReturnValue({ resumeUrl });
|
||||
const execEdPath = (cardId) => `exec-ed-tracking-path=${cardId}`;
|
||||
reduxHooks.useCardExecEdTrackingParam.mockImplementation(execEdPath);
|
||||
reduxHooks.useTrackCourseEvent.mockImplementation(
|
||||
(eventName, cardId, url) => ({ trackCourseEvent: { eventName, cardId, url } }),
|
||||
);
|
||||
|
||||
useCourseData.mockReturnValue({
|
||||
enrollment: { mode: 'executive-education' },
|
||||
courseRun: { resumeUrl: 'home-url' },
|
||||
});
|
||||
let wrapper;
|
||||
|
||||
describe('ResumeButton', () => {
|
||||
const props = {
|
||||
cardId: 'cardId',
|
||||
};
|
||||
describe('initialize hooks', () => {
|
||||
beforeEach(() => render(<IntlProvider locale="en"><ResumeButton {...props} /></IntlProvider>));
|
||||
describe('behavior', () => {
|
||||
it('initializes course run data with cardId', () => {
|
||||
expect(useCourseData).toHaveBeenCalledWith(props.cardId);
|
||||
wrapper = shallow(<ResumeButton {...props} />);
|
||||
expect(reduxHooks.useCardCourseRunData).toHaveBeenCalledWith(props.cardId);
|
||||
});
|
||||
it('loads exec education path param', () => {
|
||||
wrapper = shallow(<ResumeButton {...props} />);
|
||||
expect(reduxHooks.useCardExecEdTrackingParam).toHaveBeenCalledWith(props.cardId);
|
||||
});
|
||||
it('loads disabled states for resume action from action hooks', () => {
|
||||
wrapper = shallow(<ResumeButton {...props} />);
|
||||
expect(useActionDisabledState).toHaveBeenCalledWith(props.cardId);
|
||||
});
|
||||
});
|
||||
describe('behavior', () => {
|
||||
describe('snapshot', () => {
|
||||
describe('disabled', () => {
|
||||
beforeEach(() => {
|
||||
useActionDisabledState.mockReturnValueOnce({ disableResumeCourse: true });
|
||||
wrapper = shallow(<ResumeButton {...props} />);
|
||||
});
|
||||
test('snapshot', () => {
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
it('should be disabled', () => {
|
||||
render(<IntlProvider locale="en"><ResumeButton {...props} /></IntlProvider>);
|
||||
const button = screen.getByRole('button', { name: 'Resume' });
|
||||
expect(button).toHaveClass('disabled');
|
||||
expect(button).toHaveAttribute('aria-disabled', 'true');
|
||||
expect(wrapper.instance.props.disabled).toEqual(true);
|
||||
});
|
||||
});
|
||||
describe('enabled', () => {
|
||||
it('should be enabled', () => {
|
||||
render(<IntlProvider locale="en"><ResumeButton {...props} /></IntlProvider>);
|
||||
const button = screen.getByRole('button', { name: 'Resume' });
|
||||
expect(button).toBeInTheDocument();
|
||||
expect(button).not.toHaveClass('disabled');
|
||||
expect(button).not.toHaveAttribute('aria-disabled', 'true');
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(<ResumeButton {...props} />);
|
||||
});
|
||||
it('should track enter course clicked event on click, with exec ed param', async () => {
|
||||
render(<IntlProvider locale="en"><ResumeButton {...props} /></IntlProvider>);
|
||||
const user = userEvent.setup();
|
||||
const button = screen.getByRole('button', { name: 'Resume' });
|
||||
user.click(button);
|
||||
expect(useCourseTrackingEvent).toHaveBeenCalledWith(
|
||||
test('snapshot', () => {
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
it('should be enabled', () => {
|
||||
expect(wrapper.instance.props.disabled).toEqual(false);
|
||||
});
|
||||
it('should track enter course clicked event on click, with exec ed param', () => {
|
||||
expect(wrapper.instance.props.onClick).toEqual(reduxHooks.useTrackCourseEvent(
|
||||
track.course.enterCourseClicked,
|
||||
props.cardId,
|
||||
`home-url?org_id=${authOrgId}`,
|
||||
);
|
||||
resumeUrl + execEdPath(props.cardId),
|
||||
));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
||||
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
|
||||
import { useSelectSessionModal } from 'data/context';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import useActionDisabledState from '../hooks';
|
||||
import ActionButton from './ActionButton';
|
||||
import messages from './messages';
|
||||
@@ -11,11 +11,11 @@ import messages from './messages';
|
||||
export const SelectSessionButton = ({ cardId }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const { disableSelectSession } = useActionDisabledState(cardId);
|
||||
const { updateSelectSessionModal } = useSelectSessionModal();
|
||||
const openSessionModal = reduxHooks.useUpdateSelectSessionModalCallback(cardId);
|
||||
return (
|
||||
<ActionButton
|
||||
disabled={disableSelectSession}
|
||||
onClick={() => updateSelectSessionModal(cardId)}
|
||||
onClick={openSessionModal}
|
||||
>
|
||||
{formatMessage(messages.selectSession)}
|
||||
</ActionButton>
|
||||
|
||||
@@ -1,47 +1,34 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import { useSelectSessionModal } from 'data/context';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { reduxHooks } from 'hooks';
|
||||
import useActionDisabledState from '../hooks';
|
||||
|
||||
import SelectSessionButton from './SelectSessionButton';
|
||||
|
||||
jest.mock('data/context', () => ({
|
||||
useSelectSessionModal: jest.fn().mockReturnValue({
|
||||
updateSelectSessionModal: jest.fn(),
|
||||
}),
|
||||
jest.mock('hooks', () => ({
|
||||
reduxHooks: {
|
||||
useUpdateSelectSessionModalCallback: () => jest.fn().mockName('mockOpenSessionModal'),
|
||||
},
|
||||
}));
|
||||
jest.mock('../hooks', () => jest.fn(() => ({ disableSelectSession: false })));
|
||||
jest.mock('./ActionButton', () => 'ActionButton');
|
||||
|
||||
jest.mock('./ActionButton/hooks', () => jest.fn(() => false));
|
||||
let wrapper;
|
||||
|
||||
describe('SelectSessionButton', () => {
|
||||
const props = { cardId: 'cardId' };
|
||||
it('default render', () => {
|
||||
render(<IntlProvider locale="en"><SelectSessionButton {...props} /></IntlProvider>);
|
||||
const button = screen.getByRole('button', { name: 'Select Session' });
|
||||
expect(button).toBeInTheDocument();
|
||||
wrapper = shallow(<SelectSessionButton {...props} />);
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
expect(wrapper.instance.props.disabled).toEqual(false);
|
||||
expect(wrapper.instance.props.onClick.getMockName()).toEqual(
|
||||
reduxHooks.useUpdateSelectSessionModalCallback().getMockName(),
|
||||
);
|
||||
});
|
||||
describe('if useActionDisabledState is false', () => {
|
||||
it('should disabled Select Session', () => {
|
||||
useActionDisabledState.mockReturnValueOnce({ disableSelectSession: true });
|
||||
render(<IntlProvider locale="en"><SelectSessionButton {...props} /></IntlProvider>);
|
||||
const button = screen.getByRole('button', { name: 'Select Session' });
|
||||
expect(button).toBeDisabled();
|
||||
});
|
||||
});
|
||||
describe('on click', () => {
|
||||
it('should call openSessionModal', async () => {
|
||||
const mockedUpdateSelectSessionModal = jest.fn();
|
||||
useSelectSessionModal.mockReturnValue({
|
||||
updateSelectSessionModal: mockedUpdateSelectSessionModal,
|
||||
});
|
||||
render(<IntlProvider locale="en"><SelectSessionButton {...props} /></IntlProvider>);
|
||||
const user = userEvent.setup();
|
||||
const button = screen.getByRole('button', { name: 'Select Session' });
|
||||
await user.click(button);
|
||||
expect(mockedUpdateSelectSessionModal).toHaveBeenCalledWith(props.cardId);
|
||||
});
|
||||
test('disabled states', () => {
|
||||
useActionDisabledState.mockReturnValueOnce({ disableSelectSession: true });
|
||||
wrapper = shallow(<SelectSessionButton {...props} />);
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
expect(wrapper.instance.props.disabled).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,18 +4,17 @@ import PropTypes from 'prop-types';
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
|
||||
import track from 'tracking';
|
||||
import { useCourseTrackingEvent, useCourseData } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import useActionDisabledState from '../hooks';
|
||||
import ActionButton from './ActionButton';
|
||||
import messages from './messages';
|
||||
|
||||
export const ViewCourseButton = ({ cardId }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const courseData = useCourseData(cardId);
|
||||
const homeUrl = courseData?.courseRun?.homeUrl;
|
||||
const { homeUrl } = reduxHooks.useCardCourseRunData(cardId);
|
||||
const { disableViewCourse } = useActionDisabledState(cardId);
|
||||
|
||||
const handleClick = useCourseTrackingEvent(
|
||||
const handleClick = reduxHooks.useTrackCourseEvent(
|
||||
track.course.enterCourseClicked,
|
||||
cardId,
|
||||
homeUrl,
|
||||
|
||||
@@ -1,61 +1,45 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import { useCourseTrackingEvent } from 'hooks';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import track from 'tracking';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import useActionDisabledState from '../hooks';
|
||||
import ViewCourseButton from './ViewCourseButton';
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
useCourseData: jest.fn().mockReturnValue({
|
||||
courseRun: { homeUrl: 'homeUrl' },
|
||||
}),
|
||||
useCourseTrackingEvent: jest.fn().mockReturnValue({
|
||||
trackCourseEvent: jest.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
jest.mock('tracking', () => ({
|
||||
course: {
|
||||
enterCourseClicked: jest.fn().mockName('segment.enterCourseClicked'),
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
reduxHooks: {
|
||||
useCardCourseRunData: jest.fn(() => ({ homeUrl: 'homeUrl' })),
|
||||
useTrackCourseEvent: jest.fn(
|
||||
(eventName, cardId, url) => ({ trackCourseEvent: { eventName, cardId, url } }),
|
||||
),
|
||||
},
|
||||
}));
|
||||
jest.mock('../hooks', () => jest.fn(() => ({ disableViewCourse: false })));
|
||||
|
||||
jest.mock('./ActionButton/hooks', () => jest.fn(() => false));
|
||||
jest.mock('./ActionButton', () => 'ActionButton');
|
||||
|
||||
const defaultProps = { cardId: 'cardId' };
|
||||
const homeUrl = 'homeUrl';
|
||||
|
||||
describe('ViewCourseButton', () => {
|
||||
it('learner can view course', async () => {
|
||||
render(<IntlProvider locale="en"><ViewCourseButton {...defaultProps} /></IntlProvider>);
|
||||
const button = screen.getByRole('button', { name: 'View Course' });
|
||||
expect(button).toBeInTheDocument();
|
||||
expect(button).not.toHaveClass('disabled');
|
||||
expect(button).not.toHaveAttribute('aria-disabled', 'true');
|
||||
});
|
||||
it('calls trackCourseEvent on click', async () => {
|
||||
const mockedTrackCourseEvent = jest.fn();
|
||||
useCourseTrackingEvent.mockReturnValue(mockedTrackCourseEvent);
|
||||
render(<IntlProvider locale="en"><ViewCourseButton {...defaultProps} /></IntlProvider>);
|
||||
const user = userEvent.setup();
|
||||
const button = screen.getByRole('button', { name: 'View Course' });
|
||||
await user.click(button);
|
||||
expect(useCourseTrackingEvent).toHaveBeenCalledWith(
|
||||
test('learner can view course', () => {
|
||||
const wrapper = shallow(<ViewCourseButton {...defaultProps} />);
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
expect(wrapper.instance.props.onClick).toEqual(reduxHooks.useTrackCourseEvent(
|
||||
track.course.enterCourseClicked,
|
||||
defaultProps.cardId,
|
||||
homeUrl,
|
||||
);
|
||||
expect(mockedTrackCourseEvent).toHaveBeenCalled();
|
||||
));
|
||||
expect(wrapper.instance.props.disabled).toEqual(false);
|
||||
});
|
||||
it('learner cannot view course', () => {
|
||||
test('learner cannot view course', () => {
|
||||
useActionDisabledState.mockReturnValueOnce({ disableViewCourse: true });
|
||||
render(<IntlProvider locale="en"><ViewCourseButton {...defaultProps} /></IntlProvider>);
|
||||
const button = screen.getByRole('button', { name: 'View Course' });
|
||||
expect(button).toHaveClass('disabled');
|
||||
expect(button).toHaveAttribute('aria-disabled', 'true');
|
||||
const wrapper = shallow(<ViewCourseButton {...defaultProps} />);
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
expect(wrapper.instance.props.disabled).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`BeginCourseButton snapshot disabled snapshot 1`] = `
|
||||
<ActionButton
|
||||
as="a"
|
||||
disabled={true}
|
||||
href="#"
|
||||
onClick={
|
||||
{
|
||||
"trackCourseEvent": {
|
||||
"cardId": "cardId",
|
||||
"eventName": [MockFunction segment.enterCourseClicked],
|
||||
"url": "home-urlexec-ed-tracking-path=cardId",
|
||||
},
|
||||
}
|
||||
}
|
||||
>
|
||||
Begin Course
|
||||
</ActionButton>
|
||||
`;
|
||||
|
||||
exports[`BeginCourseButton snapshot enabled snapshot 1`] = `
|
||||
<ActionButton
|
||||
as="a"
|
||||
disabled={false}
|
||||
href="#"
|
||||
onClick={
|
||||
{
|
||||
"trackCourseEvent": {
|
||||
"cardId": "cardId",
|
||||
"eventName": [MockFunction segment.enterCourseClicked],
|
||||
"url": "home-urlexec-ed-tracking-path=cardId",
|
||||
},
|
||||
}
|
||||
}
|
||||
>
|
||||
Begin Course
|
||||
</ActionButton>
|
||||
`;
|
||||
@@ -0,0 +1,39 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`ResumeButton snapshot disabled snapshot 1`] = `
|
||||
<ActionButton
|
||||
as="a"
|
||||
disabled={true}
|
||||
href="#"
|
||||
onClick={
|
||||
{
|
||||
"trackCourseEvent": {
|
||||
"cardId": "cardId",
|
||||
"eventName": [MockFunction segment.enterCourseClicked],
|
||||
"url": "resume-urlexec-ed-tracking-path=cardId",
|
||||
},
|
||||
}
|
||||
}
|
||||
>
|
||||
Resume
|
||||
</ActionButton>
|
||||
`;
|
||||
|
||||
exports[`ResumeButton snapshot enabled snapshot 1`] = `
|
||||
<ActionButton
|
||||
as="a"
|
||||
disabled={false}
|
||||
href="#"
|
||||
onClick={
|
||||
{
|
||||
"trackCourseEvent": {
|
||||
"cardId": "cardId",
|
||||
"eventName": [MockFunction segment.enterCourseClicked],
|
||||
"url": "resume-urlexec-ed-tracking-path=cardId",
|
||||
},
|
||||
}
|
||||
}
|
||||
>
|
||||
Resume
|
||||
</ActionButton>
|
||||
`;
|
||||
@@ -0,0 +1,19 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`SelectSessionButton default render 1`] = `
|
||||
<ActionButton
|
||||
disabled={false}
|
||||
onClick={[MockFunction mockOpenSessionModal]}
|
||||
>
|
||||
Select Session
|
||||
</ActionButton>
|
||||
`;
|
||||
|
||||
exports[`SelectSessionButton disabled states 1`] = `
|
||||
<ActionButton
|
||||
disabled={true}
|
||||
onClick={[MockFunction mockOpenSessionModal]}
|
||||
>
|
||||
Select Session
|
||||
</ActionButton>
|
||||
`;
|
||||
@@ -0,0 +1,39 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`ViewCourseButton learner can view course 1`] = `
|
||||
<ActionButton
|
||||
as="a"
|
||||
disabled={false}
|
||||
href="#"
|
||||
onClick={
|
||||
{
|
||||
"trackCourseEvent": {
|
||||
"cardId": "cardId",
|
||||
"eventName": [MockFunction segment.enterCourseClicked],
|
||||
"url": "homeUrl",
|
||||
},
|
||||
}
|
||||
}
|
||||
>
|
||||
View Course
|
||||
</ActionButton>
|
||||
`;
|
||||
|
||||
exports[`ViewCourseButton learner cannot view course 1`] = `
|
||||
<ActionButton
|
||||
as="a"
|
||||
disabled={true}
|
||||
href="#"
|
||||
onClick={
|
||||
{
|
||||
"trackCourseEvent": {
|
||||
"cardId": "cardId",
|
||||
"eventName": [MockFunction segment.enterCourseClicked],
|
||||
"url": "homeUrl",
|
||||
},
|
||||
}
|
||||
}
|
||||
>
|
||||
View Course
|
||||
</ActionButton>
|
||||
`;
|
||||
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
||||
|
||||
import { ActionRow } from '@openedx/paragon';
|
||||
|
||||
import { useCourseData, useEntitlementInfo } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
|
||||
import CourseCardActionSlot from 'plugin-slots/CourseCardActionSlot';
|
||||
import SelectSessionButton from './SelectSessionButton';
|
||||
@@ -12,10 +12,11 @@ import ResumeButton from './ResumeButton';
|
||||
import ViewCourseButton from './ViewCourseButton';
|
||||
|
||||
export const CourseCardActions = ({ cardId }) => {
|
||||
const cardData = useCourseData(cardId);
|
||||
const hasStarted = cardData.enrollment.hasStarted || false;
|
||||
const { isEntitlement, isFulfilled } = useEntitlementInfo(cardData);
|
||||
const isArchived = cardData.courseRun.isArchived || false;
|
||||
const { isEntitlement, isFulfilled } = reduxHooks.useCardEntitlementData(cardId);
|
||||
const {
|
||||
hasStarted,
|
||||
} = reduxHooks.useCardEnrollmentData(cardId);
|
||||
const { isArchived } = reduxHooks.useCardCourseRunData(cardId);
|
||||
|
||||
return (
|
||||
<ActionRow data-test-id="CourseCardActions">
|
||||
|
||||
@@ -1,84 +1,95 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { useCourseData } from 'hooks';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { reduxHooks } from 'hooks';
|
||||
|
||||
import CourseCardActionSlot from 'plugin-slots/CourseCardActionSlot';
|
||||
import SelectSessionButton from './SelectSessionButton';
|
||||
import BeginCourseButton from './BeginCourseButton';
|
||||
import ResumeButton from './ResumeButton';
|
||||
import ViewCourseButton from './ViewCourseButton';
|
||||
|
||||
import CourseCardActions from '.';
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
...jest.requireActual('hooks'),
|
||||
useCourseData: jest.fn(),
|
||||
reduxHooks: {
|
||||
useCardCourseRunData: jest.fn(),
|
||||
useCardEnrollmentData: jest.fn(),
|
||||
useCardEntitlementData: jest.fn(),
|
||||
useMasqueradeData: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('plugin-slots/CourseCardActionSlot', () => jest.fn(() => <div>CourseCardActionSlot</div>));
|
||||
jest.mock('./SelectSessionButton', () => jest.fn(() => <div>SelectSessionButton</div>));
|
||||
jest.mock('./ViewCourseButton', () => jest.fn(() => <div>ViewCourseButton</div>));
|
||||
jest.mock('./BeginCourseButton', () => jest.fn(() => <div>BeginCourseButton</div>));
|
||||
jest.mock('./ResumeButton', () => jest.fn(() => <div>ResumeButton</div>));
|
||||
jest.mock('plugin-slots/CourseCardActionSlot', () => 'CustomActionButton');
|
||||
jest.mock('./SelectSessionButton', () => 'SelectSessionButton');
|
||||
jest.mock('./ViewCourseButton', () => 'ViewCourseButton');
|
||||
jest.mock('./BeginCourseButton', () => 'BeginCourseButton');
|
||||
jest.mock('./ResumeButton', () => 'ResumeButton');
|
||||
|
||||
const cardId = 'test-card-id';
|
||||
const props = { cardId };
|
||||
|
||||
let el;
|
||||
describe('CourseCardActions', () => {
|
||||
const mockHooks = ({
|
||||
isEntitlement = false,
|
||||
isExecEd2UCourse = false,
|
||||
isFulfilled = false,
|
||||
isArchived = false,
|
||||
isVerified = false,
|
||||
hasStarted = false,
|
||||
isMasquerading = false,
|
||||
} = {}) => {
|
||||
useCourseData.mockReturnValueOnce({
|
||||
enrollment: { hasStarted },
|
||||
courseRun: { isArchived },
|
||||
entitlement: isEntitlement !== null ? { isEntitlement, isFulfilled } : null,
|
||||
});
|
||||
reduxHooks.useCardEntitlementData.mockReturnValueOnce({ isEntitlement, isFulfilled });
|
||||
reduxHooks.useCardCourseRunData.mockReturnValueOnce({ isArchived });
|
||||
reduxHooks.useCardEnrollmentData.mockReturnValueOnce({ isExecEd2UCourse, isVerified, hasStarted });
|
||||
reduxHooks.useMasqueradeData.mockReturnValueOnce({ isMasquerading });
|
||||
};
|
||||
const renderComponent = () => render(<CourseCardActions {...props} />);
|
||||
describe('hooks', () => {
|
||||
it('initializes hooks', () => {
|
||||
const render = () => {
|
||||
el = shallow(<CourseCardActions {...props} />);
|
||||
};
|
||||
describe('behavior', () => {
|
||||
it('initializes redux hooks', () => {
|
||||
mockHooks();
|
||||
renderComponent();
|
||||
expect(useCourseData).toHaveBeenCalledWith(cardId);
|
||||
render();
|
||||
expect(reduxHooks.useCardEntitlementData).toHaveBeenCalledWith(cardId);
|
||||
expect(reduxHooks.useCardEnrollmentData).toHaveBeenCalledWith(cardId);
|
||||
expect(reduxHooks.useCardCourseRunData).toHaveBeenCalledWith(cardId);
|
||||
});
|
||||
});
|
||||
describe('output', () => {
|
||||
describe('entitlement course', () => {
|
||||
it('renders ViewCourseButton if fulfilled', () => {
|
||||
mockHooks({ isEntitlement: true, isFulfilled: true });
|
||||
renderComponent();
|
||||
const ViewCourseButton = screen.getByText('ViewCourseButton');
|
||||
expect(ViewCourseButton).toBeInTheDocument();
|
||||
render();
|
||||
expect(el.instance.findByType(ViewCourseButton)[0].props.cardId).toEqual(cardId);
|
||||
});
|
||||
it('renders SelectSessionButton if not fulfilled', () => {
|
||||
mockHooks({ isEntitlement: true });
|
||||
renderComponent();
|
||||
const SelectSessionButton = screen.getByText('SelectSessionButton');
|
||||
expect(SelectSessionButton).toBeInTheDocument();
|
||||
render();
|
||||
expect(el.instance.findByType(SelectSessionButton)[0].props.cardId).toEqual(cardId);
|
||||
});
|
||||
});
|
||||
describe('not entitlement, verified, or exec ed', () => {
|
||||
it('renders CourseCardActionSlot and ViewCourseButton for archived courses', () => {
|
||||
mockHooks({ isArchived: true, isEntitlement: null });
|
||||
renderComponent();
|
||||
const CourseCardActionSlot = screen.getByText('CourseCardActionSlot');
|
||||
expect(CourseCardActionSlot).toBeInTheDocument();
|
||||
const ViewCourseButton = screen.getByText('ViewCourseButton');
|
||||
expect(ViewCourseButton).toBeInTheDocument();
|
||||
mockHooks({ isArchived: true });
|
||||
render();
|
||||
expect(el.instance.findByType(CourseCardActionSlot)[0].props.cardId).toEqual(cardId);
|
||||
expect(el.instance.findByType(ViewCourseButton)[0].props.cardId).toEqual(cardId);
|
||||
});
|
||||
describe('unstarted courses', () => {
|
||||
it('renders CourseCardActionSlot and BeginCourseButton', () => {
|
||||
mockHooks({ isEntitlement: null });
|
||||
renderComponent();
|
||||
const CourseCardActionSlot = screen.getByText('CourseCardActionSlot');
|
||||
expect(CourseCardActionSlot).toBeInTheDocument();
|
||||
const BeginCourseButton = screen.getByText('BeginCourseButton');
|
||||
expect(BeginCourseButton).toBeInTheDocument();
|
||||
mockHooks();
|
||||
render();
|
||||
expect(el.instance.findByType(CourseCardActionSlot)[0].props.cardId).toEqual(cardId);
|
||||
expect(el.instance.findByType(BeginCourseButton)[0].props.cardId).toEqual(cardId);
|
||||
});
|
||||
});
|
||||
describe('active courses (started, and not archived)', () => {
|
||||
it('renders CourseCardActionSlot and ResumeButton', () => {
|
||||
mockHooks({ hasStarted: true, isEntitlement: null });
|
||||
renderComponent();
|
||||
const CourseCardActionSlot = screen.getByText('CourseCardActionSlot');
|
||||
expect(CourseCardActionSlot).toBeInTheDocument();
|
||||
const ResumeButton = screen.getByText('ResumeButton');
|
||||
expect(ResumeButton).toBeInTheDocument();
|
||||
mockHooks({ hasStarted: true });
|
||||
render();
|
||||
expect(el.instance.findByType(CourseCardActionSlot)[0].props.cardId).toEqual(cardId);
|
||||
expect(el.instance.findByType(ResumeButton)[0].props.cardId).toEqual(cardId);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
/* eslint-disable max-len */
|
||||
import React, { useMemo } from 'react';
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { MailtoLink, Hyperlink } from '@openedx/paragon';
|
||||
import { CheckCircle } from '@openedx/paragon/icons';
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
import { baseAppUrl } from 'data/services/lms/urls';
|
||||
|
||||
import { useInitializeLearnerHome } from 'data/hooks';
|
||||
import { utilHooks, useCourseData } from 'hooks';
|
||||
import { utilHooks, reduxHooks } from 'hooks';
|
||||
import Banner from 'components/Banner';
|
||||
|
||||
import messages from './messages';
|
||||
@@ -16,32 +14,15 @@ import messages from './messages';
|
||||
const { useFormatDate } = utilHooks;
|
||||
|
||||
export const CertificateBanner = ({ cardId }) => {
|
||||
const { data: learnerHomeData } = useInitializeLearnerHome();
|
||||
const courseData = useCourseData(cardId);
|
||||
const certificate = reduxHooks.useCardCertificateData(cardId);
|
||||
const {
|
||||
certificate = {},
|
||||
isVerified = false,
|
||||
isAudit = false,
|
||||
isPassing = false,
|
||||
isArchived = false,
|
||||
minPassingGrade = 0,
|
||||
progressUrl = '',
|
||||
} = useMemo(() => ({
|
||||
isVerified: courseData?.enrollment?.isVerified,
|
||||
isAudit: courseData?.enrollment?.isAudit,
|
||||
certificate: courseData?.certificate || {},
|
||||
isPassing: courseData?.gradeData?.isPassing,
|
||||
isArchived: courseData?.courseRun?.isArchived,
|
||||
minPassingGrade: Math.floor((courseData?.courseRun?.minPassingGrade ?? 0) * 100),
|
||||
progressUrl: baseAppUrl(courseData?.courseRun?.progressUrl || ''),
|
||||
}), [courseData]);
|
||||
const { supportEmail, billingEmail } = useMemo(
|
||||
() => ({
|
||||
supportEmail: learnerHomeData?.platformSettings?.supportEmail,
|
||||
billingEmail: learnerHomeData?.platformSettings?.billingEmail,
|
||||
}),
|
||||
[learnerHomeData],
|
||||
);
|
||||
isAudit,
|
||||
isVerified,
|
||||
} = reduxHooks.useCardEnrollmentData(cardId);
|
||||
const { isPassing } = reduxHooks.useCardGradeData(cardId);
|
||||
const { isArchived } = reduxHooks.useCardCourseRunData(cardId);
|
||||
const { minPassingGrade, progressUrl } = reduxHooks.useCardCourseRunData(cardId);
|
||||
const { supportEmail, billingEmail } = reduxHooks.usePlatformSettingsData();
|
||||
const { formatMessage } = useIntl();
|
||||
const formatDate = useFormatDate();
|
||||
|
||||
@@ -94,7 +75,7 @@ export const CertificateBanner = ({ cardId }) => {
|
||||
</Banner>
|
||||
);
|
||||
}
|
||||
if (certificate.isEarned && new Date(certificate.availableDate) > new Date()) {
|
||||
if (certificate.isEarnedButUnavailable) {
|
||||
return (
|
||||
<Banner>
|
||||
{formatMessage(
|
||||
|
||||
@@ -1,49 +1,44 @@
|
||||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { useCourseData } from 'hooks';
|
||||
import { useInitializeLearnerHome } from 'data/hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import CertificateBanner from './CertificateBanner';
|
||||
import messages from './messages';
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
utilHooks: {
|
||||
useFormatDate: jest.fn(() => date => date),
|
||||
},
|
||||
useCourseData: jest.fn(),
|
||||
reduxHooks: {
|
||||
useCardCertificateData: jest.fn(),
|
||||
useCardCourseRunData: jest.fn(),
|
||||
useCardEnrollmentData: jest.fn(),
|
||||
useCardGradeData: jest.fn(),
|
||||
usePlatformSettingsData: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('data/hooks', () => ({
|
||||
useInitializeLearnerHome: jest.fn(),
|
||||
}));
|
||||
|
||||
const defaultCertificate = {
|
||||
availableDate: '10/20/3030',
|
||||
isRestricted: false,
|
||||
isDownloadable: false,
|
||||
isEarnedButUnavailable: false,
|
||||
};
|
||||
const defaultEnrollment = {
|
||||
isAudit: false,
|
||||
isVerified: false,
|
||||
};
|
||||
const defaultCourseRun = { isArchived: false };
|
||||
const defaultGrade = { isPassing: false };
|
||||
const defaultPlatformSettings = {};
|
||||
const props = { cardId: 'cardId' };
|
||||
const supportEmail = 'suport@email.com';
|
||||
const billingEmail = 'billing@email.com';
|
||||
jest.mock('components/Banner', () => 'Banner');
|
||||
|
||||
describe('CertificateBanner', () => {
|
||||
useCourseData.mockReturnValue({
|
||||
enrollment: {},
|
||||
certificate: {},
|
||||
gradeData: {},
|
||||
courseRun: {
|
||||
minPassingGrade: 0.8,
|
||||
progressUrl: 'progressUrl',
|
||||
},
|
||||
const props = { cardId: 'cardId' };
|
||||
reduxHooks.useCardCourseRunData.mockReturnValue({
|
||||
minPassingGrade: 0.8,
|
||||
progressUrl: 'progressUrl',
|
||||
});
|
||||
|
||||
const defaultCertificate = {
|
||||
availableDate: '10/20/3030',
|
||||
isRestricted: false,
|
||||
isDownloadable: false,
|
||||
isEarnedButUnavailable: false,
|
||||
};
|
||||
const defaultEnrollment = {
|
||||
isAudit: false,
|
||||
isVerified: false,
|
||||
};
|
||||
const defaultCourseRun = { isArchived: false };
|
||||
const defaultGrade = { isPassing: false };
|
||||
const defaultPlatformSettings = {};
|
||||
const createWrapper = ({
|
||||
certificate = {},
|
||||
enrollment = {},
|
||||
@@ -51,227 +46,182 @@ describe('CertificateBanner', () => {
|
||||
courseRun = {},
|
||||
platformSettings = {},
|
||||
}) => {
|
||||
useCourseData.mockReturnValue({
|
||||
enrollment: { ...defaultEnrollment, ...enrollment },
|
||||
certificate: { ...defaultCertificate, ...certificate },
|
||||
gradeData: { ...defaultGrade, ...grade },
|
||||
courseRun: {
|
||||
...defaultCourseRun,
|
||||
...courseRun,
|
||||
},
|
||||
});
|
||||
const lernearData = { data: { platformSettings: { ...defaultPlatformSettings, ...platformSettings } } };
|
||||
useInitializeLearnerHome.mockReturnValue(lernearData);
|
||||
return render(<IntlProvider locale="en"><CertificateBanner {...props} /></IntlProvider>);
|
||||
reduxHooks.useCardGradeData.mockReturnValueOnce({ ...defaultGrade, ...grade });
|
||||
reduxHooks.useCardCertificateData.mockReturnValueOnce({ ...defaultCertificate, ...certificate });
|
||||
reduxHooks.useCardEnrollmentData.mockReturnValueOnce({ ...defaultEnrollment, ...enrollment });
|
||||
reduxHooks.useCardCourseRunData.mockReturnValueOnce({ ...defaultCourseRun, ...courseRun });
|
||||
reduxHooks.usePlatformSettingsData.mockReturnValueOnce({ ...defaultPlatformSettings, ...platformSettings });
|
||||
return shallow(<CertificateBanner {...props} />);
|
||||
};
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
it('is restricted', () => {
|
||||
createWrapper({
|
||||
certificate: {
|
||||
isRestricted: true,
|
||||
},
|
||||
/** TODO: Update tests to validate snapshots **/
|
||||
describe('snapshot', () => {
|
||||
test('is restricted', () => {
|
||||
const wrapper = createWrapper({
|
||||
certificate: {
|
||||
isRestricted: true,
|
||||
},
|
||||
});
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
const banner = screen.getByRole('alert');
|
||||
expect(banner).toBeInTheDocument();
|
||||
const msg = screen.getByText((text) => text.includes('please let us know.'));
|
||||
expect(msg).toBeInTheDocument();
|
||||
expect(msg).not.toContain(supportEmail);
|
||||
});
|
||||
it('is restricted with support email', () => {
|
||||
createWrapper({
|
||||
certificate: {
|
||||
isRestricted: true,
|
||||
},
|
||||
platformSettings: {
|
||||
supportEmail,
|
||||
},
|
||||
test('is restricted with support email', () => {
|
||||
const wrapper = createWrapper({
|
||||
certificate: {
|
||||
isRestricted: true,
|
||||
},
|
||||
platformSettings: {
|
||||
supportEmail: 'suport@email',
|
||||
},
|
||||
});
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
const banner = screen.getByRole('alert');
|
||||
expect(banner).toBeInTheDocument();
|
||||
const msg = screen.getByText((text) => text.includes(supportEmail));
|
||||
expect(msg).toBeInTheDocument();
|
||||
});
|
||||
it('is restricted with billing email but not verified', () => {
|
||||
createWrapper({
|
||||
certificate: {
|
||||
isRestricted: true,
|
||||
},
|
||||
platformSettings: {
|
||||
billingEmail,
|
||||
},
|
||||
test('is restricted with billing email', () => {
|
||||
const wrapper = createWrapper({
|
||||
certificate: {
|
||||
isRestricted: true,
|
||||
},
|
||||
platformSettings: {
|
||||
billingEmail: 'billing@email',
|
||||
},
|
||||
});
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
const banner = screen.getByRole('alert');
|
||||
expect(banner).toBeInTheDocument();
|
||||
expect(banner).toHaveClass('alert-danger');
|
||||
const msg = screen.queryByText((text) => text.includes(billingEmail));
|
||||
expect(msg).not.toBeInTheDocument();
|
||||
});
|
||||
it('is restricted and verified', () => {
|
||||
createWrapper({
|
||||
certificate: {
|
||||
isRestricted: true,
|
||||
},
|
||||
enrollment: {
|
||||
isVerified: true,
|
||||
},
|
||||
test('is restricted and verified', () => {
|
||||
const wrapper = createWrapper({
|
||||
certificate: {
|
||||
isRestricted: true,
|
||||
},
|
||||
enrollment: {
|
||||
isVerified: true,
|
||||
},
|
||||
});
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
const banner = screen.getByRole('alert');
|
||||
expect(banner).toBeInTheDocument();
|
||||
const restrictedMsg = screen.getByText((text) => text.includes('please let us know.'));
|
||||
expect(restrictedMsg).toBeInTheDocument();
|
||||
const refundMsg = screen.getByText((text) => text.includes('If you would like a refund'));
|
||||
expect(refundMsg).toBeInTheDocument();
|
||||
});
|
||||
it('is restricted and verified with support email', () => {
|
||||
createWrapper({
|
||||
certificate: {
|
||||
isRestricted: true,
|
||||
},
|
||||
enrollment: {
|
||||
isVerified: true,
|
||||
},
|
||||
platformSettings: {
|
||||
supportEmail,
|
||||
},
|
||||
test('is restricted and verified with support email', () => {
|
||||
const wrapper = createWrapper({
|
||||
certificate: {
|
||||
isRestricted: true,
|
||||
},
|
||||
enrollment: {
|
||||
isVerified: true,
|
||||
},
|
||||
platformSettings: {
|
||||
supportEmail: 'suport@email',
|
||||
},
|
||||
});
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
const restrictedMsg = screen.getByText((text) => text.includes(supportEmail));
|
||||
expect(restrictedMsg).toBeInTheDocument();
|
||||
const refundMsg = screen.getByText((text) => text.includes('If you would like a refund'));
|
||||
expect(refundMsg).toBeInTheDocument();
|
||||
expect(refundMsg.innerHTML).not.toContain(billingEmail);
|
||||
});
|
||||
it('is restricted and verified with billing email', () => {
|
||||
createWrapper({
|
||||
certificate: {
|
||||
isRestricted: true,
|
||||
},
|
||||
enrollment: {
|
||||
isVerified: true,
|
||||
},
|
||||
platformSettings: {
|
||||
billingEmail,
|
||||
},
|
||||
test('is restricted and verified with billing email', () => {
|
||||
const wrapper = createWrapper({
|
||||
certificate: {
|
||||
isRestricted: true,
|
||||
},
|
||||
enrollment: {
|
||||
isVerified: true,
|
||||
},
|
||||
platformSettings: {
|
||||
billingEmail: 'billing@email',
|
||||
},
|
||||
});
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
const restrictedMsg = screen.queryByText((text) => text.includes('please let us know.'));
|
||||
expect(restrictedMsg).toBeInTheDocument();
|
||||
expect(restrictedMsg.innerHTML).not.toContain(supportEmail);
|
||||
const refundMsg = screen.getByText((text) => text.includes(billingEmail));
|
||||
expect(refundMsg).toBeInTheDocument();
|
||||
});
|
||||
it('is restricted and verified with support and billing email', () => {
|
||||
createWrapper({
|
||||
certificate: {
|
||||
isRestricted: true,
|
||||
},
|
||||
enrollment: {
|
||||
isVerified: true,
|
||||
},
|
||||
platformSettings: {
|
||||
supportEmail,
|
||||
billingEmail,
|
||||
},
|
||||
test('is restricted and verified with support and billing email', () => {
|
||||
const wrapper = createWrapper({
|
||||
certificate: {
|
||||
isRestricted: true,
|
||||
},
|
||||
enrollment: {
|
||||
isVerified: true,
|
||||
},
|
||||
platformSettings: {
|
||||
supportEmail: 'suport@email',
|
||||
billingEmail: 'billing@email',
|
||||
},
|
||||
});
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
const restrictedMsg = screen.getByText((text) => text.includes(supportEmail));
|
||||
expect(restrictedMsg).toBeInTheDocument();
|
||||
const refundMsg = screen.getByText((text) => text.includes(billingEmail));
|
||||
expect(refundMsg).toBeInTheDocument();
|
||||
});
|
||||
it('is passing and is downloadable', () => {
|
||||
createWrapper({
|
||||
grade: { isPassing: true },
|
||||
certificate: { isDownloadable: true },
|
||||
test('is passing and is downloadable', () => {
|
||||
const wrapper = createWrapper({
|
||||
grade: { isPassing: true },
|
||||
certificate: { isDownloadable: true },
|
||||
});
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
const banner = screen.getByRole('alert');
|
||||
expect(banner).toBeInTheDocument();
|
||||
expect(banner).toHaveClass('alert-success');
|
||||
const readyMsg = screen.getByText((text) => text.includes('Congratulations.'));
|
||||
expect(readyMsg).toBeInTheDocument();
|
||||
});
|
||||
it('not passing and is downloadable', () => {
|
||||
createWrapper({
|
||||
grade: { isPassing: false },
|
||||
certificate: { isDownloadable: true },
|
||||
test('not passing and is downloadable', () => {
|
||||
const wrapper = createWrapper({
|
||||
grade: { isPassing: false },
|
||||
certificate: { isDownloadable: true },
|
||||
});
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
const banner = screen.getByRole('alert');
|
||||
expect(banner).toBeInTheDocument();
|
||||
expect(banner).toHaveClass('alert-success');
|
||||
const readyMsg = screen.getByText((text) => text.includes('Congratulations.'));
|
||||
expect(readyMsg).toBeInTheDocument();
|
||||
});
|
||||
it('not passing and audit', () => {
|
||||
createWrapper({
|
||||
enrollment: {
|
||||
isAudit: true,
|
||||
},
|
||||
test('not passing and audit', () => {
|
||||
const wrapper = createWrapper({
|
||||
enrollment: {
|
||||
isAudit: true,
|
||||
},
|
||||
});
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
const banner = screen.getByRole('alert');
|
||||
expect(banner).toHaveClass('alert-info');
|
||||
const auditMsg = screen.getByText((text) => text.includes('Grade required to pass the course:'));
|
||||
expect(auditMsg).toBeInTheDocument();
|
||||
});
|
||||
it('not passing and has finished', () => {
|
||||
createWrapper({
|
||||
courseRun: { isArchived: true },
|
||||
test('not passing and has finished', () => {
|
||||
const wrapper = createWrapper({
|
||||
courseRun: { isArchived: true },
|
||||
});
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
const banner = screen.getByRole('alert');
|
||||
expect(banner).toHaveClass('alert-warning');
|
||||
const archivedMsg = screen.getByText('You are not eligible for a certificate.');
|
||||
expect(archivedMsg).toBeInTheDocument();
|
||||
});
|
||||
it('not passing and not audit and not finished', () => {
|
||||
createWrapper({});
|
||||
const banner = screen.getByRole('alert');
|
||||
expect(banner).toHaveClass('alert-warning');
|
||||
const msg = screen.getByText((text) => text.includes('Grade required for a certificate'));
|
||||
expect(msg).toBeInTheDocument();
|
||||
});
|
||||
it('is passing and is earned but unavailable', () => {
|
||||
createWrapper({
|
||||
grade: {
|
||||
isPassing: true,
|
||||
},
|
||||
certificate: {
|
||||
isEarned: true,
|
||||
availableDate: '10/20/3030',
|
||||
},
|
||||
test('not passing and not audit and not finished', () => {
|
||||
const wrapper = createWrapper({});
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
const banner = screen.getByRole('alert');
|
||||
expect(banner).toHaveClass('alert-info');
|
||||
const earnedMsg = screen.getByText((text) => text.includes('Your grade and certificate will be ready after'));
|
||||
expect(earnedMsg).toBeInTheDocument();
|
||||
});
|
||||
it('is passing and not downloadable render empty', () => {
|
||||
createWrapper({
|
||||
grade: {
|
||||
isPassing: true,
|
||||
},
|
||||
test('is passing and is earned but unavailable', () => {
|
||||
const wrapper = createWrapper({
|
||||
grade: {
|
||||
isPassing: true,
|
||||
},
|
||||
certificate: {
|
||||
isEarnedButUnavailable: true,
|
||||
},
|
||||
});
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
test('is passing and not downloadable render empty', () => {
|
||||
const wrapper = createWrapper({
|
||||
grade: {
|
||||
isPassing: true,
|
||||
},
|
||||
});
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
const banner = screen.queryByRole('alert');
|
||||
expect(banner).toBeNull();
|
||||
});
|
||||
it('should use default values when courseData is empty or undefined', () => {
|
||||
useCourseData.mockReturnValue({});
|
||||
const lernearData = { data: { platformSettings: { supportEmail } } };
|
||||
useInitializeLearnerHome.mockReturnValue(lernearData);
|
||||
render(<IntlProvider locale="en"><CertificateBanner cardId="test-card" /></IntlProvider>);
|
||||
|
||||
const mockedUseMemo = jest.spyOn(React, 'useMemo');
|
||||
const useMemoCall = mockedUseMemo.mock.calls.find(call => call[1].some(dep => dep === undefined || dep === null));
|
||||
|
||||
if (useMemoCall) {
|
||||
const result = useMemoCall[0]();
|
||||
|
||||
expect(result.certificate).toEqual({});
|
||||
expect(result.isVerified).toBe(false);
|
||||
expect(result.isAudit).toBe(false);
|
||||
expect(result.isPassing).toBe(false);
|
||||
expect(result.isArchived).toBe(false);
|
||||
expect(result.minPassingGrade).toBe(0);
|
||||
expect(result.progressUrl).toBeDefined();
|
||||
}
|
||||
|
||||
mockedUseMemo.mockRestore();
|
||||
describe('behavior', () => {
|
||||
it('is restricted', () => {
|
||||
const wrapper = createWrapper({
|
||||
certificate: {
|
||||
isRestricted: true,
|
||||
},
|
||||
platformSettings: {
|
||||
supportEmail: 'suport@email',
|
||||
billingEmail: 'billing@email',
|
||||
},
|
||||
});
|
||||
const bannerMessage = wrapper.instance.findByType('format-message-function').map(el => el.props.message.defaultMessage).join('\n');
|
||||
expect(bannerMessage).toEqual(messages.certRestricted.defaultMessage);
|
||||
expect(bannerMessage).toContain(messages.certRestricted.defaultMessage);
|
||||
});
|
||||
it('is restricted and verified', () => {
|
||||
const wrapper = createWrapper({
|
||||
certificate: {
|
||||
isRestricted: true,
|
||||
},
|
||||
enrollment: {
|
||||
isVerified: true,
|
||||
},
|
||||
platformSettings: {
|
||||
supportEmail: 'suport@email',
|
||||
billingEmail: 'billing@email',
|
||||
},
|
||||
});
|
||||
const bannerMessage = wrapper.instance.findByType('format-message-function').map(el => el.props.message.defaultMessage).join('\n');
|
||||
expect(bannerMessage).toContain(messages.certRestricted.defaultMessage);
|
||||
expect(bannerMessage).toContain(messages.certRefundContactBilling.defaultMessage);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,26 +1,21 @@
|
||||
/* eslint-disable max-len */
|
||||
import React, { useMemo } from 'react';
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Hyperlink } from '@openedx/paragon';
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
|
||||
import { utilHooks, useCourseData } from 'hooks';
|
||||
import { utilHooks, reduxHooks } from 'hooks';
|
||||
import Banner from 'components/Banner';
|
||||
import messages from './messages';
|
||||
|
||||
export const CourseBanner = ({ cardId }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const courseData = useCourseData(cardId);
|
||||
const {
|
||||
isVerified = false,
|
||||
isAuditAccessExpired = false,
|
||||
isVerified,
|
||||
isAuditAccessExpired,
|
||||
coursewareAccess = {},
|
||||
} = useMemo(() => ({
|
||||
isVerified: courseData.enrollment?.isVerified,
|
||||
isAuditAccessExpired: courseData.enrollment?.isAuditAccessExpired,
|
||||
coursewareAccess: courseData.enrollment?.coursewareAccess || {},
|
||||
}), [courseData]);
|
||||
const courseRun = courseData?.courseRun || {};
|
||||
} = reduxHooks.useCardEnrollmentData(cardId);
|
||||
const courseRun = reduxHooks.useCardCourseRunData(cardId);
|
||||
const { formatMessage } = useIntl();
|
||||
const formatDate = utilHooks.useFormatDate();
|
||||
|
||||
const { hasUnmetPrerequisites, isStaff, isTooEarly } = coursewareAccess;
|
||||
|
||||
@@ -1,20 +1,27 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import React from 'react';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
import { Hyperlink } from '@openedx/paragon';
|
||||
|
||||
import { useCourseData } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import { formatMessage } from 'testUtils';
|
||||
import { CourseBanner } from './CourseBanner';
|
||||
|
||||
import messages from './messages';
|
||||
|
||||
jest.mock('components/Banner', () => 'Banner');
|
||||
jest.mock('hooks', () => ({
|
||||
useCourseData: jest.fn(),
|
||||
utilHooks: {
|
||||
useFormatDate: () => date => date,
|
||||
},
|
||||
reduxHooks: {
|
||||
useCardCourseRunData: jest.fn(),
|
||||
useCardEnrollmentData: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
const cardId = 'test-card-id';
|
||||
const cardId = 'my-test-course-number';
|
||||
|
||||
let el;
|
||||
|
||||
const enrollmentData = {
|
||||
isVerified: false,
|
||||
@@ -31,80 +38,94 @@ const courseRunData = {
|
||||
marketingUrl: 'marketing-url',
|
||||
};
|
||||
|
||||
const renderCourseBanner = (overrides = {}) => {
|
||||
const render = (overrides = {}) => {
|
||||
const {
|
||||
courseRun = {},
|
||||
enrollment = {},
|
||||
} = overrides;
|
||||
useCourseData.mockReturnValue({
|
||||
courseRun: {
|
||||
...courseRunData,
|
||||
...courseRun,
|
||||
},
|
||||
enrollment: {
|
||||
...enrollmentData,
|
||||
...enrollment,
|
||||
},
|
||||
reduxHooks.useCardCourseRunData.mockReturnValueOnce({
|
||||
...courseRunData,
|
||||
...courseRun,
|
||||
});
|
||||
return render(<IntlProvider locale="en"><CourseBanner cardId={cardId} /></IntlProvider>);
|
||||
reduxHooks.useCardEnrollmentData.mockReturnValueOnce({
|
||||
...enrollmentData,
|
||||
...enrollment,
|
||||
});
|
||||
el = shallow(<CourseBanner cardId={cardId} />);
|
||||
};
|
||||
|
||||
describe('CourseBanner', () => {
|
||||
it('initializes data with course number from enrollment, course and course run data', () => {
|
||||
renderCourseBanner();
|
||||
expect(useCourseData).toHaveBeenCalledWith(cardId);
|
||||
test('initializes data with course number from enrollment, course and course run data', () => {
|
||||
render();
|
||||
expect(reduxHooks.useCardCourseRunData).toHaveBeenCalledWith(cardId);
|
||||
expect(reduxHooks.useCardEnrollmentData).toHaveBeenCalledWith(cardId);
|
||||
});
|
||||
it('no display if learner is verified', () => {
|
||||
renderCourseBanner({ enrollment: { isVerified: true } });
|
||||
expect(screen.queryByRole('alert')).toBeNull();
|
||||
});
|
||||
it('should use default values when enrollment data is undefined', () => {
|
||||
renderCourseBanner({
|
||||
enrollment: undefined,
|
||||
courseRun: {},
|
||||
});
|
||||
|
||||
expect(useCourseData).toHaveBeenCalledWith('test-card-id');
|
||||
test('no display if learner is verified', () => {
|
||||
render({ enrollment: { isVerified: true } });
|
||||
expect(el.isEmptyRender()).toEqual(true);
|
||||
});
|
||||
describe('audit access expired', () => {
|
||||
it('should display correct message and link', () => {
|
||||
renderCourseBanner({ enrollment: { isAuditAccessExpired: true } });
|
||||
const auditAccessText = screen.getByText(formatMessage(messages.auditAccessExpired));
|
||||
expect(auditAccessText).toBeInTheDocument();
|
||||
const auditAccessLink = screen.getByText(formatMessage(messages.findAnotherCourse));
|
||||
expect(auditAccessLink).toBeInTheDocument();
|
||||
beforeEach(() => {
|
||||
render({ enrollment: { isAuditAccessExpired: true } });
|
||||
});
|
||||
test('snapshot: (auditAccessExpired, findAnotherCourse hyperlink)', () => {
|
||||
expect(el.snapshot).toMatchSnapshot();
|
||||
});
|
||||
test('messages: auditAccessExpired', () => {
|
||||
expect(el.instance.children[0].children[0].el).toContain(messages.auditAccessExpired.defaultMessage);
|
||||
expect(el.instance.findByType(Hyperlink)[0].children[0].el).toEqual(messages.findAnotherCourse.defaultMessage);
|
||||
});
|
||||
});
|
||||
describe('unmet prerequisites', () => {
|
||||
it('should display correct message', () => {
|
||||
renderCourseBanner({ enrollment: { coursewareAccess: { hasUnmetPrerequisites: true } } });
|
||||
const preReqText = screen.getByText(formatMessage(messages.prerequisitesNotMet));
|
||||
expect(preReqText).toBeInTheDocument();
|
||||
beforeEach(() => {
|
||||
render({ enrollment: { coursewareAccess: { hasUnmetPrerequisites: true } } });
|
||||
});
|
||||
test('snapshot: unmetPrerequisites', () => {
|
||||
expect(el.snapshot).toMatchSnapshot();
|
||||
});
|
||||
test('messages: prerequisitesNotMet', () => {
|
||||
expect(el.instance.children[0].children[0].el).toContain(messages.prerequisitesNotMet.defaultMessage);
|
||||
});
|
||||
});
|
||||
describe('too early', () => {
|
||||
describe('no start date', () => {
|
||||
it('should not display banner', () => {
|
||||
renderCourseBanner({ enrollment: { coursewareAccess: { isTooEarly: true } }, courseRun: { startDate: null } });
|
||||
const banner = screen.queryByRole('alert');
|
||||
expect(banner).toBeNull();
|
||||
beforeEach(() => {
|
||||
render({ enrollment: { coursewareAccess: { isTooEarly: true } }, courseRun: { startDate: null } });
|
||||
});
|
||||
test('snapshot', () => expect(el.snapshot).toMatchSnapshot());
|
||||
test('messages', () => expect(el.instance.children).toEqual([]));
|
||||
});
|
||||
describe('has start date', () => {
|
||||
it('should display messages courseHasNotStarted', () => {
|
||||
renderCourseBanner({ enrollment: { coursewareAccess: { isTooEarly: true } } });
|
||||
const earlyMsg = screen.getByText(
|
||||
beforeEach(() => {
|
||||
render({ enrollment: { coursewareAccess: { isTooEarly: true } } });
|
||||
});
|
||||
test('snapshot', () => expect(el.snapshot).toMatchSnapshot());
|
||||
|
||||
test('messages: courseHasNotStarted', () => {
|
||||
expect(el.instance.children[0].children[0].el).toContain(
|
||||
formatMessage(messages.courseHasNotStarted, { startDate: courseRunData.startDate }),
|
||||
);
|
||||
expect(earlyMsg).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('staff', () => {
|
||||
it('should not display banner', () => {
|
||||
renderCourseBanner({ enrollment: { coursewareAccess: { isStaff: true } } });
|
||||
const banner = screen.queryByRole('alert');
|
||||
expect(banner).toBeNull();
|
||||
beforeEach(() => {
|
||||
render({ enrollment: { coursewareAccess: { isStaff: true } } });
|
||||
});
|
||||
test('snapshot: isStaff', () => {
|
||||
expect(el.snapshot).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
test('snapshot: stacking banners', () => {
|
||||
render({
|
||||
enrollment: {
|
||||
coursewareAccess: {
|
||||
isStaff: true,
|
||||
isTooEarly: true,
|
||||
hasUnmetPrerequisites: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(el.snapshot).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`CreditBanner component render with error state snapshot 1`] = `
|
||||
<Banner
|
||||
variant="danger"
|
||||
>
|
||||
<p
|
||||
className="credit-error-msg"
|
||||
data-testid="credit-error-msg"
|
||||
>
|
||||
<format-message-function
|
||||
message={
|
||||
{
|
||||
"defaultMessage": "An error occurred with this transaction. For help, contact {supportEmailLink}.",
|
||||
"description": "",
|
||||
"id": "learner-dash.courseCard.banners.credit.error",
|
||||
}
|
||||
}
|
||||
values={
|
||||
{
|
||||
"supportEmailLink": <MailtoLink
|
||||
to="test-support-email"
|
||||
>
|
||||
test-support-email
|
||||
</MailtoLink>,
|
||||
}
|
||||
}
|
||||
/>
|
||||
</p>
|
||||
<ContentComponent
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
</Banner>
|
||||
`;
|
||||
|
||||
exports[`CreditBanner component render with error state with no email snapshot 1`] = `
|
||||
<Banner
|
||||
variant="danger"
|
||||
>
|
||||
<p
|
||||
className="credit-error-msg"
|
||||
data-testid="credit-error-msg"
|
||||
>
|
||||
An error occurred with this transaction.
|
||||
</p>
|
||||
<ContentComponent
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
</Banner>
|
||||
`;
|
||||
|
||||
exports[`CreditBanner component render with no error state snapshot 1`] = `
|
||||
<Banner>
|
||||
<ContentComponent
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
</Banner>
|
||||
`;
|
||||
@@ -1,8 +1,6 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useInitializeLearnerHome } from 'data/hooks';
|
||||
import { StrictDict } from 'utils';
|
||||
|
||||
import { useCourseData } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
|
||||
import ApprovedContent from './views/ApprovedContent';
|
||||
import EligibleContent from './views/EligibleContent';
|
||||
@@ -17,29 +15,9 @@ export const statusComponents = StrictDict({
|
||||
});
|
||||
|
||||
export const useCreditBannerData = (cardId) => {
|
||||
const courseData = useCourseData(cardId);
|
||||
const { data: learnerHomeData } = useInitializeLearnerHome();
|
||||
const supportEmail = useMemo(
|
||||
() => (learnerHomeData?.platformSettings?.supportEmail),
|
||||
[learnerHomeData],
|
||||
);
|
||||
|
||||
const credit = useMemo(() => {
|
||||
const creditData = courseData?.credit;
|
||||
if (!creditData || Object.keys(creditData).length === 0) {
|
||||
return { isEligible: false };
|
||||
}
|
||||
return {
|
||||
isEligible: true,
|
||||
providerStatusUrl: creditData.providerStatusUrl,
|
||||
providerName: creditData.providerName,
|
||||
providerId: creditData.providerId,
|
||||
error: creditData.error,
|
||||
purchased: creditData.purchased,
|
||||
requestStatus: creditData.requestStatus,
|
||||
};
|
||||
}, [courseData]);
|
||||
if (!credit.isEligible || !courseData?.credit?.isEligible) { return null; }
|
||||
const credit = reduxHooks.useCardCreditData(cardId);
|
||||
const { supportEmail } = reduxHooks.usePlatformSettingsData();
|
||||
if (!credit.isEligible) { return null; }
|
||||
|
||||
const { error, purchased, requestStatus } = credit;
|
||||
let ContentComponent = EligibleContent;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { keyStore } from 'utils';
|
||||
import { useCourseData } from 'hooks';
|
||||
import { useInitializeLearnerHome } from 'data/hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
|
||||
import ApprovedContent from './views/ApprovedContent';
|
||||
import EligibleContent from './views/EligibleContent';
|
||||
@@ -10,19 +9,12 @@ import RejectedContent from './views/RejectedContent';
|
||||
|
||||
import * as hooks from './hooks';
|
||||
|
||||
jest.mock('react', () => ({
|
||||
...jest.requireActual('react'),
|
||||
useMemo: (fn) => fn(),
|
||||
}));
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
useCourseData: jest.fn(),
|
||||
reduxHooks: {
|
||||
useCardCreditData: jest.fn(),
|
||||
usePlatformSettingsData: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('data/hooks', () => ({
|
||||
useInitializeLearnerHome: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('./views/ApprovedContent', () => 'ApprovedContent');
|
||||
jest.mock('./views/EligibleContent', () => 'EligibleContent');
|
||||
jest.mock('./views/MustRequestContent', () => 'MustRequestContent');
|
||||
@@ -42,18 +34,18 @@ const defaultProps = {
|
||||
};
|
||||
|
||||
const loadHook = (creditData = {}) => {
|
||||
useCourseData.mockReturnValue({ credit: { ...defaultProps, ...creditData } });
|
||||
reduxHooks.useCardCreditData.mockReturnValue({ ...defaultProps, ...creditData });
|
||||
out = hooks.useCreditBannerData(cardId);
|
||||
};
|
||||
|
||||
describe('useCreditBannerData hook', () => {
|
||||
beforeEach(() => {
|
||||
useInitializeLearnerHome.mockReturnValue({ data: { platformSettings: { supportEmail } } });
|
||||
reduxHooks.usePlatformSettingsData.mockReturnValue({ supportEmail });
|
||||
});
|
||||
it('loads card credit data with cardID and loads platform settings data', () => {
|
||||
loadHook({ isEligible: false });
|
||||
expect(useCourseData).toHaveBeenCalledWith(cardId);
|
||||
expect(useInitializeLearnerHome).toHaveBeenCalledWith();
|
||||
expect(reduxHooks.useCardCreditData).toHaveBeenCalledWith(cardId);
|
||||
expect(reduxHooks.usePlatformSettingsData).toHaveBeenCalledWith();
|
||||
});
|
||||
describe('non-credit-eligible learner', () => {
|
||||
it('returns null if the learner is not credit eligible', () => {
|
||||
|
||||
@@ -1,65 +1,95 @@
|
||||
import { screen, render } from '@testing-library/react';
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import React from 'react';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { formatMessage } from 'testUtils';
|
||||
import { MailtoLink } from '@openedx/paragon';
|
||||
|
||||
import hooks from './hooks';
|
||||
import { CreditBanner } from '.';
|
||||
import messages from './messages';
|
||||
import CreditBanner from '.';
|
||||
|
||||
jest.mock('components/Banner', () => 'Banner');
|
||||
|
||||
jest.mock('./hooks', () => ({
|
||||
useCreditBannerData: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('CreditBanner', () => {
|
||||
const mockCardId = 'test-card-id';
|
||||
const mockContentComponent = () => <div data-testid="mock-content">Test Content</div>;
|
||||
const mockSupportEmail = 'support@test.com';
|
||||
let el;
|
||||
const cardId = 'test-card-id';
|
||||
|
||||
const renderCreditBanner = () => render(
|
||||
<IntlProvider locale="en">
|
||||
<CreditBanner cardId={mockCardId} />
|
||||
</IntlProvider>,
|
||||
);
|
||||
const ContentComponent = () => 'ContentComponent';
|
||||
const supportEmail = 'test-support-email';
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should return null if hook returns null', () => {
|
||||
hooks.useCreditBannerData.mockReturnValue(null);
|
||||
renderCreditBanner();
|
||||
const banner = screen.queryByRole('alert');
|
||||
expect(banner).toBeNull();
|
||||
});
|
||||
|
||||
it('should render content component without error', () => {
|
||||
hooks.useCreditBannerData.mockReturnValue({
|
||||
ContentComponent: mockContentComponent,
|
||||
error: false,
|
||||
describe('CreditBanner component', () => {
|
||||
describe('behavior', () => {
|
||||
beforeEach(() => {
|
||||
hooks.useCreditBannerData.mockReturnValue(null);
|
||||
el = shallow(<CreditBanner cardId={cardId} />);
|
||||
});
|
||||
renderCreditBanner();
|
||||
|
||||
expect(screen.getByTestId('mock-content')).toBeInTheDocument();
|
||||
expect(screen.queryByTestId('credit-error-msg')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render error message with support email', () => {
|
||||
hooks.useCreditBannerData.mockReturnValue({
|
||||
ContentComponent: mockContentComponent,
|
||||
error: true,
|
||||
supportEmail: mockSupportEmail,
|
||||
it('initializes hooks with cardId', () => {
|
||||
expect(hooks.useCreditBannerData).toHaveBeenCalledWith(cardId);
|
||||
});
|
||||
renderCreditBanner();
|
||||
|
||||
expect(screen.getByTestId('credit-error-msg')).toBeInTheDocument();
|
||||
expect(screen.getByText(mockSupportEmail)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render error message without support email', () => {
|
||||
hooks.useCreditBannerData.mockReturnValue({
|
||||
ContentComponent: mockContentComponent,
|
||||
error: true,
|
||||
it('returns null if hookData is null', () => {
|
||||
expect(el.isEmptyRender()).toEqual(true);
|
||||
});
|
||||
});
|
||||
describe('render', () => {
|
||||
describe('with error state', () => {
|
||||
beforeEach(() => {
|
||||
hooks.useCreditBannerData.mockReturnValue({
|
||||
error: true,
|
||||
ContentComponent,
|
||||
supportEmail,
|
||||
});
|
||||
el = shallow(<CreditBanner cardId={cardId} />);
|
||||
});
|
||||
test('snapshot', () => {
|
||||
expect(el.snapshot).toMatchSnapshot();
|
||||
});
|
||||
it('passes danger variant to Banner parent', () => {
|
||||
expect(el.instance.findByType('Banner')[0].props.variant).toEqual('danger');
|
||||
});
|
||||
it('includes credit-error-msg with support email link', () => {
|
||||
expect(el.instance.findByTestId('credit-error-msg')[0].children[0].el).toEqual(shallow(formatMessage(messages.error, {
|
||||
supportEmailLink: (<MailtoLink to={supportEmail}>{supportEmail}</MailtoLink>),
|
||||
})));
|
||||
});
|
||||
it('loads ContentComponent with cardId', () => {
|
||||
expect(el.instance.findByType('ContentComponent')[0].props.cardId).toEqual(cardId);
|
||||
});
|
||||
});
|
||||
renderCreditBanner();
|
||||
|
||||
expect(screen.getByTestId('credit-error-msg')).toBeInTheDocument();
|
||||
expect(screen.queryByText(mockSupportEmail)).not.toBeInTheDocument();
|
||||
describe('with error state with no email', () => {
|
||||
beforeEach(() => {
|
||||
hooks.useCreditBannerData.mockReturnValue({
|
||||
error: true,
|
||||
ContentComponent,
|
||||
});
|
||||
el = shallow(<CreditBanner cardId={cardId} />);
|
||||
});
|
||||
test('snapshot', () => {
|
||||
expect(el.snapshot).toMatchSnapshot();
|
||||
});
|
||||
it('includes credit-error-msg without support email link', () => {
|
||||
expect(el.instance.findByTestId('credit-error-msg')[0].children[0].el).toEqual(formatMessage(messages.errorNoEmail));
|
||||
});
|
||||
});
|
||||
|
||||
describe('with no error state', () => {
|
||||
beforeEach(() => {
|
||||
hooks.useCreditBannerData.mockReturnValue({
|
||||
error: false,
|
||||
ContentComponent,
|
||||
supportEmail,
|
||||
});
|
||||
el = shallow(<CreditBanner cardId={cardId} />);
|
||||
});
|
||||
test('snapshot', () => {
|
||||
expect(el.snapshot).toMatchSnapshot();
|
||||
});
|
||||
it('loads ContentComponent with cardId', () => {
|
||||
expect(el.instance.findByType('ContentComponent')[0].props.cardId).toEqual(cardId);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,24 +1,17 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
|
||||
import { useCourseData, useIsMasquerading } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import CreditContent from './components/CreditContent';
|
||||
import ProviderLink from './components/ProviderLink';
|
||||
|
||||
import messages from './messages';
|
||||
|
||||
export const ApprovedContent = ({ cardId }) => {
|
||||
const courseData = useCourseData(cardId);
|
||||
const { providerStatusUrl: href, providerName } = useMemo(() => {
|
||||
const creditData = courseData?.credit;
|
||||
return {
|
||||
providerStatusUrl: creditData.providerStatusUrl,
|
||||
providerName: creditData.providerName,
|
||||
};
|
||||
}, [courseData]);
|
||||
const isMasquerading = useIsMasquerading();
|
||||
const { providerStatusUrl: href, providerName } = reduxHooks.useCardCreditData(cardId);
|
||||
const { isMasquerading } = reduxHooks.useMasqueradeData();
|
||||
const { formatMessage } = useIntl();
|
||||
return (
|
||||
<CreditContent
|
||||
|
||||
@@ -1,72 +1,63 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import React from 'react';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { formatMessage } from 'testUtils';
|
||||
import { useCourseData, useIsMasquerading } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import messages from './messages';
|
||||
import ProviderLink from './components/ProviderLink';
|
||||
import ApprovedContent from './ApprovedContent';
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
useCourseData: jest.fn(),
|
||||
useIsMasquerading: jest.fn(),
|
||||
reduxHooks: {
|
||||
useCardCreditData: jest.fn(),
|
||||
useMasqueradeData: jest.fn(),
|
||||
},
|
||||
}));
|
||||
jest.mock('./components/CreditContent', () => 'CreditContent');
|
||||
jest.mock('./components/ProviderLink', () => 'ProviderLink');
|
||||
|
||||
let el;
|
||||
const cardId = 'test-card-id';
|
||||
const credit = {
|
||||
providerStatusUrl: 'test-credit-provider-status-url',
|
||||
providerName: 'test-credit-provider-name',
|
||||
};
|
||||
useCourseData.mockReturnValue({ credit });
|
||||
useIsMasquerading.mockReturnValue(false);
|
||||
reduxHooks.useCardCreditData.mockReturnValue(credit);
|
||||
reduxHooks.useMasqueradeData.mockReturnValue({ isMasquerading: false });
|
||||
|
||||
describe('ApprovedContent component', () => {
|
||||
describe('hooks', () => {
|
||||
beforeEach(() => {
|
||||
el = shallow(<ApprovedContent cardId={cardId} />);
|
||||
});
|
||||
describe('behavior', () => {
|
||||
it('initializes credit data with cardId', () => {
|
||||
render(<IntlProvider locale="en"><ApprovedContent cardId={cardId} /></IntlProvider>);
|
||||
expect(useCourseData).toHaveBeenCalledWith(cardId);
|
||||
expect(reduxHooks.useCardCreditData).toHaveBeenCalledWith(cardId);
|
||||
});
|
||||
});
|
||||
describe('render', () => {
|
||||
describe('rendered CreditContent component', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
render(<IntlProvider locale="en"><ApprovedContent cardId={cardId} /></IntlProvider>);
|
||||
let component;
|
||||
beforeAll(() => {
|
||||
component = el.instance.findByType('CreditContent');
|
||||
});
|
||||
it('action.message is formatted viewCredit message', () => {
|
||||
const actionButton = screen.getByRole('link', { name: messages.viewCredit.defaultMessage });
|
||||
expect(actionButton).toBeInTheDocument();
|
||||
expect(actionButton).toHaveTextContent(formatMessage(messages.viewCredit));
|
||||
test('action.href from credit.providerStatusUrl', () => {
|
||||
expect(component[0].props.action.href).toEqual(credit.providerStatusUrl);
|
||||
});
|
||||
it('action.href from credit.providerStatusUrl', () => {
|
||||
const actionButton = screen.getByRole('link', { name: messages.viewCredit.defaultMessage });
|
||||
expect(actionButton).toHaveAttribute('href', credit.providerStatusUrl);
|
||||
test('action.message is formatted viewCredit message', () => {
|
||||
expect(component[0].props.action.message).toEqual(formatMessage(messages.viewCredit));
|
||||
});
|
||||
it('action.disabled is false', () => {
|
||||
const actionButton = screen.getByRole('link', { name: messages.viewCredit.defaultMessage });
|
||||
expect(actionButton).not.toHaveAttribute('aria-disabled', 'true');
|
||||
expect(actionButton).not.toHaveClass('disabled');
|
||||
expect(actionButton).toBeEnabled();
|
||||
test('action.disabled is false', () => {
|
||||
expect(component[0].props.action.disabled).toEqual(false);
|
||||
});
|
||||
it('message is formatted approved message', () => {
|
||||
const creditMsg = screen.getByTestId('credit-msg');
|
||||
expect(creditMsg).toBeInTheDocument();
|
||||
expect(creditMsg.textContent).toContain(`${credit.providerName} has approved your request for course credit`);
|
||||
});
|
||||
});
|
||||
describe('when masquerading', () => {
|
||||
beforeEach(() => {
|
||||
useIsMasquerading.mockReturnValue(true);
|
||||
render(<IntlProvider locale="en"><ApprovedContent cardId={cardId} /></IntlProvider>);
|
||||
});
|
||||
|
||||
it('disables the action button', () => {
|
||||
const actionButton = screen.getByRole('link', { name: messages.viewCredit.defaultMessage });
|
||||
expect(actionButton).toHaveAttribute('aria-disabled', 'true');
|
||||
expect(actionButton).toHaveClass('disabled');
|
||||
});
|
||||
|
||||
it('still renders provider name and link correctly', () => {
|
||||
const creditMsg = screen.getByTestId('credit-msg');
|
||||
expect(creditMsg.textContent).toContain(credit.providerName);
|
||||
test('message is formatted approved message', () => {
|
||||
expect(component[0].props.message).toEqual(formatMessage(
|
||||
messages.approved,
|
||||
{
|
||||
congratulations: (<b>{formatMessage(messages.congratulations)}</b>),
|
||||
linkToProviderSite: <ProviderLink cardId={cardId} />,
|
||||
providerName: credit.providerName,
|
||||
},
|
||||
));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
||||
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
|
||||
import { useCourseData } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import track from 'tracking';
|
||||
|
||||
import CreditContent from './components/CreditContent';
|
||||
@@ -11,9 +11,8 @@ import messages from './messages';
|
||||
|
||||
export const EligibleContent = ({ cardId }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const courseData = useCourseData(cardId);
|
||||
const providerName = courseData?.credit?.providerName;
|
||||
const courseId = courseData?.courseRun?.courseId;
|
||||
const { providerName } = reduxHooks.useCardCreditData(cardId);
|
||||
const { courseId } = reduxHooks.useCardCourseRunData(cardId);
|
||||
|
||||
const onClick = track.credit.purchase(courseId);
|
||||
const getCredit = formatMessage(messages.getCredit);
|
||||
|
||||
@@ -1,65 +1,81 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import React from 'react';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { useCourseData } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import { formatMessage } from 'testUtils';
|
||||
import track from 'tracking';
|
||||
|
||||
import messages from './messages';
|
||||
import EligibleContent from './EligibleContent';
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
useCourseData: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('tracking', () => ({
|
||||
credit: {
|
||||
purchase: jest.fn(),
|
||||
reduxHooks: {
|
||||
useCardCreditData: jest.fn(),
|
||||
useCardCourseRunData: jest.fn(),
|
||||
},
|
||||
}));
|
||||
jest.mock('./components/CreditContent', () => 'CreditContent');
|
||||
jest.mock('tracking', () => ({
|
||||
credit: {
|
||||
purchase: (...args) => ({ trackCredit: args }),
|
||||
},
|
||||
}));
|
||||
|
||||
let el;
|
||||
let component;
|
||||
|
||||
const cardId = 'test-card-id';
|
||||
const courseId = 'test-course-id';
|
||||
const credit = {
|
||||
providerName: 'test-credit-provider-name',
|
||||
};
|
||||
useCourseData.mockReturnValue({ credit, courseRun: { courseId } });
|
||||
|
||||
const renderEligibleContent = () => render(<IntlProvider locale="en" messages={{}}><EligibleContent cardId={cardId} /></IntlProvider>);
|
||||
reduxHooks.useCardCreditData.mockReturnValue(credit);
|
||||
reduxHooks.useCardCourseRunData.mockReturnValue({ courseId });
|
||||
|
||||
const render = () => {
|
||||
el = shallow(<EligibleContent cardId={cardId} />);
|
||||
};
|
||||
const loadComponent = () => {
|
||||
component = el.instance.findByType('CreditContent');
|
||||
};
|
||||
describe('EligibleContent component', () => {
|
||||
describe('hooks', () => {
|
||||
it('initializes credit data with cardId', () => {
|
||||
renderEligibleContent();
|
||||
expect(useCourseData).toHaveBeenCalledWith(cardId);
|
||||
});
|
||||
beforeEach(() => {
|
||||
render();
|
||||
});
|
||||
describe('behavior', () => {
|
||||
it('initializes credit data with cardId', () => {
|
||||
expect(reduxHooks.useCardCreditData).toHaveBeenCalledWith(cardId);
|
||||
});
|
||||
it('initializes course run data with cardId', () => {
|
||||
expect(reduxHooks.useCardCourseRunData).toHaveBeenCalledWith(cardId);
|
||||
});
|
||||
});
|
||||
describe('render', () => {
|
||||
describe('rendered CreditContent component', () => {
|
||||
it('action message is formatted getCredit message', () => {
|
||||
renderEligibleContent();
|
||||
const button = screen.getByRole('button', { name: messages.getCredit.defaultMessage });
|
||||
expect(button).toBeInTheDocument();
|
||||
beforeEach(() => {
|
||||
loadComponent();
|
||||
});
|
||||
it('onClick sends credit purchase track event', async () => {
|
||||
const user = userEvent.setup();
|
||||
renderEligibleContent();
|
||||
const button = screen.getByRole('button', { name: messages.getCredit.defaultMessage });
|
||||
await user.click(button);
|
||||
expect(track.credit.purchase).toHaveBeenCalledWith(courseId);
|
||||
test('action.onClick sends credit purchase track event', () => {
|
||||
expect(component[0].props.action.onClick).toEqual(
|
||||
track.credit.purchase(courseId),
|
||||
);
|
||||
});
|
||||
it('message is formatted eligible message if provider', () => {
|
||||
renderEligibleContent();
|
||||
const eligibleMessage = screen.getByTestId('credit-msg');
|
||||
expect(eligibleMessage).toBeInTheDocument();
|
||||
expect(eligibleMessage).toHaveTextContent(credit.providerName);
|
||||
test('action.message is formatted getCredit message', () => {
|
||||
expect(component[0].props.action.message).toEqual(formatMessage(messages.getCredit));
|
||||
});
|
||||
it('message is formatted eligible message if no provider', () => {
|
||||
useCourseData.mockReturnValue({ credit: {}, courseRun: { courseId } });
|
||||
renderEligibleContent();
|
||||
const eligibleMessage = screen.getByTestId('credit-msg');
|
||||
expect(eligibleMessage).toBeInTheDocument();
|
||||
expect(eligibleMessage).toHaveTextContent(messages.getCredit.defaultMessage);
|
||||
test('message is formatted eligible message if no provider', () => {
|
||||
reduxHooks.useCardCreditData.mockReturnValueOnce({});
|
||||
render();
|
||||
loadComponent();
|
||||
expect(component[0].props.message).toEqual(formatMessage(
|
||||
messages.eligible,
|
||||
{ getCredit: (<b>{formatMessage(messages.getCredit)}</b>) },
|
||||
));
|
||||
});
|
||||
test('message is formatted eligible message if provider', () => {
|
||||
expect(component[0].props.message).toEqual(
|
||||
formatMessage(messages.eligibleFromProvider, { providerName: credit.providerName }),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
||||
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
|
||||
import { useIsMasquerading } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import CreditContent from './components/CreditContent';
|
||||
import ProviderLink from './components/ProviderLink';
|
||||
import hooks from './hooks';
|
||||
@@ -13,7 +13,7 @@ import messages from './messages';
|
||||
export const MustRequestContent = ({ cardId }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const { requestData, createCreditRequest } = hooks.useCreditRequestData(cardId);
|
||||
const isMasquerading = useIsMasquerading();
|
||||
const { isMasquerading } = reduxHooks.useMasqueradeData();
|
||||
return (
|
||||
<CreditContent
|
||||
action={{
|
||||
|
||||
@@ -1,102 +1,73 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { useCourseData, useIsMasquerading } from 'hooks';
|
||||
import React from 'react';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { formatMessage } from 'testUtils';
|
||||
|
||||
import { reduxHooks } from 'hooks';
|
||||
import messages from './messages';
|
||||
import hooks from './hooks';
|
||||
import ProviderLink from './components/ProviderLink';
|
||||
import MustRequestContent from './MustRequestContent';
|
||||
|
||||
jest.mock('./hooks', () => ({
|
||||
useCreditRequestData: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
useCourseData: jest.fn(),
|
||||
useIsMasquerading: jest.fn(),
|
||||
reduxHooks: { useMasqueradeData: jest.fn() },
|
||||
}));
|
||||
jest.mock('./components/CreditContent', () => 'CreditContent');
|
||||
jest.mock('./components/ProviderLink', () => 'ProviderLink');
|
||||
|
||||
let el;
|
||||
let component;
|
||||
|
||||
const cardId = 'test-card-id';
|
||||
const requestData = {
|
||||
url: 'test-request-data-url',
|
||||
parameters: {
|
||||
key1: 'val1',
|
||||
key2: 'val2',
|
||||
key3: 'val3',
|
||||
},
|
||||
};
|
||||
const providerName = 'test-credit-provider-name';
|
||||
const providerStatusUrl = 'test-credit-provider-status-url';
|
||||
const requestData = { test: 'requestData' };
|
||||
const createCreditRequest = jest.fn().mockName('createCreditRequest');
|
||||
hooks.useCreditRequestData.mockReturnValue({
|
||||
requestData,
|
||||
createCreditRequest,
|
||||
});
|
||||
reduxHooks.useMasqueradeData.mockReturnValue({ isMasquerading: false });
|
||||
|
||||
const renderMustRequestContent = () => render(
|
||||
<IntlProvider locale="en" messages={messages}>
|
||||
<MustRequestContent cardId={cardId} />
|
||||
</IntlProvider>,
|
||||
);
|
||||
|
||||
const render = () => {
|
||||
el = shallow(<MustRequestContent cardId={cardId} />);
|
||||
};
|
||||
describe('MustRequestContent component', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
hooks.useCreditRequestData.mockReturnValue({
|
||||
requestData,
|
||||
createCreditRequest,
|
||||
});
|
||||
useIsMasquerading.mockReturnValue(false);
|
||||
useCourseData.mockReturnValue({
|
||||
credit: {
|
||||
providerName,
|
||||
providerStatusUrl,
|
||||
},
|
||||
});
|
||||
render();
|
||||
});
|
||||
|
||||
describe('hooks', () => {
|
||||
describe('behavior', () => {
|
||||
it('initializes credit request data with cardId', () => {
|
||||
renderMustRequestContent();
|
||||
expect(hooks.useCreditRequestData).toHaveBeenCalledWith(cardId);
|
||||
});
|
||||
});
|
||||
|
||||
describe('behavior', () => {
|
||||
describe('rendered content', () => {
|
||||
describe('render', () => {
|
||||
describe('rendered CreditContent component', () => {
|
||||
beforeEach(() => {
|
||||
renderMustRequestContent();
|
||||
component = el.instance.findByType('CreditContent');
|
||||
});
|
||||
|
||||
it('calls createCreditRequest when request credit button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
const button = screen.getByRole('button', { name: /request credit/i });
|
||||
await user.click(button);
|
||||
expect(createCreditRequest).toHaveBeenCalled();
|
||||
test('action.onClick calls createCreditRequest from useCreditRequestData hook', () => {
|
||||
expect(component[0].props.action.onClick).toEqual(createCreditRequest);
|
||||
});
|
||||
|
||||
it('shows request credit button that is enabled', () => {
|
||||
const button = screen.getByRole('button', { name: /request credit/i });
|
||||
expect(button).toBeEnabled();
|
||||
test('action.message is formatted requestCredit message', () => {
|
||||
expect(component[0].props.action.message).toEqual(
|
||||
formatMessage(messages.requestCredit),
|
||||
);
|
||||
});
|
||||
|
||||
it('displays must request message with provider link', () => {
|
||||
expect(screen.getByTestId('credit-msg')).toHaveTextContent(/request credit/i);
|
||||
test('action.disabled is false', () => {
|
||||
expect(component[0].props.action.disabled).toEqual(false);
|
||||
});
|
||||
|
||||
it('renders credit request form with correct data', () => {
|
||||
const { container } = renderMustRequestContent();
|
||||
const form = container.querySelector('form');
|
||||
expect(form).toBeInTheDocument();
|
||||
expect(form).toHaveAttribute('action', requestData.url);
|
||||
test('message is formatted mustRequest message', () => {
|
||||
expect(component[0].props.message).toEqual(
|
||||
formatMessage(messages.mustRequest, {
|
||||
linkToProviderSite: <ProviderLink cardId={cardId} />,
|
||||
requestCredit: <b>{formatMessage(messages.requestCredit)}</b>,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when masquerading', () => {
|
||||
beforeEach(() => {
|
||||
useIsMasquerading.mockReturnValue(true);
|
||||
renderMustRequestContent();
|
||||
});
|
||||
|
||||
it('disables the request credit button', () => {
|
||||
const button = screen.getByRole('button', { name: /request credit/i });
|
||||
expect(button).toHaveClass('disabled');
|
||||
expect(button).toHaveAttribute('aria-disabled', 'true');
|
||||
test('requestData drawn from useCreditRequestData hook', () => {
|
||||
expect(component[0].props.requestData).toEqual(requestData);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,14 +3,13 @@ import PropTypes from 'prop-types';
|
||||
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
|
||||
import { useCourseData, useIsMasquerading } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import CreditContent from './components/CreditContent';
|
||||
import messages from './messages';
|
||||
|
||||
export const PendingContent = ({ cardId }) => {
|
||||
const courseData = useCourseData(cardId);
|
||||
const { providerStatusUrl: href, providerName } = courseData?.credit || {};
|
||||
const isMasquerading = useIsMasquerading();
|
||||
const { providerStatusUrl: href, providerName } = reduxHooks.useCardCreditData(cardId);
|
||||
const { isMasquerading } = reduxHooks.useMasqueradeData();
|
||||
const { formatMessage } = useIntl();
|
||||
return (
|
||||
<CreditContent
|
||||
|
||||
@@ -1,68 +1,62 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import { useCourseData, useIsMasquerading } from 'hooks';
|
||||
import React from 'react';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { formatMessage } from 'testUtils';
|
||||
import { reduxHooks } from 'hooks';
|
||||
|
||||
import messages from './messages';
|
||||
import PendingContent from './PendingContent';
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
useCourseData: jest.fn(),
|
||||
useIsMasquerading: jest.fn(),
|
||||
reduxHooks: { useCardCreditData: jest.fn(), useMasqueradeData: jest.fn() },
|
||||
}));
|
||||
jest.mock('./components/CreditContent', () => 'CreditContent');
|
||||
jest.mock('./components/ProviderLink', () => 'ProviderLink');
|
||||
|
||||
let el;
|
||||
let component;
|
||||
|
||||
const cardId = 'test-card-id';
|
||||
const providerName = 'test-credit-provider-name';
|
||||
const providerStatusUrl = 'test-credit-provider-status-url';
|
||||
useIsMasquerading.mockReturnValue(false);
|
||||
useCourseData.mockReturnValue({
|
||||
credit: {
|
||||
providerName,
|
||||
providerStatusUrl,
|
||||
},
|
||||
reduxHooks.useCardCreditData.mockReturnValue({
|
||||
providerName,
|
||||
providerStatusUrl,
|
||||
});
|
||||
reduxHooks.useMasqueradeData.mockReturnValue({ isMasquerading: false });
|
||||
|
||||
const renderPendingContent = () => render(
|
||||
<IntlProvider messages={{}} locale="en">
|
||||
<PendingContent cardId={cardId} />
|
||||
</IntlProvider>,
|
||||
);
|
||||
const render = () => {
|
||||
el = shallow(<PendingContent cardId={cardId} />);
|
||||
};
|
||||
describe('PendingContent component', () => {
|
||||
describe('hooks', () => {
|
||||
it('initializes card credit data with cardId', () => {
|
||||
renderPendingContent();
|
||||
expect(useCourseData).toHaveBeenCalledWith(cardId);
|
||||
});
|
||||
beforeEach(() => {
|
||||
render();
|
||||
});
|
||||
describe('behavior', () => {
|
||||
it('initializes card credit data with cardId', () => {
|
||||
expect(reduxHooks.useCardCreditData).toHaveBeenCalledWith(cardId);
|
||||
});
|
||||
});
|
||||
describe('render', () => {
|
||||
describe('rendered CreditContent component', () => {
|
||||
it('action message is formatted requestCredit message', () => {
|
||||
renderPendingContent();
|
||||
const button = screen.getByRole('link', { name: messages.viewDetails.defaultMessage });
|
||||
expect(button).toBeInTheDocument();
|
||||
beforeEach(() => {
|
||||
component = el.instance.findByType('CreditContent');
|
||||
});
|
||||
it('action href will go to provider status site', () => {
|
||||
renderPendingContent();
|
||||
const button = screen.getByRole('link', { name: messages.viewDetails.defaultMessage });
|
||||
expect(button).toHaveAttribute('href', providerStatusUrl);
|
||||
test('action.href will go to provider status site', () => {
|
||||
expect(component[0].props.action.href).toEqual(providerStatusUrl);
|
||||
});
|
||||
it('action.disabled is false', () => {
|
||||
renderPendingContent();
|
||||
const button = screen.getByRole('link', { name: messages.viewDetails.defaultMessage });
|
||||
expect(button).not.toHaveClass('disabled');
|
||||
test('action.message is formatted requestCredit message', () => {
|
||||
expect(component[0].props.action.message).toEqual(
|
||||
formatMessage(messages.viewDetails),
|
||||
);
|
||||
});
|
||||
it('message is formatted pending message with provider name', () => {
|
||||
renderPendingContent();
|
||||
const component = screen.getByTestId('credit-msg');
|
||||
expect(component).toBeInTheDocument();
|
||||
expect(component).toHaveTextContent(`${providerName} has received`);
|
||||
test('action.disabled is false', () => {
|
||||
expect(component[0].props.action.disabled).toEqual(false);
|
||||
});
|
||||
describe('when masqueradeData is true', () => {
|
||||
it('disables the view details button', () => {
|
||||
useIsMasquerading.mockReturnValue(true);
|
||||
renderPendingContent();
|
||||
const button = screen.getByRole('link', { name: messages.viewDetails.defaultMessage });
|
||||
expect(button).toHaveClass('disabled');
|
||||
});
|
||||
test('message is formatted pending message', () => {
|
||||
expect(component[0].props.message).toEqual(
|
||||
formatMessage(messages.received, { providerName }),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,19 +3,18 @@ import PropTypes from 'prop-types';
|
||||
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
|
||||
import { useCourseData } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import CreditContent from './components/CreditContent';
|
||||
import ProviderLink from './components/ProviderLink';
|
||||
import messages from './messages';
|
||||
|
||||
export const RejectedContent = ({ cardId }) => {
|
||||
const courseData = useCourseData(cardId);
|
||||
const credit = courseData?.credit;
|
||||
const credit = reduxHooks.useCardCreditData(cardId);
|
||||
const { formatMessage } = useIntl();
|
||||
return (
|
||||
<CreditContent
|
||||
message={formatMessage(messages.rejected, {
|
||||
providerName: credit?.providerName,
|
||||
providerName: credit.providerName,
|
||||
linkToProviderSite: (<ProviderLink cardId={cardId} />),
|
||||
})}
|
||||
/>
|
||||
|
||||
@@ -1,43 +1,53 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import React from 'react';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { useCourseData } from 'hooks';
|
||||
import { formatMessage } from 'testUtils';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import messages from './messages';
|
||||
import ProviderLink from './components/ProviderLink';
|
||||
import RejectedContent from './RejectedContent';
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
useCourseData: jest.fn(),
|
||||
reduxHooks: {
|
||||
useCardCreditData: jest.fn(),
|
||||
},
|
||||
}));
|
||||
jest.mock('./components/CreditContent', () => 'CreditContent');
|
||||
jest.mock('./components/ProviderLink', () => 'ProviderLink');
|
||||
|
||||
const cardId = 'test-card-id';
|
||||
const credit = {
|
||||
providerStatusUrl: 'test-credit-provider-status-url',
|
||||
providerName: 'test-credit-provider-name',
|
||||
};
|
||||
useCourseData.mockReturnValue({
|
||||
credit,
|
||||
});
|
||||
reduxHooks.useCardCreditData.mockReturnValue(credit);
|
||||
|
||||
const renderRejectedContent = () => render(<IntlProvider><RejectedContent cardId={cardId} /></IntlProvider>);
|
||||
let el;
|
||||
let component;
|
||||
const render = () => { el = shallow(<RejectedContent cardId={cardId} />); };
|
||||
const loadComponent = () => { component = el.instance.findByType('CreditContent'); };
|
||||
|
||||
describe('RejectedContent component', () => {
|
||||
describe('hooks', () => {
|
||||
beforeEach(render);
|
||||
describe('behavior', () => {
|
||||
it('initializes credit data with cardId', () => {
|
||||
renderRejectedContent();
|
||||
expect(useCourseData).toHaveBeenCalledWith(cardId);
|
||||
expect(reduxHooks.useCardCreditData).toHaveBeenCalledWith(cardId);
|
||||
});
|
||||
});
|
||||
describe('render', () => {
|
||||
describe('rendered CreditContent component', () => {
|
||||
it('no action is passed', () => {
|
||||
renderRejectedContent();
|
||||
const action = screen.queryByTestId('action-row-btn');
|
||||
expect(action).not.toBeInTheDocument();
|
||||
beforeAll(loadComponent);
|
||||
test('no action is passed', () => {
|
||||
expect(component[0].props.action).toEqual(undefined);
|
||||
});
|
||||
it('message is formatted rejected message', () => {
|
||||
renderRejectedContent();
|
||||
const message = screen.getByTestId('credit-msg');
|
||||
expect(message).toBeInTheDocument();
|
||||
expect(message).toHaveTextContent(`${credit.providerName} did not approve your request for course credit.`);
|
||||
test('message is formatted rejected message', () => {
|
||||
expect(component[0].props.message).toEqual(formatMessage(
|
||||
messages.rejected,
|
||||
{
|
||||
linkToProviderSite: <ProviderLink cardId={cardId} />,
|
||||
providerName: credit.providerName,
|
||||
},
|
||||
));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import CreditContent from './CreditContent';
|
||||
|
||||
let el;
|
||||
const action = {
|
||||
href: 'test-action-href',
|
||||
onClick: jest.fn().mockName('test-action-onClick'),
|
||||
@@ -13,57 +15,45 @@ const message = 'test-message';
|
||||
const requestData = { url: 'test-request-data-url', parameters: { key1: 'val1' } };
|
||||
const props = { action, message, requestData };
|
||||
|
||||
const renderCreditContent = (data) => render(
|
||||
<CreditContent {...data} />,
|
||||
);
|
||||
|
||||
describe('CreditContent component', () => {
|
||||
describe('render', () => {
|
||||
describe('with action', () => {
|
||||
it('loads href and message into action row button', () => {
|
||||
renderCreditContent(props);
|
||||
const button = screen.getByRole('link', { name: action.message });
|
||||
expect(button).toBeInTheDocument();
|
||||
expect(button).toHaveAttribute('href', action.href);
|
||||
expect(button).not.toHaveAttribute('disabled');
|
||||
beforeEach(() => {
|
||||
el = shallow(<CreditContent {...props} />);
|
||||
});
|
||||
test('snapshot', () => {
|
||||
expect(el.snapshot).toMatchSnapshot();
|
||||
});
|
||||
it('loads href, onClick, and message into action row button', () => {
|
||||
const buttonEl = el.instance.findByTestId('action-row-btn')[0];
|
||||
expect(buttonEl.props.href).toEqual(action.href);
|
||||
expect(buttonEl.props.onClick).toEqual(action.onClick);
|
||||
expect(buttonEl.props.disabled).toEqual(action.disabled);
|
||||
expect(buttonEl.children[0].el).toEqual(action.message);
|
||||
});
|
||||
it('loads message into credit-msg div', () => {
|
||||
renderCreditContent(props);
|
||||
const creditMsg = screen.getByTestId('credit-msg');
|
||||
expect(creditMsg).toBeInTheDocument();
|
||||
expect(creditMsg.innerHTML).toEqual(message);
|
||||
expect(el.instance.findByTestId('credit-msg')[0].children[0].el).toEqual(message);
|
||||
});
|
||||
it('loads CreditRequestForm with passed requestData', () => {
|
||||
const { container } = renderCreditContent(props);
|
||||
const creditForm = container.querySelector('form');
|
||||
expect(creditForm).toBeInTheDocument();
|
||||
expect(creditForm).toHaveAttribute('action', requestData.url);
|
||||
expect(el.instance.findByType('CreditRequestForm')[0].props.requestData).toEqual(requestData);
|
||||
});
|
||||
it('disables action button when action.disabled is true', () => {
|
||||
renderCreditContent({ ...props, action: { ...action, disabled: true } });
|
||||
const button = screen.getByRole('link', { name: action.message });
|
||||
expect(button).toBeInTheDocument();
|
||||
expect(button).toHaveClass('disabled');
|
||||
expect(button).toHaveAttribute('aria-disabled', 'true');
|
||||
test('disables action button when action.disabled is true', () => {
|
||||
el = shallow(<CreditContent {...props} action={{ ...action, disabled: true }} />);
|
||||
expect(el.instance.findByTestId('action-row-btn')[0].props.disabled).toEqual(true);
|
||||
});
|
||||
});
|
||||
describe('without action', () => {
|
||||
test('snapshot', () => {
|
||||
el = shallow(<CreditContent {...{ message, requestData }} />);
|
||||
});
|
||||
test('snapshot', () => {
|
||||
expect(el.snapshot).toMatchSnapshot();
|
||||
});
|
||||
it('loads message into credit-msg div', () => {
|
||||
renderCreditContent({ message, requestData });
|
||||
const creditMsg = screen.getByTestId('credit-msg');
|
||||
expect(creditMsg).toBeInTheDocument();
|
||||
expect(creditMsg.innerHTML).toEqual(message);
|
||||
expect(el.instance.findByTestId('credit-msg')[0].children[0].el).toEqual(message);
|
||||
});
|
||||
it('loads CreditRequestForm with passed requestData', () => {
|
||||
const { container } = renderCreditContent({ message, requestData });
|
||||
const creditForm = container.querySelector('form');
|
||||
expect(creditForm).toBeInTheDocument();
|
||||
expect(creditForm).toHaveAttribute('action', requestData.url);
|
||||
});
|
||||
it('does not render action row button', () => {
|
||||
renderCreditContent({ message, requestData });
|
||||
const button = screen.queryByRole('link', { name: action.message });
|
||||
expect(button).not.toBeInTheDocument();
|
||||
expect(el.instance.findByType('CreditRequestForm')[0].props.requestData).toEqual(requestData);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`CreditRequestForm component render output valid requestData snapshot 1`] = `
|
||||
<Form
|
||||
accept-method="UTF-8"
|
||||
action="test-request-data-url"
|
||||
className="hidden"
|
||||
method="POST"
|
||||
>
|
||||
<FormControl
|
||||
as="textarea"
|
||||
key="key1"
|
||||
name="key1"
|
||||
value="val1"
|
||||
/>
|
||||
<FormControl
|
||||
as="textarea"
|
||||
key="key2"
|
||||
name="key2"
|
||||
value="val2"
|
||||
/>
|
||||
<FormControl
|
||||
as="textarea"
|
||||
key="key3"
|
||||
name="key3"
|
||||
value="val3"
|
||||
/>
|
||||
<Button
|
||||
type="submit"
|
||||
/>
|
||||
</Form>
|
||||
`;
|
||||
@@ -4,12 +4,6 @@ import useCreditRequestFormData from './hooks';
|
||||
|
||||
const requestData = 'test-request-data';
|
||||
|
||||
jest.mock('react', () => ({
|
||||
...jest.requireActual('react'),
|
||||
useRef: jest.fn((val) => ({ current: val, useRef: true })),
|
||||
useEffect: jest.fn((cb, prereqs) => ({ useEffect: { cb, prereqs } })),
|
||||
}));
|
||||
|
||||
let out;
|
||||
const ref = {
|
||||
current: { click: jest.fn() },
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { render } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { keyStore } from 'utils';
|
||||
|
||||
@@ -10,8 +11,7 @@ jest.mock('./hooks', () => ({
|
||||
default: jest.fn(),
|
||||
}));
|
||||
|
||||
const ref = { current: { click: jest.fn() }, useRef: jest.fn() };
|
||||
|
||||
const ref = 'test-ref';
|
||||
const requestData = {
|
||||
url: 'test-request-data-url',
|
||||
parameters: {
|
||||
@@ -25,41 +25,40 @@ const paramKeys = keyStore(requestData.parameters);
|
||||
|
||||
useCreditRequestFormData.mockReturnValue({ ref });
|
||||
|
||||
const renderForm = (data) => render(<CreditRequestForm requestData={data} />);
|
||||
let el;
|
||||
const shallowRender = (data) => { el = shallow(<CreditRequestForm requestData={data} />); };
|
||||
describe('CreditRequestForm component', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
describe('hooks', () => {
|
||||
describe('behavior', () => {
|
||||
it('initializes ref from hook with requestData', () => {
|
||||
renderForm(requestData);
|
||||
shallowRender(requestData);
|
||||
expect(useCreditRequestFormData).toHaveBeenCalledWith(requestData);
|
||||
});
|
||||
});
|
||||
describe('render output', () => {
|
||||
describe('null requestData', () => {
|
||||
it('returns null', () => {
|
||||
const { container } = renderForm(null);
|
||||
expect(container.firstChild).toBeNull();
|
||||
shallowRender(null);
|
||||
expect(el.isEmptyRender()).toEqual(true);
|
||||
});
|
||||
});
|
||||
describe('valid requestData', () => {
|
||||
beforeEach(() => {
|
||||
shallowRender(requestData);
|
||||
});
|
||||
test('snapshot', () => {
|
||||
expect(el.snapshot).toMatchSnapshot();
|
||||
});
|
||||
it('loads Form with requestData url', () => {
|
||||
const { container } = renderForm(requestData);
|
||||
const creditForm = container.querySelector('form');
|
||||
expect(creditForm).toBeInTheDocument();
|
||||
expect(creditForm).toHaveAttribute('action', requestData.url);
|
||||
expect(el.instance.findByType('Form')[0].props.action).toEqual(requestData.url);
|
||||
});
|
||||
it('loads a textarea form control for each requestData parameter', () => {
|
||||
const { container } = renderForm(requestData);
|
||||
const controls = container.querySelectorAll('textarea');
|
||||
expect(controls.length).toEqual(Object.keys(requestData.parameters).length);
|
||||
expect(controls[0]).toHaveAttribute('name', paramKeys.key1);
|
||||
expect(controls[0]).toHaveValue(requestData.parameters.key1);
|
||||
expect(controls[1]).toHaveAttribute('name', paramKeys.key2);
|
||||
expect(controls[1]).toHaveValue(requestData.parameters.key2);
|
||||
expect(controls[2]).toHaveAttribute('name', paramKeys.key3);
|
||||
expect(controls[2]).toHaveValue(requestData.parameters.key3);
|
||||
const controls = el.instance.findByType('FormControl');
|
||||
expect(controls[0].props.name).toEqual(paramKeys.key1);
|
||||
expect(controls[0].props.value).toEqual(requestData.parameters.key1);
|
||||
expect(controls[1].props.name).toEqual(paramKeys.key2);
|
||||
expect(controls[1].props.value).toEqual(requestData.parameters.key2);
|
||||
expect(controls[2].props.name).toEqual(paramKeys.key3);
|
||||
expect(controls[2].props.value).toEqual(requestData.parameters.key3);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,9 @@ import { render } from '@testing-library/react';
|
||||
import useCreditRequestFormData from './hooks';
|
||||
import CreditRequestForm from '.';
|
||||
|
||||
jest.unmock('@openedx/paragon');
|
||||
jest.unmock('react');
|
||||
|
||||
jest.mock('./hooks', () => ({
|
||||
__esModule: true,
|
||||
default: jest.fn(),
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { useCourseData } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import { Hyperlink } from '@openedx/paragon';
|
||||
|
||||
export const ProviderLink = ({ cardId }) => {
|
||||
const courseData = useCourseData(cardId);
|
||||
const credit = courseData?.credit || {};
|
||||
const credit = reduxHooks.useCardCreditData(cardId);
|
||||
return (
|
||||
<Hyperlink
|
||||
href={credit.providerStatusUrl}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import { useCourseData } from 'hooks';
|
||||
import React from 'react';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { reduxHooks } from 'hooks';
|
||||
|
||||
import ProviderLink from './ProviderLink';
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
useCourseData: jest.fn(),
|
||||
reduxHooks: {
|
||||
useCardCreditData: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
const cardId = 'test-card-id';
|
||||
@@ -13,30 +16,27 @@ const credit = {
|
||||
providerStatusUrl: 'test-credit-provider-status-url',
|
||||
providerName: 'test-credit-provider-name',
|
||||
};
|
||||
|
||||
const renderProviderLink = () => render(
|
||||
<IntlProvider locale="en"><ProviderLink cardId={cardId} /></IntlProvider>,
|
||||
);
|
||||
let el;
|
||||
|
||||
describe('ProviderLink component', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
useCourseData.mockReturnValue({ credit });
|
||||
renderProviderLink();
|
||||
reduxHooks.useCardCreditData.mockReturnValue(credit);
|
||||
el = shallow(<ProviderLink cardId={cardId} />);
|
||||
});
|
||||
describe('hooks', () => {
|
||||
describe('behavior', () => {
|
||||
it('initializes credit hook with cardId', () => {
|
||||
expect(useCourseData).toHaveBeenCalledWith(cardId);
|
||||
expect(reduxHooks.useCardCreditData).toHaveBeenCalledWith(cardId);
|
||||
});
|
||||
});
|
||||
describe('render', () => {
|
||||
test('snapshot', () => {
|
||||
expect(el.snapshot).toMatchSnapshot();
|
||||
});
|
||||
it('passes credit.providerStatusUrl to the hyperlink href', () => {
|
||||
const providerLink = screen.getByRole('link', { href: credit.providerStatusUrl });
|
||||
expect(providerLink).toBeInTheDocument();
|
||||
expect(el.instance.findByType('Hyperlink')[0].props.href).toEqual(credit.providerStatusUrl);
|
||||
});
|
||||
it('passes providerName for the link message', () => {
|
||||
const providerLink = screen.getByRole('link', { href: credit.providerStatusUrl });
|
||||
expect(providerLink).toHaveTextContent(credit.providerName);
|
||||
expect(el.instance.findByType('Hyperlink')[0].children[0].el).toEqual(credit.providerName);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`CreditContent component render with action snapshot 1`] = `
|
||||
<Fragment>
|
||||
<div
|
||||
className="message-copy credit-msg"
|
||||
data-testid="credit-msg"
|
||||
>
|
||||
test-message
|
||||
</div>
|
||||
<ActionRow
|
||||
className="mt-4"
|
||||
>
|
||||
<Button
|
||||
as="a"
|
||||
className="border-gray-400"
|
||||
data-testid="action-row-btn"
|
||||
disabled={false}
|
||||
href="test-action-href"
|
||||
onClick={[MockFunction test-action-onClick]}
|
||||
rel="noopener"
|
||||
target="_blank"
|
||||
variant="outline-primary"
|
||||
>
|
||||
test-action-message
|
||||
</Button>
|
||||
</ActionRow>
|
||||
<CreditRequestForm
|
||||
requestData={
|
||||
{
|
||||
"parameters": {
|
||||
"key1": "val1",
|
||||
},
|
||||
"url": "test-request-data-url",
|
||||
}
|
||||
}
|
||||
/>
|
||||
</Fragment>
|
||||
`;
|
||||
|
||||
exports[`CreditContent component render without action snapshot 1`] = `
|
||||
<Fragment>
|
||||
<div
|
||||
className="message-copy credit-msg"
|
||||
data-testid="credit-msg"
|
||||
>
|
||||
test-message
|
||||
</div>
|
||||
<CreditRequestForm
|
||||
requestData={
|
||||
{
|
||||
"parameters": {
|
||||
"key1": "val1",
|
||||
},
|
||||
"url": "test-request-data-url",
|
||||
}
|
||||
}
|
||||
/>
|
||||
</Fragment>
|
||||
`;
|
||||
@@ -0,0 +1,11 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`ProviderLink component render snapshot 1`] = `
|
||||
<Hyperlink
|
||||
href="test-credit-provider-status-url"
|
||||
rel="noopener"
|
||||
target="_blank"
|
||||
>
|
||||
test-credit-provider-name
|
||||
</Hyperlink>
|
||||
`;
|
||||
@@ -1,8 +1,7 @@
|
||||
import React from 'react';
|
||||
import { AppContext } from '@edx/frontend-platform/react';
|
||||
|
||||
import { StrictDict } from 'utils';
|
||||
import { useCourseData } from 'hooks';
|
||||
import { useCreateCreditRequest } from 'data/hooks';
|
||||
import { apiHooks } from 'hooks';
|
||||
|
||||
import * as module from './hooks';
|
||||
|
||||
@@ -12,19 +11,13 @@ export const state = StrictDict({
|
||||
|
||||
export const useCreditRequestData = (cardId) => {
|
||||
const [requestData, setRequestData] = module.state.creditRequestData(null);
|
||||
const courseData = useCourseData(cardId);
|
||||
const providerId = courseData?.credit?.providerId;
|
||||
const { authenticatedUser: { username } } = React.useContext(AppContext);
|
||||
const courseId = courseData?.courseRun?.courseId;
|
||||
const { mutate: createCreditMutation } = useCreateCreditRequest();
|
||||
|
||||
const createCreditApiRequest = apiHooks.useCreateCreditRequest(cardId);
|
||||
const createCreditRequest = (e) => {
|
||||
e.preventDefault();
|
||||
createCreditMutation({ providerId, courseId, username }, {
|
||||
onSuccess: (response) => {
|
||||
setRequestData(response.data);
|
||||
},
|
||||
});
|
||||
createCreditApiRequest()
|
||||
.then((request) => {
|
||||
setRequestData(request.data);
|
||||
});
|
||||
};
|
||||
return { requestData, createCreditRequest };
|
||||
};
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { MockUseState } from 'testUtils';
|
||||
import { apiHooks } from 'hooks';
|
||||
import * as hooks from './hooks';
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
apiHooks: {
|
||||
useCreateCreditRequest: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
const state = new MockUseState(hooks);
|
||||
|
||||
const cardId = 'test-card-id';
|
||||
const requestData = { data: 'request data' };
|
||||
const creditRequest = jest.fn().mockReturnValue(Promise.resolve(requestData));
|
||||
apiHooks.useCreateCreditRequest.mockReturnValue(creditRequest);
|
||||
const event = { preventDefault: jest.fn() };
|
||||
|
||||
let out;
|
||||
describe('Credit Banner view hooks', () => {
|
||||
describe('state', () => {
|
||||
state.testGetter(state.keys.creditRequestData);
|
||||
});
|
||||
describe('useCreditRequestData', () => {
|
||||
beforeEach(() => {
|
||||
state.mock();
|
||||
out = hooks.useCreditRequestData(cardId);
|
||||
});
|
||||
describe('behavior', () => {
|
||||
it('initializes creditRequestData state field with null value', () => {
|
||||
state.expectInitializedWith(state.keys.creditRequestData, null);
|
||||
});
|
||||
it('calls useCreateCreditRequest with passed cardID', () => {
|
||||
expect(apiHooks.useCreateCreditRequest).toHaveBeenCalledWith(cardId);
|
||||
});
|
||||
});
|
||||
describe('output', () => {
|
||||
it('returns requestData state value', () => {
|
||||
state.mockVal(state.keys.creditRequestData, requestData);
|
||||
out = hooks.useCreditRequestData(cardId);
|
||||
expect(out.requestData).toEqual(requestData);
|
||||
});
|
||||
describe('createCreditRequest', () => {
|
||||
it('returns an event handler that prevents default click behavior', () => {
|
||||
out.createCreditRequest(event);
|
||||
expect(event.preventDefault).toHaveBeenCalled();
|
||||
});
|
||||
it('calls api.createCreditRequest and sets requestData with the response', async () => {
|
||||
await out.createCreditRequest(event);
|
||||
expect(creditRequest).toHaveBeenCalledWith();
|
||||
expect(state.setState.creditRequestData).toHaveBeenCalledWith(requestData.data);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,192 +0,0 @@
|
||||
import { renderHook, act, waitFor } from '@testing-library/react';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import React from 'react';
|
||||
import * as api from 'data/services/lms/api';
|
||||
import { useCourseData } from 'hooks';
|
||||
import { AppContext } from '@edx/frontend-platform/react';
|
||||
import * as hooks from './hooks';
|
||||
|
||||
jest.mock('data/services/lms/api', () => ({
|
||||
createCreditRequest: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
useCourseData: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('@edx/frontend-platform/logging', () => ({
|
||||
...jest.requireActual('@edx/frontend-platform/logging'),
|
||||
logError: jest.fn(),
|
||||
}));
|
||||
|
||||
const createWrapper = () => {
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: { retry: false },
|
||||
mutations: { retry: false },
|
||||
},
|
||||
});
|
||||
|
||||
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<AppContext.Provider value={{
|
||||
authenticatedUser: { username: 'test-user' },
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</AppContext.Provider>
|
||||
</QueryClientProvider>
|
||||
);
|
||||
return wrapper;
|
||||
};
|
||||
|
||||
describe('useCreditRequestData', () => {
|
||||
let wrapper;
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = createWrapper();
|
||||
(useCourseData as jest.Mock).mockReturnValue({
|
||||
credit: { providerId: 'provider-123' },
|
||||
courseRun: { courseId: 'course-456' },
|
||||
});
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('initializes requestData as null', () => {
|
||||
const { result } = renderHook(() => hooks.useCreditRequestData('card-123'), { wrapper });
|
||||
|
||||
expect(result.current.requestData).toBeNull();
|
||||
});
|
||||
|
||||
it('returns createCreditRequest function', () => {
|
||||
const { result } = renderHook(() => hooks.useCreditRequestData('card-123'), { wrapper });
|
||||
|
||||
expect(typeof result.current.createCreditRequest).toBe('function');
|
||||
});
|
||||
|
||||
it('prevents default event behavior', async () => {
|
||||
const event = { preventDefault: jest.fn() };
|
||||
(api.createCreditRequest as jest.Mock).mockResolvedValue({ data: 'success' });
|
||||
|
||||
const { result } = renderHook(() => hooks.useCreditRequestData('card-123'), { wrapper });
|
||||
|
||||
await act(async () => {
|
||||
result.current.createCreditRequest(event);
|
||||
});
|
||||
|
||||
expect(event.preventDefault).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('calls API with correct parameters', async () => {
|
||||
const event = { preventDefault: jest.fn() };
|
||||
(api.createCreditRequest as jest.Mock).mockResolvedValue({ data: 'success' });
|
||||
|
||||
const { result } = renderHook(() => hooks.useCreditRequestData('card-123'), { wrapper });
|
||||
|
||||
await act(async () => {
|
||||
result.current.createCreditRequest(event);
|
||||
});
|
||||
|
||||
expect(api.createCreditRequest).toHaveBeenCalledWith({
|
||||
providerId: 'provider-123',
|
||||
courseId: 'course-456',
|
||||
username: 'test-user',
|
||||
});
|
||||
});
|
||||
|
||||
it('sets requestData with response data on success', async () => {
|
||||
const event = { preventDefault: jest.fn() };
|
||||
const responseData = { data: { id: 'credit-123', status: 'pending' } };
|
||||
(api.createCreditRequest as jest.Mock).mockResolvedValue(responseData);
|
||||
|
||||
const { result } = renderHook(() => hooks.useCreditRequestData('card-123'), { wrapper });
|
||||
|
||||
await act(async () => {
|
||||
result.current.createCreditRequest(event);
|
||||
});
|
||||
|
||||
expect(api.createCreditRequest).toHaveBeenCalledWith({
|
||||
providerId: 'provider-123',
|
||||
courseId: 'course-456',
|
||||
username: 'test-user',
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.requestData).toEqual(responseData.data);
|
||||
});
|
||||
});
|
||||
|
||||
it('handles missing providerId gracefully', async () => {
|
||||
const event = { preventDefault: jest.fn() };
|
||||
(useCourseData as jest.Mock).mockReturnValue({
|
||||
credit: null,
|
||||
courseRun: { courseId: 'course-456' },
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => hooks.useCreditRequestData('card-123'), { wrapper });
|
||||
|
||||
await act(async () => {
|
||||
result.current.createCreditRequest(event);
|
||||
});
|
||||
|
||||
expect(api.createCreditRequest).toHaveBeenCalledWith({
|
||||
providerId: undefined,
|
||||
courseId: 'course-456',
|
||||
username: 'test-user',
|
||||
});
|
||||
});
|
||||
|
||||
it('handles missing courseId gracefully', async () => {
|
||||
const event = { preventDefault: jest.fn() };
|
||||
(useCourseData as jest.Mock).mockReturnValue({
|
||||
credit: { providerId: 'provider-123' },
|
||||
courseRun: null,
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => hooks.useCreditRequestData('card-123'), { wrapper });
|
||||
|
||||
await act(async () => {
|
||||
result.current.createCreditRequest(event);
|
||||
});
|
||||
|
||||
expect(api.createCreditRequest).toHaveBeenCalledWith({
|
||||
providerId: 'provider-123',
|
||||
courseId: undefined,
|
||||
username: 'test-user',
|
||||
});
|
||||
});
|
||||
|
||||
it('handles API errors without crashing', async () => {
|
||||
const event = { preventDefault: jest.fn() };
|
||||
(api.createCreditRequest as jest.Mock).mockRejectedValue(new Error('API Error'));
|
||||
|
||||
const { result } = renderHook(() => hooks.useCreditRequestData('card-123'), { wrapper });
|
||||
|
||||
await act(async () => {
|
||||
result.current.createCreditRequest(event);
|
||||
});
|
||||
|
||||
expect(result.current.requestData).toBeNull();
|
||||
});
|
||||
|
||||
it('uses cardId to fetch course data', () => {
|
||||
renderHook(() => hooks.useCreditRequestData('different-card'), { wrapper });
|
||||
|
||||
expect(useCourseData).toHaveBeenCalledWith('different-card');
|
||||
});
|
||||
|
||||
it('handles undefined response data', async () => {
|
||||
const event = { preventDefault: jest.fn() };
|
||||
(api.createCreditRequest as jest.Mock).mockResolvedValue({ status: 200 });
|
||||
|
||||
const { result } = renderHook(() => hooks.useCreditRequestData('card-123'), { wrapper });
|
||||
|
||||
await act(async () => {
|
||||
result.current.createCreditRequest(event);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.requestData).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,21 +1,16 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
import { Button, MailtoLink } from '@openedx/paragon';
|
||||
|
||||
import { utilHooks, useCourseData, useEntitlementInfo } from 'hooks';
|
||||
import { useSelectSessionModal } from 'data/context';
|
||||
import Banner from 'components/Banner';
|
||||
import { useInitializeLearnerHome } from 'data/hooks';
|
||||
import { utilHooks, reduxHooks } from 'hooks';
|
||||
|
||||
import Banner from 'components/Banner';
|
||||
import messages from './messages';
|
||||
|
||||
export const EntitlementBanner = ({ cardId }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const { data: learnerHomeData } = useInitializeLearnerHome();
|
||||
const courseData = useCourseData(cardId);
|
||||
|
||||
const {
|
||||
isEntitlement,
|
||||
hasSessions,
|
||||
@@ -23,12 +18,9 @@ export const EntitlementBanner = ({ cardId }) => {
|
||||
changeDeadline,
|
||||
showExpirationWarning,
|
||||
isExpired,
|
||||
} = useEntitlementInfo(courseData);
|
||||
const supportEmail = useMemo(
|
||||
() => learnerHomeData?.platformSettings?.supportEmail,
|
||||
[learnerHomeData],
|
||||
);
|
||||
const { updateSelectSessionModal } = useSelectSessionModal();
|
||||
} = reduxHooks.useCardEntitlementData(cardId);
|
||||
const { supportEmail } = reduxHooks.usePlatformSettingsData();
|
||||
const openSessionModal = reduxHooks.useUpdateSelectSessionModalCallback(cardId);
|
||||
const formatDate = utilHooks.useFormatDate();
|
||||
|
||||
if (!isEntitlement) {
|
||||
@@ -50,7 +42,7 @@ export const EntitlementBanner = ({ cardId }) => {
|
||||
{formatMessage(messages.entitlementExpiringSoon, {
|
||||
changeDeadline: formatDate(changeDeadline),
|
||||
selectSessionButton: (
|
||||
<Button variant="link" size="inline" className="m-0 p-0" onClick={() => updateSelectSessionModal(cardId)}>
|
||||
<Button variant="link" size="inline" className="m-0 p-0" onClick={openSessionModal}>
|
||||
{formatMessage(messages.selectSession)}
|
||||
</Button>
|
||||
),
|
||||
|
||||
@@ -1,43 +1,26 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import { formatMessage } from 'testUtils';
|
||||
import React from 'react';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { useCourseData } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import EntitlementBanner from './EntitlementBanner';
|
||||
import messages from './messages';
|
||||
|
||||
jest.mock('react', () => ({
|
||||
...jest.requireActual('react'),
|
||||
useMemo: (fn) => fn(),
|
||||
}));
|
||||
|
||||
jest.mock('data/hooks', () => ({
|
||||
useInitializeLearnerHome: jest.fn().mockReturnValue({
|
||||
data: {
|
||||
platformSettings: {
|
||||
supportEmail: 'test-support-email',
|
||||
},
|
||||
},
|
||||
}),
|
||||
}));
|
||||
const mockUpdateSelectSessionModal = jest.fn().mockName('updateSelectSessionModal');
|
||||
jest.mock('data/context/SelectSessionProvider', () => ({
|
||||
useSelectSessionModal: () => ({
|
||||
updateSelectSessionModal: mockUpdateSelectSessionModal,
|
||||
}),
|
||||
}));
|
||||
|
||||
jest.mock('components/Banner', () => 'Banner');
|
||||
jest.mock('hooks', () => ({
|
||||
...jest.requireActual('hooks'),
|
||||
useCourseData: jest.fn(),
|
||||
utilHooks: {
|
||||
useFormatDate: () => date => date?.toDateString(),
|
||||
useFormatDate: () => date => date,
|
||||
},
|
||||
reduxHooks: {
|
||||
usePlatformSettingsData: jest.fn(),
|
||||
useCardEntitlementData: jest.fn(),
|
||||
useUpdateSelectSessionModalCallback: jest.fn(
|
||||
(cardId) => jest.fn().mockName(`updateSelectSessionModalCallback(${cardId})`),
|
||||
),
|
||||
},
|
||||
|
||||
}));
|
||||
|
||||
const cardId = 'test-card-id';
|
||||
const cardId = 'my-test-course-number';
|
||||
|
||||
let el;
|
||||
|
||||
const entitlementData = {
|
||||
isEntitlement: true,
|
||||
@@ -48,78 +31,33 @@ const entitlementData = {
|
||||
};
|
||||
const platformData = { supportEmail: 'test-support-email' };
|
||||
|
||||
const renderComponent = (overrides = {}) => {
|
||||
const render = (overrides = {}) => {
|
||||
const { entitlement = {} } = overrides;
|
||||
useCourseData.mockReturnValue({
|
||||
entitlement: { ...entitlementData, ...entitlement },
|
||||
platformSettings: platformData,
|
||||
});
|
||||
return render(<IntlProvider locale="en"><EntitlementBanner cardId={cardId} /></IntlProvider>);
|
||||
reduxHooks.useCardEntitlementData.mockReturnValueOnce({ ...entitlementData, ...entitlement });
|
||||
reduxHooks.usePlatformSettingsData.mockReturnValueOnce(platformData);
|
||||
el = shallow(<EntitlementBanner cardId={cardId} />);
|
||||
};
|
||||
|
||||
describe('EntitlementBanner', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
test('initializes data with course number from entitlement', () => {
|
||||
render();
|
||||
expect(reduxHooks.useCardEntitlementData).toHaveBeenCalledWith(cardId);
|
||||
expect(reduxHooks.useUpdateSelectSessionModalCallback).toHaveBeenCalledWith(cardId);
|
||||
});
|
||||
it('initializes data with course number from entitlement', () => {
|
||||
renderComponent();
|
||||
expect(useCourseData).toHaveBeenCalledWith(cardId);
|
||||
test('no display if not an entitlement', () => {
|
||||
render({ entitlement: { isEntitlement: false } });
|
||||
expect(el.isEmptyRender()).toEqual(true);
|
||||
});
|
||||
it('no display if not an entitlement', () => {
|
||||
renderComponent({ entitlement: { isEntitlement: false } });
|
||||
const banner = screen.queryByRole('alert');
|
||||
expect(banner).toBeNull();
|
||||
test('snapshot: no sessions available', () => {
|
||||
render({ entitlement: { isFulfilled: false, hasSessions: false } });
|
||||
expect(el.snapshot).toMatchSnapshot();
|
||||
});
|
||||
it('renders when no sessions available', () => {
|
||||
renderComponent({ entitlement: { isFulfilled: false, hasSessions: false } });
|
||||
const banner = screen.getByRole('alert');
|
||||
expect(banner).toBeInTheDocument();
|
||||
expect(banner).toHaveClass('alert-warning');
|
||||
expect(banner.innerHTML).toContain(platformData.supportEmail);
|
||||
test('snapshot: expiration warning', () => {
|
||||
render({ entitlement: { showExpirationWarning: true } });
|
||||
expect(el.snapshot).toMatchSnapshot();
|
||||
});
|
||||
it('renders when expiration warning', () => {
|
||||
const deadline = new Date();
|
||||
deadline.setDate(deadline.getDate() + 4);
|
||||
const deadlineStr = `${deadline.getMonth() + 1}/${deadline.getDate()}/${deadline.getFullYear()}`;
|
||||
renderComponent({ entitlement: { changeDeadline: deadlineStr, isFulfilled: false, availableSessions: [1, 2, 3] } });
|
||||
const banner = screen.getByRole('alert');
|
||||
expect(banner).toBeInTheDocument();
|
||||
expect(banner).toHaveClass('alert-info');
|
||||
const button = screen.getByRole('button', { name: formatMessage(messages.selectSession) });
|
||||
expect(button).toBeInTheDocument();
|
||||
});
|
||||
it('renders expired banner', () => {
|
||||
renderComponent({ entitlement: { isExpired: true, availableSessions: [1, 2, 3] } });
|
||||
const banner = screen.getByRole('alert');
|
||||
expect(banner).toBeInTheDocument();
|
||||
expect(banner.innerHTML).toContain(formatMessage(messages.entitlementExpired));
|
||||
});
|
||||
it('should call updateSelectSessionModal with cardId when select session button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
const deadline = new Date();
|
||||
deadline.setDate(deadline.getDate() + 4);
|
||||
const deadlineStr = `${deadline.getMonth() + 1}/${deadline.getDate()}/${deadline.getFullYear()}`;
|
||||
renderComponent({ entitlement: { changeDeadline: deadlineStr, isFulfilled: false, availableSessions: [1, 2, 3] } });
|
||||
const banner = screen.getByRole('alert');
|
||||
expect(banner).toBeInTheDocument();
|
||||
expect(banner).toHaveClass('alert-info');
|
||||
const button = screen.getByRole('button', { name: formatMessage(messages.selectSession) });
|
||||
expect(button).toBeInTheDocument();
|
||||
await user.click(button);
|
||||
|
||||
expect(mockUpdateSelectSessionModal).toHaveBeenCalledWith(cardId);
|
||||
});
|
||||
it('should return null when isExpired is false and showExpirationWarning is false', () => {
|
||||
renderComponent({
|
||||
entitlement: {
|
||||
isEntitlement: true,
|
||||
hasSessions: true,
|
||||
isFulfilled: true,
|
||||
showExpirationWarning: false,
|
||||
isExpired: false,
|
||||
},
|
||||
});
|
||||
const banner = screen.queryByRole('alert');
|
||||
expect(banner).toBeNull();
|
||||
test('no display if sessions available and not displaying warning', () => {
|
||||
render();
|
||||
expect(el.isEmptyRender()).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { ProgramsList } from './ProgramsList';
|
||||
|
||||
@@ -9,23 +9,15 @@ describe('ProgramsList', () => {
|
||||
title: 'Example Program 1',
|
||||
},
|
||||
{
|
||||
programUrl: 'http://example2.com',
|
||||
programUrl: 'http://example.com',
|
||||
title: 'Example Program 2',
|
||||
},
|
||||
];
|
||||
|
||||
it('renders correctly', () => {
|
||||
render(<ProgramsList programs={programs} />);
|
||||
const list = screen.getByRole('list');
|
||||
expect(list).toBeInTheDocument();
|
||||
expect(list.children.length).toEqual(programs.length);
|
||||
});
|
||||
const wrapper = shallow(<ProgramsList programs={programs} />);
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
|
||||
it('add the links correctly', () => {
|
||||
render(<ProgramsList programs={programs} />);
|
||||
programs.forEach(program => {
|
||||
const link = screen.getByRole('link', { name: program.title });
|
||||
expect(link).toHaveAttribute('href', program.url);
|
||||
});
|
||||
expect(wrapper.instance.findByType('li').length).toEqual(programs.length);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`ProgramsList renders correctly 1`] = `
|
||||
<ul
|
||||
className="related-programs-list-container"
|
||||
>
|
||||
<li
|
||||
className="my-2"
|
||||
key="http://example.com"
|
||||
>
|
||||
<a
|
||||
href="http://example.com"
|
||||
>
|
||||
Example Program 1
|
||||
</a>
|
||||
</li>
|
||||
<li
|
||||
className="my-2"
|
||||
key="http://example.com"
|
||||
>
|
||||
<a
|
||||
href="http://example.com"
|
||||
>
|
||||
Example Program 2
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
`;
|
||||
@@ -0,0 +1,29 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`RelatedProgramsBanner render with programs 1`] = `
|
||||
<Banner
|
||||
className="bg-white border-top border-bottom mb-0 related-programs-banner"
|
||||
icon={[MockFunction icons.Program]}
|
||||
variant="info"
|
||||
>
|
||||
<span
|
||||
className="font-weight-bolder"
|
||||
>
|
||||
Related Programs:
|
||||
</span>
|
||||
<ProgramsList
|
||||
programs={
|
||||
[
|
||||
{
|
||||
"title": "Program 1",
|
||||
"url": "http://example.com/program1",
|
||||
},
|
||||
{
|
||||
"title": "Program 2",
|
||||
"url": "http://example.com/program2",
|
||||
},
|
||||
]
|
||||
}
|
||||
/>
|
||||
</Banner>
|
||||
`;
|
||||
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
|
||||
import { Program } from '@openedx/paragon/icons';
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
|
||||
import { useCourseData } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import Banner from 'components/Banner';
|
||||
|
||||
import ProgramList from './ProgramsList';
|
||||
@@ -12,10 +12,10 @@ import messages from './messages';
|
||||
|
||||
export const RelatedProgramsBanner = ({ cardId }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const courseData = useCourseData(cardId);
|
||||
const programData = courseData?.programs;
|
||||
|
||||
if (!courseData || !programData?.relatedPrograms.length) {
|
||||
const programData = reduxHooks.useCardRelatedProgramsData(cardId);
|
||||
|
||||
if (!programData?.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ export const RelatedProgramsBanner = ({ cardId }) => {
|
||||
<span className="font-weight-bolder">
|
||||
{formatMessage(messages.relatedPrograms)}
|
||||
</span>
|
||||
<ProgramList programs={programData.relatedPrograms} />
|
||||
<ProgramList programs={programData.list} />
|
||||
</Banner>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,47 +1,42 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { useCourseData } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import RelatedProgramsBanner from '.';
|
||||
|
||||
jest.mock('./ProgramsList', () => 'ProgramsList');
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
useCourseData: jest.fn(),
|
||||
reduxHooks: {
|
||||
useCardRelatedProgramsData: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
const cardId = 'test-card-id';
|
||||
const programData = {
|
||||
list: [
|
||||
{
|
||||
title: 'Program 1',
|
||||
url: 'http://example.com/program1',
|
||||
},
|
||||
{
|
||||
title: 'Program 2',
|
||||
url: 'http://example.com/program2',
|
||||
},
|
||||
],
|
||||
length: 2,
|
||||
};
|
||||
|
||||
describe('RelatedProgramsBanner', () => {
|
||||
it('render empty', () => {
|
||||
useCourseData.mockReturnValue(null);
|
||||
render(<IntlProvider locale="en"><RelatedProgramsBanner cardId={cardId} /></IntlProvider>);
|
||||
const banner = screen.queryByRole('alert');
|
||||
expect(banner).toBeNull();
|
||||
test('render empty', () => {
|
||||
reduxHooks.useCardRelatedProgramsData.mockReturnValue({
|
||||
length: 0,
|
||||
});
|
||||
const el = shallow(<RelatedProgramsBanner cardId={cardId} />);
|
||||
expect(el.isEmptyRender()).toEqual(true);
|
||||
});
|
||||
|
||||
it('render with programs', () => {
|
||||
useCourseData.mockReturnValue({ programs: { relatedPrograms: programData.list } });
|
||||
render(<IntlProvider locale="en"><RelatedProgramsBanner cardId={cardId} /></IntlProvider>);
|
||||
const list = screen.getByRole('list');
|
||||
expect(list.childElementCount).toBe(programData.list.length);
|
||||
});
|
||||
|
||||
it('render related programs title', () => {
|
||||
useCourseData.mockReturnValue({ programs: { relatedPrograms: programData.list } });
|
||||
render(<IntlProvider locale="en"><RelatedProgramsBanner cardId={cardId} /></IntlProvider>);
|
||||
const title = screen.getByText('Related Programs:');
|
||||
expect(title).toBeInTheDocument();
|
||||
test('render with programs', () => {
|
||||
reduxHooks.useCardRelatedProgramsData.mockReturnValue({
|
||||
list: [
|
||||
{
|
||||
title: 'Program 1',
|
||||
url: 'http://example.com/program1',
|
||||
},
|
||||
{
|
||||
title: 'Program 2',
|
||||
url: 'http://example.com/program2',
|
||||
},
|
||||
],
|
||||
length: 2,
|
||||
});
|
||||
const el = shallow(<RelatedProgramsBanner cardId={cardId} />);
|
||||
expect(el.snapshot).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`CertificateBanner snapshot is passing and is downloadable 1`] = `
|
||||
<Banner
|
||||
icon={[MockFunction icons.CheckCircle]}
|
||||
variant="success"
|
||||
>
|
||||
Congratulations. Your certificate is ready.
|
||||
</Banner>
|
||||
`;
|
||||
|
||||
exports[`CertificateBanner snapshot is passing and is earned but unavailable 1`] = `
|
||||
<Banner>
|
||||
Your grade and certificate will be ready after 10/20/3030.
|
||||
</Banner>
|
||||
`;
|
||||
|
||||
exports[`CertificateBanner snapshot is passing and not downloadable render empty 1`] = `null`;
|
||||
|
||||
exports[`CertificateBanner snapshot is restricted 1`] = `
|
||||
<Banner
|
||||
variant="danger"
|
||||
>
|
||||
Your Certificate of Achievement is being held pending confirmation that the issuance of your Certificate is in compliance with strict U.S. embargoes on Iran, Cuba, Syria, and Sudan. If you think our system has mistakenly identified you as being connected with one of those countries, please let us know.
|
||||
</Banner>
|
||||
`;
|
||||
|
||||
exports[`CertificateBanner snapshot is restricted and verified 1`] = `
|
||||
<Banner
|
||||
variant="danger"
|
||||
>
|
||||
Your Certificate of Achievement is being held pending confirmation that the issuance of your Certificate is in compliance with strict U.S. embargoes on Iran, Cuba, Syria, and Sudan. If you think our system has mistakenly identified you as being connected with one of those countries, please let us know.
|
||||
|
||||
If you would like a refund on your Certificate of Achievement, please contact us.
|
||||
</Banner>
|
||||
`;
|
||||
|
||||
exports[`CertificateBanner snapshot is restricted and verified with billing email 1`] = `
|
||||
<Banner
|
||||
variant="danger"
|
||||
>
|
||||
Your Certificate of Achievement is being held pending confirmation that the issuance of your Certificate is in compliance with strict U.S. embargoes on Iran, Cuba, Syria, and Sudan. If you think our system has mistakenly identified you as being connected with one of those countries, please let us know.
|
||||
|
||||
<format-message-function
|
||||
message={
|
||||
{
|
||||
"defaultMessage": "If you would like a refund on your Certificate of Achievement, please contact our billing address {billingEmail}",
|
||||
"description": "Message to learners to contact billing for certificate refunds",
|
||||
"id": "learner-dash.courseCard.banners.certificateRefundContactBilling",
|
||||
}
|
||||
}
|
||||
values={
|
||||
{
|
||||
"billingEmail": <MailtoLink
|
||||
to="billing@email"
|
||||
>
|
||||
billing@email
|
||||
</MailtoLink>,
|
||||
}
|
||||
}
|
||||
/>
|
||||
</Banner>
|
||||
`;
|
||||
|
||||
exports[`CertificateBanner snapshot is restricted and verified with support and billing email 1`] = `
|
||||
<Banner
|
||||
variant="danger"
|
||||
>
|
||||
<format-message-function
|
||||
message={
|
||||
{
|
||||
"defaultMessage": "Your Certificate of Achievement is being held pending confirmation that the issuance of your Certificate is in compliance with strict U.S. embargoes on Iran, Cuba, Syria, and Sudan. If you think our system has mistakenly identified you as being connected with one of those countries, please let us know by contacting {supportEmail}.",
|
||||
"description": "Restricted certificate warning message",
|
||||
"id": "learner-dash.courseCard.banners.certificateRestricted",
|
||||
}
|
||||
}
|
||||
values={
|
||||
{
|
||||
"supportEmail": <MailtoLink
|
||||
to="suport@email"
|
||||
>
|
||||
suport@email
|
||||
</MailtoLink>,
|
||||
}
|
||||
}
|
||||
/>
|
||||
|
||||
<format-message-function
|
||||
message={
|
||||
{
|
||||
"defaultMessage": "If you would like a refund on your Certificate of Achievement, please contact our billing address {billingEmail}",
|
||||
"description": "Message to learners to contact billing for certificate refunds",
|
||||
"id": "learner-dash.courseCard.banners.certificateRefundContactBilling",
|
||||
}
|
||||
}
|
||||
values={
|
||||
{
|
||||
"billingEmail": <MailtoLink
|
||||
to="billing@email"
|
||||
>
|
||||
billing@email
|
||||
</MailtoLink>,
|
||||
}
|
||||
}
|
||||
/>
|
||||
</Banner>
|
||||
`;
|
||||
|
||||
exports[`CertificateBanner snapshot is restricted and verified with support email 1`] = `
|
||||
<Banner
|
||||
variant="danger"
|
||||
>
|
||||
<format-message-function
|
||||
message={
|
||||
{
|
||||
"defaultMessage": "Your Certificate of Achievement is being held pending confirmation that the issuance of your Certificate is in compliance with strict U.S. embargoes on Iran, Cuba, Syria, and Sudan. If you think our system has mistakenly identified you as being connected with one of those countries, please let us know by contacting {supportEmail}.",
|
||||
"description": "Restricted certificate warning message",
|
||||
"id": "learner-dash.courseCard.banners.certificateRestricted",
|
||||
}
|
||||
}
|
||||
values={
|
||||
{
|
||||
"supportEmail": <MailtoLink
|
||||
to="suport@email"
|
||||
>
|
||||
suport@email
|
||||
</MailtoLink>,
|
||||
}
|
||||
}
|
||||
/>
|
||||
|
||||
If you would like a refund on your Certificate of Achievement, please contact us.
|
||||
</Banner>
|
||||
`;
|
||||
|
||||
exports[`CertificateBanner snapshot is restricted with billing email 1`] = `
|
||||
<Banner
|
||||
variant="danger"
|
||||
>
|
||||
Your Certificate of Achievement is being held pending confirmation that the issuance of your Certificate is in compliance with strict U.S. embargoes on Iran, Cuba, Syria, and Sudan. If you think our system has mistakenly identified you as being connected with one of those countries, please let us know.
|
||||
</Banner>
|
||||
`;
|
||||
|
||||
exports[`CertificateBanner snapshot is restricted with support email 1`] = `
|
||||
<Banner
|
||||
variant="danger"
|
||||
>
|
||||
<format-message-function
|
||||
message={
|
||||
{
|
||||
"defaultMessage": "Your Certificate of Achievement is being held pending confirmation that the issuance of your Certificate is in compliance with strict U.S. embargoes on Iran, Cuba, Syria, and Sudan. If you think our system has mistakenly identified you as being connected with one of those countries, please let us know by contacting {supportEmail}.",
|
||||
"description": "Restricted certificate warning message",
|
||||
"id": "learner-dash.courseCard.banners.certificateRestricted",
|
||||
}
|
||||
}
|
||||
values={
|
||||
{
|
||||
"supportEmail": <MailtoLink
|
||||
to="suport@email"
|
||||
>
|
||||
suport@email
|
||||
</MailtoLink>,
|
||||
}
|
||||
}
|
||||
/>
|
||||
</Banner>
|
||||
`;
|
||||
|
||||
exports[`CertificateBanner snapshot not passing and audit 1`] = `
|
||||
<Banner>
|
||||
Grade required to pass the course: 0.8%
|
||||
</Banner>
|
||||
`;
|
||||
|
||||
exports[`CertificateBanner snapshot not passing and has finished 1`] = `
|
||||
<Banner
|
||||
variant="warning"
|
||||
>
|
||||
You are not eligible for a certificate.
|
||||
|
||||
<Hyperlink
|
||||
destination="progressUrl"
|
||||
isInline={true}
|
||||
>
|
||||
View grades.
|
||||
</Hyperlink>
|
||||
</Banner>
|
||||
`;
|
||||
|
||||
exports[`CertificateBanner snapshot not passing and is downloadable 1`] = `
|
||||
<Banner
|
||||
icon={[MockFunction icons.CheckCircle]}
|
||||
variant="success"
|
||||
>
|
||||
Congratulations. Your certificate is ready.
|
||||
</Banner>
|
||||
`;
|
||||
|
||||
exports[`CertificateBanner snapshot not passing and not audit and not finished 1`] = `
|
||||
<Banner
|
||||
variant="warning"
|
||||
>
|
||||
Grade required for a certificate: 0.8%
|
||||
</Banner>
|
||||
`;
|
||||
@@ -0,0 +1,38 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`CourseBanner audit access expired snapshot: (auditAccessExpired, findAnotherCourse hyperlink) 1`] = `
|
||||
<Fragment>
|
||||
<Banner>
|
||||
Your audit access to this course has expired.
|
||||
|
||||
<Hyperlink
|
||||
destination=""
|
||||
isInline={true}
|
||||
>
|
||||
Find another course
|
||||
</Hyperlink>
|
||||
</Banner>
|
||||
</Fragment>
|
||||
`;
|
||||
|
||||
exports[`CourseBanner snapshot: stacking banners 1`] = `<Fragment />`;
|
||||
|
||||
exports[`CourseBanner staff snapshot: isStaff 1`] = `<Fragment />`;
|
||||
|
||||
exports[`CourseBanner too early has start date snapshot 1`] = `
|
||||
<Fragment>
|
||||
<Banner>
|
||||
You can't access this course just yet because the course hasn't started yet. The course will start on 11/11/3030.
|
||||
</Banner>
|
||||
</Fragment>
|
||||
`;
|
||||
|
||||
exports[`CourseBanner too early no start date snapshot 1`] = `<Fragment />`;
|
||||
|
||||
exports[`CourseBanner unmet prerequisites snapshot: unmetPrerequisites 1`] = `
|
||||
<Fragment>
|
||||
<Banner>
|
||||
You can't access this course just yet because you have not met the pre-requisites.
|
||||
</Banner>
|
||||
</Fragment>
|
||||
`;
|
||||
@@ -0,0 +1,53 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`EntitlementBanner snapshot: expiration warning 1`] = `
|
||||
<Banner>
|
||||
<format-message-function
|
||||
message={
|
||||
{
|
||||
"defaultMessage": "You must {selectSessionButton} by {changeDeadline} to access the course.",
|
||||
"description": "Entitlement course message when the entitlement is expiring soon.",
|
||||
"id": "learner-dash.courseCard.banners.entitlementExpiringSoon",
|
||||
}
|
||||
}
|
||||
values={
|
||||
{
|
||||
"changeDeadline": "11/11/2022",
|
||||
"selectSessionButton": <Button
|
||||
className="m-0 p-0"
|
||||
onClick={[MockFunction updateSelectSessionModalCallback(my-test-course-number)]}
|
||||
size="inline"
|
||||
variant="link"
|
||||
>
|
||||
select a session
|
||||
</Button>,
|
||||
}
|
||||
}
|
||||
/>
|
||||
</Banner>
|
||||
`;
|
||||
|
||||
exports[`EntitlementBanner snapshot: no sessions available 1`] = `
|
||||
<Banner
|
||||
variant="warning"
|
||||
>
|
||||
<format-message-function
|
||||
message={
|
||||
{
|
||||
"defaultMessage": "There are no sessions available at the moment. The course team will create new sessions soon. If no sessions appear, please contact {emailLink} for information.",
|
||||
"description": "Entitlement course message when no sessions are available",
|
||||
"id": "learner-dash.courseCard.banners.entitlementUnavailable",
|
||||
}
|
||||
}
|
||||
values={
|
||||
{
|
||||
"emailLink": <MailtoLink
|
||||
to="test-support-email"
|
||||
>
|
||||
test-support-email
|
||||
</MailtoLink>,
|
||||
}
|
||||
}
|
||||
/>
|
||||
</Banner>
|
||||
`;
|
||||
@@ -0,0 +1,41 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`CourseCardBanners render with isEnrolled false 1`] = `
|
||||
<div
|
||||
className="course-card-banners"
|
||||
data-testid="CourseCardBanners"
|
||||
>
|
||||
<RelatedProgramsBanner
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
<CourseBannerSlot
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
<EntitlementBanner
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`CourseCardBanners renders default CourseCardBanners 1`] = `
|
||||
<div
|
||||
className="course-card-banners"
|
||||
data-testid="CourseCardBanners"
|
||||
>
|
||||
<RelatedProgramsBanner
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
<CourseBannerSlot
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
<EntitlementBanner
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
<CertificateBanner
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
<CreditBanner
|
||||
cardId="test-card-id"
|
||||
/>
|
||||
</div>
|
||||
`;
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { useCourseData } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
|
||||
import CourseBannerSlot from 'plugin-slots/CourseBannerSlot';
|
||||
import CertificateBanner from './CertificateBanner';
|
||||
@@ -10,11 +10,7 @@ import EntitlementBanner from './EntitlementBanner';
|
||||
import RelatedProgramsBanner from './RelatedProgramsBanner';
|
||||
|
||||
export const CourseCardBanners = ({ cardId }) => {
|
||||
const courseData = useCourseData(cardId);
|
||||
if (!courseData) {
|
||||
return null;
|
||||
}
|
||||
const { isEnrolled = false } = courseData.enrollment;
|
||||
const { isEnrolled } = reduxHooks.useCardEnrollmentData(cardId);
|
||||
return (
|
||||
<div className="course-card-banners" data-testid="CourseCardBanners">
|
||||
<RelatedProgramsBanner cardId={cardId} />
|
||||
|
||||
@@ -1,55 +1,32 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { useCourseData } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
|
||||
import CourseCardBanners from '.';
|
||||
|
||||
jest.mock('./CourseBanner', () => jest.fn(() => <div>CourseBanner</div>));
|
||||
jest.mock('./CertificateBanner', () => jest.fn(() => <div>CertificateBanner</div>));
|
||||
jest.mock('./CreditBanner', () => jest.fn(() => <div>CreditBanner</div>));
|
||||
jest.mock('./EntitlementBanner', () => jest.fn(() => <div>EntitlementBanner</div>));
|
||||
jest.mock('./RelatedProgramsBanner', () => jest.fn(() => <div>RelatedProgramsBanner</div>));
|
||||
|
||||
const mockedComponents = [
|
||||
'CourseBanner',
|
||||
'CertificateBanner',
|
||||
'CreditBanner',
|
||||
'EntitlementBanner',
|
||||
'RelatedProgramsBanner',
|
||||
];
|
||||
jest.mock('./CourseBanner', () => 'CourseBanner');
|
||||
jest.mock('./CertificateBanner', () => 'CertificateBanner');
|
||||
jest.mock('./CreditBanner', () => 'CreditBanner');
|
||||
jest.mock('./EntitlementBanner', () => 'EntitlementBanner');
|
||||
jest.mock('./RelatedProgramsBanner', () => 'RelatedProgramsBanner');
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
useCourseData: jest.fn(() => ({
|
||||
enrollment: {
|
||||
isEnrolled: true,
|
||||
},
|
||||
})),
|
||||
reduxHooks: {
|
||||
useCardEnrollmentData: jest.fn(() => ({ isEnrolled: true })),
|
||||
},
|
||||
}));
|
||||
|
||||
describe('CourseCardBanners', () => {
|
||||
const props = {
|
||||
cardId: 'test-card-id',
|
||||
};
|
||||
it('renders default CourseCardBanners', () => {
|
||||
render(<IntlProvider locale="en"><CourseCardBanners {...props} /></IntlProvider>);
|
||||
mockedComponents.map((componentName) => {
|
||||
const mockedComponent = screen.getByText(componentName);
|
||||
return expect(mockedComponent).toBeInTheDocument();
|
||||
});
|
||||
test('renders default CourseCardBanners', () => {
|
||||
const wrapper = shallow(<CourseCardBanners {...props} />);
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
it('render null with no courseData', () => {
|
||||
useCourseData.mockReturnValue(null);
|
||||
const { container } = render(<IntlProvider locale="en"><CourseCardBanners {...props} /></IntlProvider>);
|
||||
expect(container.firstChild).toBeNull();
|
||||
});
|
||||
it('render with isEnrolled false', () => {
|
||||
useCourseData.mockReturnValue({ enrollment: { isEnrolled: false } });
|
||||
render(<IntlProvider locale="en"><CourseCardBanners {...props} /></IntlProvider>);
|
||||
const mockedComponentsIfNotEnrolled = mockedComponents.slice(-2);
|
||||
mockedComponentsIfNotEnrolled.map((componentName) => {
|
||||
const mockedComponent = screen.getByText(componentName);
|
||||
return expect(mockedComponent).toBeInTheDocument();
|
||||
});
|
||||
test('render with isEnrolled false', () => {
|
||||
reduxHooks.useCardEnrollmentData.mockReturnValueOnce({ isEnrolled: false });
|
||||
const wrapper = shallow(<CourseCardBanners {...props} />);
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`CourseCard Details component does not have change session button on regular course 1`] = `
|
||||
<div>
|
||||
<span
|
||||
class="small"
|
||||
data-testid="CourseCardDetails"
|
||||
>
|
||||
provider-name
|
||||
•
|
||||
test-course-number
|
||||
• access-message
|
||||
</span>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`CourseCard Details component has change session button on entitlement course 1`] = `
|
||||
<div>
|
||||
<span
|
||||
class="small"
|
||||
data-testid="CourseCardDetails"
|
||||
>
|
||||
provider-name
|
||||
•
|
||||
test-course-number
|
||||
• access-message
|
||||
•
|
||||
<button
|
||||
class="m-0 p-0"
|
||||
variant="link"
|
||||
>
|
||||
change-or-leave-session-message
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`CourseCard Details component has change session button on entitlement course but no access message 1`] = `
|
||||
<div>
|
||||
<span
|
||||
class="small"
|
||||
data-testid="CourseCardDetails"
|
||||
>
|
||||
provider-name
|
||||
•
|
||||
test-course-number
|
||||
•
|
||||
<button
|
||||
class="m-0 p-0"
|
||||
variant="link"
|
||||
>
|
||||
change-or-leave-session-message
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
`;
|
||||
@@ -1,21 +1,20 @@
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
import { utilHooks, useCourseData, useEntitlementInfo } from 'hooks';
|
||||
import { useSelectSessionModal } from 'data/context';
|
||||
import { utilHooks, reduxHooks } from 'hooks';
|
||||
|
||||
import * as hooks from './hooks';
|
||||
import messages from './messages';
|
||||
|
||||
export const useAccessMessage = ({ cardId }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const courseData = useCourseData(cardId);
|
||||
const { courseRun, enrollment } = courseData || {};
|
||||
const enrollment = reduxHooks.useCardEnrollmentData(cardId);
|
||||
const courseRun = reduxHooks.useCardCourseRunData(cardId);
|
||||
const formatDate = utilHooks.useFormatDate();
|
||||
if (!courseRun.isStarted) {
|
||||
if (!courseRun.startDate && !courseRun.advertisedStart) { return null; }
|
||||
const startDate = courseRun.advertisedStart ? courseRun.advertisedStart : formatDate(courseRun.startDate);
|
||||
return formatMessage(messages.courseStarts, { startDate });
|
||||
}
|
||||
if (enrollment?.isEnrolled) {
|
||||
if (enrollment.isEnrolled) {
|
||||
const { isArchived, endDate } = courseRun;
|
||||
const {
|
||||
accessExpirationDate,
|
||||
@@ -39,15 +38,15 @@ export const useAccessMessage = ({ cardId }) => {
|
||||
|
||||
export const useCardDetailsData = ({ cardId }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const courseData = useCourseData(cardId);
|
||||
const providerName = courseData?.courseProvider?.name;
|
||||
const courseNumber = courseData?.course?.courseNumber;
|
||||
const providerName = reduxHooks.useCardProviderData(cardId).name;
|
||||
const { courseNumber } = reduxHooks.useCardCourseData(cardId);
|
||||
const {
|
||||
isEntitlement,
|
||||
isFulfilled,
|
||||
canChange,
|
||||
} = useEntitlementInfo(courseData);
|
||||
const { updateSelectSessionModal } = useSelectSessionModal();
|
||||
} = reduxHooks.useCardEntitlementData(cardId);
|
||||
|
||||
const openSessionModal = reduxHooks.useUpdateSelectSessionModalCallback(cardId);
|
||||
|
||||
return {
|
||||
providerName: providerName || formatMessage(messages.unknownProviderName),
|
||||
@@ -55,7 +54,7 @@ export const useCardDetailsData = ({ cardId }) => {
|
||||
isEntitlement,
|
||||
isFulfilled,
|
||||
canChange,
|
||||
openSessionModal: () => updateSelectSessionModal(cardId),
|
||||
openSessionModal,
|
||||
courseNumber,
|
||||
changeOrLeaveSessionMessage: formatMessage(messages.changeOrLeaveSessionButton),
|
||||
};
|
||||
|
||||
@@ -1,38 +1,25 @@
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
|
||||
import { keyStore } from 'utils';
|
||||
import { utilHooks, useCourseData } from 'hooks';
|
||||
import { useSelectSessionModal } from 'data/context';
|
||||
import { utilHooks, reduxHooks } from 'hooks';
|
||||
|
||||
import * as hooks from './hooks';
|
||||
import messages from './messages';
|
||||
|
||||
jest.mock('react', () => ({
|
||||
...jest.requireActual('react'),
|
||||
useMemo: (fn) => fn(),
|
||||
}));
|
||||
|
||||
const updateSelectSessionModalMock = jest.fn().mockName('updateSelectSessionModal');
|
||||
jest.mock('data/context', () => ({
|
||||
useSelectSessionModal: jest.fn(),
|
||||
}));
|
||||
jest.mock('hooks', () => ({
|
||||
...jest.requireActual('hooks'),
|
||||
useCourseData: jest.fn(),
|
||||
utilHooks: {
|
||||
useFormatDate: jest.fn(),
|
||||
},
|
||||
reduxHooks: {
|
||||
useCardCourseData: jest.fn(),
|
||||
useCardCourseRunData: jest.fn(),
|
||||
useCardEnrollmentData: jest.fn(),
|
||||
useCardEntitlementData: jest.fn(),
|
||||
useCardProviderData: jest.fn(),
|
||||
useUpdateSelectSessionModalCallback: (...args) => ({ updateSelectSessionModalCallback: args }),
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('@edx/frontend-platform/i18n', () => {
|
||||
const { formatMessage } = jest.requireActual('testUtils');
|
||||
return {
|
||||
...jest.requireActual('@edx/frontend-platform/i18n'),
|
||||
useIntl: () => ({
|
||||
formatMessage,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
const cardId = 'my-test-card-id';
|
||||
const courseNumber = 'test-course-number';
|
||||
const useAccessMessage = 'test-access-message';
|
||||
@@ -63,13 +50,15 @@ describe('CourseCardDetails hooks', () => {
|
||||
const runHook = ({ provider = {}, entitlement = {} }) => {
|
||||
jest.spyOn(hooks, hookKeys.useAccessMessage)
|
||||
.mockImplementationOnce(mockAccessMessage);
|
||||
useCourseData.mockReturnValue({
|
||||
courseProvider: { ...providerData, ...provider },
|
||||
course: { courseNumber },
|
||||
courseRun: {},
|
||||
entitlement: { ...entitlementData, ...entitlement },
|
||||
reduxHooks.useCardProviderData.mockReturnValueOnce({
|
||||
...providerData,
|
||||
...provider,
|
||||
});
|
||||
useSelectSessionModal.mockReturnValue({ updateSelectSessionModal: updateSelectSessionModalMock });
|
||||
reduxHooks.useCardEntitlementData.mockReturnValueOnce({
|
||||
...entitlementData,
|
||||
...entitlement,
|
||||
});
|
||||
reduxHooks.useCardCourseData.mockReturnValueOnce({ courseNumber });
|
||||
out = hooks.useCardDetailsData({ cardId });
|
||||
};
|
||||
beforeEach(() => {
|
||||
@@ -86,10 +75,6 @@ describe('CourseCardDetails hooks', () => {
|
||||
it('forward changeOrLeaveSessionMessage', () => {
|
||||
expect(out.changeOrLeaveSessionMessage).toEqual(formatMessage(messages.changeOrLeaveSessionButton));
|
||||
});
|
||||
it('calls updateSelectSessionModal when openSessionModal is called', () => {
|
||||
out.openSessionModal();
|
||||
expect(updateSelectSessionModalMock).toHaveBeenCalledWith(cardId);
|
||||
});
|
||||
});
|
||||
|
||||
describe('useAccessMessage', () => {
|
||||
@@ -106,16 +91,21 @@ describe('CourseCardDetails hooks', () => {
|
||||
endDate: '10/20/2000',
|
||||
};
|
||||
const runHook = ({ enrollment = {}, courseRun = {} }) => {
|
||||
useCourseData.mockReturnValue({
|
||||
courseRun: { ...courseRunData, ...courseRun },
|
||||
enrollment: { ...enrollmentData, ...enrollment },
|
||||
reduxHooks.useCardCourseRunData.mockReturnValueOnce({
|
||||
...courseRunData,
|
||||
...courseRun,
|
||||
});
|
||||
reduxHooks.useCardEnrollmentData.mockReturnValueOnce({
|
||||
...enrollmentData,
|
||||
...enrollment,
|
||||
});
|
||||
out = hooks.useAccessMessage({ cardId });
|
||||
};
|
||||
|
||||
it('loads data from enrollment and course run data based on course number', () => {
|
||||
runHook({});
|
||||
expect(useCourseData).toHaveBeenCalledWith(cardId);
|
||||
expect(reduxHooks.useCardCourseRunData).toHaveBeenCalledWith(cardId);
|
||||
expect(reduxHooks.useCardEnrollmentData).toHaveBeenCalledWith(cardId);
|
||||
});
|
||||
|
||||
describe('if not started yet', () => {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
@import "~@edx/brand/paragon/variables";
|
||||
@import "~@openedx/paragon/scss/core/core";
|
||||
@import "~@edx/brand/paragon/overrides";
|
||||
|
||||
a.course-card-title {
|
||||
color: var(--pgn-color-black);
|
||||
color: $black;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
import CourseCardDetails from '.';
|
||||
|
||||
@@ -47,36 +48,23 @@ describe('CourseCard Details component', () => {
|
||||
return separatorsCount;
|
||||
};
|
||||
|
||||
it('has change session button on entitlement course', () => {
|
||||
test('has change session button on entitlement course', () => {
|
||||
const wrapper = createWrapper();
|
||||
const sessionButton = screen.getByRole('button', { name: defaultHooks.changeOrLeaveSessionMessage });
|
||||
expect(sessionButton).toBeInTheDocument();
|
||||
|
||||
const accessMessage = screen.getByText((text) => text.includes(defaultHooks.accessMessage));
|
||||
expect(accessMessage).toBeInTheDocument();
|
||||
expect(wrapper.container).toMatchSnapshot();
|
||||
// it has 3 separator, 4 column
|
||||
expect(fetchSeparators(wrapper)).toBe(3);
|
||||
});
|
||||
|
||||
it('has change session button on entitlement course but no access message', () => {
|
||||
test('has change session button on entitlement course but no access message', () => {
|
||||
const wrapper = createWrapper({ accessMessage: null });
|
||||
const sessionButton = screen.getByRole('button', { name: defaultHooks.changeOrLeaveSessionMessage });
|
||||
expect(sessionButton).toBeInTheDocument();
|
||||
|
||||
const accessMessage = screen.queryByText((text) => text.includes(defaultHooks.accessMessage));
|
||||
expect(accessMessage).toBeNull();
|
||||
|
||||
expect(wrapper.container).toMatchSnapshot();
|
||||
// it has 2 separator, 3 column
|
||||
expect(fetchSeparators(wrapper)).toBe(2);
|
||||
});
|
||||
|
||||
it('does not have change session button on regular course', () => {
|
||||
test('does not have change session button on regular course', () => {
|
||||
const wrapper = createWrapper({ isEntitlement: false });
|
||||
const sessionButton = screen.queryByRole('button', { name: defaultHooks.changeOrLeaveSessionMessage });
|
||||
expect(sessionButton).toBeNull();
|
||||
|
||||
const accessMessage = screen.getByText((text) => text.includes(defaultHooks.accessMessage));
|
||||
expect(accessMessage).toBeInTheDocument();
|
||||
expect(wrapper.container).toMatchSnapshot();
|
||||
// it has 2 separator, 3 column
|
||||
expect(fetchSeparators(wrapper)).toBe(2);
|
||||
});
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
import { baseAppUrl } from 'data/services/lms/urls';
|
||||
|
||||
import { Badge } from '@openedx/paragon';
|
||||
|
||||
import track from 'tracking';
|
||||
import { useCourseData, useCourseTrackingEvent } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
import verifiedRibbon from 'assets/verified-ribbon.png';
|
||||
import useActionDisabledState from './hooks';
|
||||
|
||||
@@ -16,10 +15,11 @@ const { courseImageClicked } = track.course;
|
||||
|
||||
export const CourseCardImage = ({ cardId, orientation }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const courseData = useCourseData(cardId);
|
||||
const { homeUrl } = courseData?.courseRun || {};
|
||||
const { bannerImgSrc } = reduxHooks.useCardCourseData(cardId);
|
||||
const { homeUrl } = reduxHooks.useCardCourseRunData(cardId);
|
||||
const { isVerified } = reduxHooks.useCardEnrollmentData(cardId);
|
||||
const { disableCourseTitle } = useActionDisabledState(cardId);
|
||||
const handleImageClicked = useCourseTrackingEvent(courseImageClicked, cardId, homeUrl);
|
||||
const handleImageClicked = reduxHooks.useTrackCourseEvent(courseImageClicked, cardId, homeUrl);
|
||||
const wrapperClassName = `pgn__card-wrapper-image-cap d-inline-block overflow-visible ${orientation}`;
|
||||
const image = (
|
||||
<>
|
||||
@@ -27,11 +27,11 @@ export const CourseCardImage = ({ cardId, orientation }) => {
|
||||
// w-100 is necessary for images on Safari, otherwise stretches full height of the image
|
||||
// https://stackoverflow.com/a/44250830
|
||||
className="pgn__card-image-cap w-100 show"
|
||||
src={courseData?.course?.bannerImgSrc && baseAppUrl(courseData.course.bannerImgSrc)}
|
||||
src={bannerImgSrc}
|
||||
alt={formatMessage(messages.bannerAlt)}
|
||||
/>
|
||||
{
|
||||
courseData?.enrollment?.isVerified && (
|
||||
isVerified && (
|
||||
<span
|
||||
className="course-card-verify-ribbon-container"
|
||||
title={formatMessage(messages.verifiedHoverDescription)}
|
||||
|
||||
@@ -1,93 +1,65 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import { formatMessage } from 'testUtils';
|
||||
import { useCourseData } from 'hooks';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { reduxHooks } from 'hooks';
|
||||
import track from 'tracking';
|
||||
import useActionDisabledState from './hooks';
|
||||
import { CourseCardImage } from './CourseCardImage';
|
||||
import messages from '../messages';
|
||||
import CourseCardImage from './CourseCardImage';
|
||||
|
||||
const homeUrl = 'https://example.com';
|
||||
const bannerImgSrc = 'banner-img-src.jpg';
|
||||
const homeUrl = 'home-url';
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
useCourseData: jest.fn(() => ({
|
||||
course: { bannerImgSrc },
|
||||
courseRun: { homeUrl },
|
||||
enrollment: {},
|
||||
})),
|
||||
useCourseTrackingEvent: jest.fn((eventName, cardId, url) => ({
|
||||
trackCourseEvent: { eventName, cardId, url },
|
||||
})),
|
||||
jest.mock('tracking', () => ({
|
||||
course: {
|
||||
courseImageClicked: jest.fn().mockName('segment.courseImageClicked'),
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('./hooks', () => jest.fn());
|
||||
jest.mock('hooks', () => ({
|
||||
reduxHooks: {
|
||||
useCardCourseData: jest.fn(() => ({ bannerImgSrc: 'banner-img-src' })),
|
||||
useCardCourseRunData: jest.fn(() => ({ homeUrl })),
|
||||
useCardEnrollmentData: jest.fn(() => ({ isVerified: true })),
|
||||
useTrackCourseEvent: jest.fn((eventName, cardId, url) => ({
|
||||
trackCourseEvent: { eventName, cardId, url },
|
||||
})),
|
||||
},
|
||||
}));
|
||||
jest.mock('./hooks', () => jest.fn(() => ({ disableCourseTitle: false })));
|
||||
|
||||
describe('CourseCardImage', () => {
|
||||
const props = {
|
||||
cardId: 'test-card-id',
|
||||
orientation: 'horizontal',
|
||||
cardId: 'cardId',
|
||||
orientation: 'orientation',
|
||||
};
|
||||
|
||||
it('renders course image with correct attributes', () => {
|
||||
useActionDisabledState.mockReturnValue({ disableCourseTitle: true });
|
||||
useCourseData.mockReturnValue(
|
||||
{
|
||||
course: { bannerImgSrc },
|
||||
courseRun: { homeUrl },
|
||||
enrollment: { isVerified: true },
|
||||
},
|
||||
);
|
||||
render(<IntlProvider locale="en"><CourseCardImage {...props} /></IntlProvider>);
|
||||
|
||||
const image = screen.getByRole('img', { name: formatMessage(messages.bannerAlt) });
|
||||
expect(image).toBeInTheDocument();
|
||||
expect(image.src).toContain(bannerImgSrc);
|
||||
expect(image.parentElement).toHaveClass('horizontal');
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('isVerified, should render badge', () => {
|
||||
useActionDisabledState.mockReturnValue({ disableCourseTitle: false });
|
||||
useCourseData.mockReturnValue(
|
||||
{
|
||||
course: { bannerImgSrc },
|
||||
courseRun: { homeUrl },
|
||||
enrollment: { isVerified: true },
|
||||
},
|
||||
);
|
||||
render(<IntlProvider locale="en"><CourseCardImage {...props} /></IntlProvider>);
|
||||
|
||||
const badge = screen.getByText(formatMessage(messages.verifiedBanner));
|
||||
expect(badge).toBeInTheDocument();
|
||||
const badgeImg = screen.getByRole('img', { name: formatMessage(messages.verifiedBannerRibbonAlt) });
|
||||
expect(badgeImg).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders link with correct href if disableCourseTitle is false', () => {
|
||||
useActionDisabledState.mockReturnValue({ disableCourseTitle: false });
|
||||
useCourseData.mockReturnValue(
|
||||
{
|
||||
course: { bannerImgSrc },
|
||||
courseRun: { homeUrl },
|
||||
enrollment: { isVerified: false },
|
||||
},
|
||||
);
|
||||
render(<IntlProvider locale="en"><CourseCardImage {...props} /></IntlProvider>);
|
||||
|
||||
const link = screen.getByRole('link');
|
||||
expect(link).toHaveAttribute('href', homeUrl);
|
||||
});
|
||||
describe('hooks', () => {
|
||||
it('initializes', () => {
|
||||
useActionDisabledState.mockReturnValue({ disableCourseTitle: false });
|
||||
useCourseData.mockReturnValue(
|
||||
{
|
||||
course: { bannerImgSrc },
|
||||
courseRun: { homeUrl },
|
||||
enrollment: { isVerified: true },
|
||||
},
|
||||
describe('snapshot', () => {
|
||||
test('renders clickable link course Image', () => {
|
||||
const wrapper = shallow(<CourseCardImage {...props} />);
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
expect(wrapper.instance.type).toBe('a');
|
||||
expect(wrapper.instance.props.onClick).toEqual(
|
||||
reduxHooks.useTrackCourseEvent(
|
||||
track.course.courseImageClicked,
|
||||
props.cardId,
|
||||
homeUrl,
|
||||
),
|
||||
);
|
||||
});
|
||||
test('renders disabled link', () => {
|
||||
useActionDisabledState.mockReturnValueOnce({ disableCourseTitle: true });
|
||||
const wrapper = shallow(<CourseCardImage {...props} />);
|
||||
expect(wrapper.snapshot).toMatchSnapshot();
|
||||
expect(wrapper.instance.type).toBe('div');
|
||||
});
|
||||
});
|
||||
describe('behavior', () => {
|
||||
it('initializes', () => {
|
||||
shallow(<CourseCardImage {...props} />);
|
||||
expect(reduxHooks.useCardCourseData).toHaveBeenCalledWith(props.cardId);
|
||||
expect(reduxHooks.useCardCourseRunData).toHaveBeenCalledWith(
|
||||
props.cardId,
|
||||
);
|
||||
render(<IntlProvider locale="en"><CourseCardImage {...props} /></IntlProvider>);
|
||||
expect(useCourseData).toHaveBeenCalledWith(props.cardId);
|
||||
expect(useActionDisabledState).toHaveBeenCalledWith(props.cardId);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import * as ReactShare from 'react-share';
|
||||
import { EXECUTIVE_EDUCATION_COURSE_MODES } from 'data/constants/course';
|
||||
|
||||
import { StrictDict } from '@edx/react-unit-test-utils';
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
import { Dropdown } from '@openedx/paragon';
|
||||
|
||||
import track from 'tracking';
|
||||
import { useCourseTrackingEvent, useCourseData, useIsMasquerading } from 'hooks';
|
||||
import { useCardSocialSettingsData } from './hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
|
||||
import messages from './messages';
|
||||
|
||||
export const testIds = {
|
||||
export const testIds = StrictDict({
|
||||
emailSettingsModalToggle: 'emailSettingsModalToggle',
|
||||
};
|
||||
});
|
||||
|
||||
export const SocialShareMenu = ({ cardId, emailSettings }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const courseData = useCourseData(cardId);
|
||||
const courseName = courseData?.course?.courseName;
|
||||
const isExecEd2UCourse = EXECUTIVE_EDUCATION_COURSE_MODES.includes(courseData.enrollment.mode);
|
||||
const isEmailEnabled = courseData?.enrollment?.isEmailEnabled ?? false;
|
||||
const { twitter, facebook } = useCardSocialSettingsData(cardId);
|
||||
const isMasquerading = useIsMasquerading();
|
||||
|
||||
const handleTwitterShare = useCourseTrackingEvent(track.socialShare, cardId, 'twitter');
|
||||
const handleFacebookShare = useCourseTrackingEvent(track.socialShare, cardId, 'facebook');
|
||||
const { courseName } = reduxHooks.useCardCourseData(cardId);
|
||||
const { isEmailEnabled, isExecEd2UCourse } = reduxHooks.useCardEnrollmentData(cardId);
|
||||
const { twitter, facebook } = reduxHooks.useCardSocialSettingsData(cardId);
|
||||
const { isMasquerading } = reduxHooks.useMasqueradeData();
|
||||
|
||||
const handleTwitterShare = reduxHooks.useTrackCourseEvent(track.socialShare, cardId, 'twitter');
|
||||
const handleFacebookShare = reduxHooks.useTrackCourseEvent(track.socialShare, cardId, 'facebook');
|
||||
|
||||
if (isExecEd2UCourse) {
|
||||
return null;
|
||||
@@ -51,7 +51,6 @@ export const SocialShareMenu = ({ cardId, emailSettings }) => {
|
||||
})}
|
||||
resetButtonStyle={false}
|
||||
className="pgn__dropdown-item dropdown-item"
|
||||
aria-label="facebook"
|
||||
>
|
||||
{formatMessage(messages.shareToFacebook)}
|
||||
</ReactShare.FacebookShareButton>
|
||||
@@ -66,7 +65,6 @@ export const SocialShareMenu = ({ cardId, emailSettings }) => {
|
||||
})}
|
||||
resetButtonStyle={false}
|
||||
className="pgn__dropdown-item dropdown-item"
|
||||
aria-label="twitter"
|
||||
>
|
||||
{formatMessage(messages.shareToTwitter)}
|
||||
</ReactShare.TwitterShareButton>
|
||||
|
||||
@@ -1,27 +1,43 @@
|
||||
import { when } from 'jest-when';
|
||||
import * as ReactShare from 'react-share';
|
||||
|
||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
import { formatMessage, shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import track from 'tracking';
|
||||
import { useCourseTrackingEvent, useCourseData, useIsMasquerading } from 'hooks';
|
||||
import { reduxHooks } from 'hooks';
|
||||
|
||||
import { useEmailSettings, useCardSocialSettingsData } from './hooks';
|
||||
import SocialShareMenu from './SocialShareMenu';
|
||||
import { useEmailSettings } from './hooks';
|
||||
import SocialShareMenu, { testIds } from './SocialShareMenu';
|
||||
import messages from './messages';
|
||||
|
||||
jest.mock('react-share', () => ({
|
||||
FacebookShareButton: () => 'FacebookShareButton',
|
||||
TwitterShareButton: () => 'TwitterShareButton',
|
||||
}));
|
||||
|
||||
jest.mock('tracking', () => ({
|
||||
socialShare: 'test-social-share-key',
|
||||
}));
|
||||
|
||||
jest.mock('@edx/frontend-platform/i18n', () => ({
|
||||
...jest.requireActual('@edx/frontend-platform/i18n'),
|
||||
useIntl: jest.fn().mockReturnValue({
|
||||
formatMessage: jest.requireActual('@edx/react-unit-test-utils').formatMessage,
|
||||
}),
|
||||
}));
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
useCourseData: jest.fn(),
|
||||
useCourseTrackingEvent: jest.fn((...args) => ({ trackCourseEvent: args })),
|
||||
useIsMasquerading: jest.fn(),
|
||||
reduxHooks: {
|
||||
useMasqueradeData: jest.fn(),
|
||||
useCardCourseData: jest.fn(),
|
||||
useCardEnrollmentData: jest.fn(),
|
||||
useCardSocialSettingsData: jest.fn(),
|
||||
useTrackCourseEvent: jest.fn((...args) => ({ trackCourseEvent: args })),
|
||||
},
|
||||
}));
|
||||
jest.mock('./hooks', () => ({
|
||||
useEmailSettings: jest.fn(),
|
||||
useCardSocialSettingsData: jest.fn(),
|
||||
}));
|
||||
|
||||
const props = {
|
||||
@@ -31,9 +47,9 @@ const props = {
|
||||
|
||||
const mockHook = (fn, returnValue, options = {}) => {
|
||||
if (options.isCardHook) {
|
||||
when(fn).calledWith(props.cardId).mockReturnValue(returnValue);
|
||||
when(fn).calledWith(props.cardId).mockReturnValueOnce(returnValue);
|
||||
} else {
|
||||
when(fn).calledWith().mockReturnValue(returnValue);
|
||||
when(fn).calledWith().mockReturnValueOnce(returnValue);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -54,86 +70,101 @@ const socialShare = {
|
||||
|
||||
const mockHooks = (returnVals = {}) => {
|
||||
mockHook(
|
||||
useCourseData,
|
||||
reduxHooks.useCardEnrollmentData,
|
||||
{
|
||||
enrollment: {
|
||||
isEmailEnabled: !!returnVals.isEmailEnabled,
|
||||
mode: returnVals.isExecEd2UCourse ? 'exec-ed-2u' : 'standard',
|
||||
},
|
||||
course: { courseName },
|
||||
isEmailEnabled: !!returnVals.isEmailEnabled,
|
||||
isExecEd2UCourse: !!returnVals.isExecEd2UCourse,
|
||||
},
|
||||
{ isCardHook: true },
|
||||
);
|
||||
mockHook(reduxHooks.useCardCourseData, { courseName }, { isCardHook: true });
|
||||
mockHook(reduxHooks.useMasqueradeData, { isMasquerading: !!returnVals.isMasquerading });
|
||||
mockHook(
|
||||
useCardSocialSettingsData,
|
||||
reduxHooks.useCardSocialSettingsData,
|
||||
{
|
||||
facebook: { ...socialShare.facebook, isEnabled: !!returnVals.facebook?.isEnabled },
|
||||
twitter: { ...socialShare.twitter, isEnabled: !!returnVals.twitter?.isEnabled },
|
||||
},
|
||||
{ isCardHook: true },
|
||||
);
|
||||
mockHook(useIsMasquerading, !!returnVals.isMasquerading);
|
||||
};
|
||||
|
||||
const renderComponent = () => render(<IntlProvider locale="en"><SocialShareMenu {...props} /></IntlProvider>);
|
||||
let el;
|
||||
const render = () => {
|
||||
el = shallow(<SocialShareMenu {...props} />);
|
||||
};
|
||||
|
||||
describe('SocialShareMenu', () => {
|
||||
describe('behavior', () => {
|
||||
beforeEach(() => {
|
||||
mockHooks();
|
||||
renderComponent();
|
||||
render();
|
||||
});
|
||||
it('initializes intl hook', () => {
|
||||
expect(useIntl).toHaveBeenCalledWith();
|
||||
});
|
||||
it('initializes local hooks', () => {
|
||||
when(useEmailSettings).expectCalledWith();
|
||||
});
|
||||
it('initializes hook data ', () => {
|
||||
when(useCourseData).expectCalledWith(props.cardId);
|
||||
when(useCardSocialSettingsData).expectCalledWith(props.cardId);
|
||||
when(useIsMasquerading).expectCalledWith();
|
||||
when(useCourseTrackingEvent).expectCalledWith(track.socialShare, props.cardId, 'twitter');
|
||||
when(useCourseTrackingEvent).expectCalledWith(track.socialShare, props.cardId, 'facebook');
|
||||
it('initializes redux hook data ', () => {
|
||||
when(reduxHooks.useCardEnrollmentData).expectCalledWith(props.cardId);
|
||||
when(reduxHooks.useCardCourseData).expectCalledWith(props.cardId);
|
||||
when(reduxHooks.useCardSocialSettingsData).expectCalledWith(props.cardId);
|
||||
when(reduxHooks.useMasqueradeData).expectCalledWith();
|
||||
when(reduxHooks.useTrackCourseEvent).expectCalledWith(track.socialShare, props.cardId, 'twitter');
|
||||
when(reduxHooks.useTrackCourseEvent).expectCalledWith(track.socialShare, props.cardId, 'facebook');
|
||||
});
|
||||
});
|
||||
describe('render', () => {
|
||||
it('renders null if exec ed course', () => {
|
||||
mockHooks({ isExecEd2UCourse: true });
|
||||
renderComponent();
|
||||
const emailSettingsButton = screen.queryByRole('button', { name: messages.emailSettings.defaultMessage });
|
||||
expect(emailSettingsButton).toBeNull();
|
||||
const facebookShareButton = screen.queryByRole('button', { name: 'facebook' });
|
||||
expect(facebookShareButton).toBeNull();
|
||||
const twitterShareButton = screen.queryByRole('button', { name: 'twitter' });
|
||||
expect(twitterShareButton).toBeNull();
|
||||
render();
|
||||
expect(el.isEmptyRender()).toEqual(true);
|
||||
});
|
||||
const testEmailSettingsDropdown = (isMasquerading = false) => {
|
||||
describe('email settings dropdown', () => {
|
||||
const loadToggle = () => el.instance.findByTestId(testIds.emailSettingsModalToggle)[0];
|
||||
it('renders', () => {
|
||||
const emailSettingsButton = screen.getByRole('button', { name: messages.emailSettings.defaultMessage });
|
||||
expect(emailSettingsButton).toBeInTheDocument();
|
||||
expect(el.instance.findByTestId(testIds.emailSettingsModalToggle).length).toEqual(1);
|
||||
});
|
||||
if (isMasquerading) {
|
||||
it('is disabled', () => {
|
||||
const emailSettingsButton = screen.getByRole('button', { name: messages.emailSettings.defaultMessage });
|
||||
expect(emailSettingsButton).toHaveAttribute('aria-disabled', 'true');
|
||||
expect(loadToggle().props.disabled).toEqual(true);
|
||||
});
|
||||
} else {
|
||||
it('is enabled', () => {
|
||||
const emailSettingsButton = screen.getByRole('button', { name: messages.emailSettings.defaultMessage });
|
||||
expect(emailSettingsButton).toBeEnabled();
|
||||
expect(loadToggle().props.disabled).toEqual(false);
|
||||
});
|
||||
}
|
||||
test('show email settings modal on click', () => {
|
||||
expect(loadToggle().props.onClick).toEqual(props.emailSettings.show);
|
||||
});
|
||||
});
|
||||
};
|
||||
const testFacebookShareButton = () => {
|
||||
it('renders facebook share button', () => {
|
||||
const facebookShareButton = screen.getByRole('button', { name: 'facebook' });
|
||||
expect(facebookShareButton).toBeInTheDocument();
|
||||
test('renders facebook share button with courseName and brand', () => {
|
||||
const button = el.instance.findByType(ReactShare.FacebookShareButton)[0];
|
||||
expect(button.props.url).toEqual(socialShare.facebook.shareUrl);
|
||||
expect(button.props.onClick).toEqual(
|
||||
reduxHooks.useTrackCourseEvent(track.socialShare, props.cardId, 'facebook'),
|
||||
);
|
||||
expect(button.props.title).toEqual(formatMessage(messages.shareQuote, {
|
||||
courseName,
|
||||
socialBrand: socialShare.facebook.socialBrand,
|
||||
}));
|
||||
});
|
||||
};
|
||||
const testTwitterShareButton = () => {
|
||||
it('renders twitter share button', () => {
|
||||
const twitterShareButton = screen.getByRole('button', { name: 'twitter' });
|
||||
expect(twitterShareButton).toBeInTheDocument();
|
||||
test('renders twitter share button with courseName and brand', () => {
|
||||
const button = el.instance.findByType(ReactShare.TwitterShareButton)[0];
|
||||
expect(button.props.url).toEqual(socialShare.twitter.shareUrl);
|
||||
expect(button.props.onClick).toEqual(
|
||||
reduxHooks.useTrackCourseEvent(track.socialShare, props.cardId, 'twitter'),
|
||||
);
|
||||
expect(button.props.title).toEqual(formatMessage(messages.shareQuote, {
|
||||
courseName,
|
||||
socialBrand: socialShare.twitter.socialBrand,
|
||||
}));
|
||||
});
|
||||
};
|
||||
describe('all enabled', () => {
|
||||
@@ -143,7 +174,19 @@ describe('SocialShareMenu', () => {
|
||||
twitter: { isEnabled: true },
|
||||
isEmailEnabled: true,
|
||||
});
|
||||
renderComponent();
|
||||
render();
|
||||
});
|
||||
describe('email settings dropdown', () => {
|
||||
const loadToggle = () => el.instance.findByTestId(testIds.emailSettingsModalToggle)[0];
|
||||
it('renders', () => {
|
||||
expect(el.instance.findByTestId(testIds.emailSettingsModalToggle).length).toEqual(1);
|
||||
});
|
||||
it('is enabled', () => {
|
||||
expect(loadToggle().props.disabled).toEqual(false);
|
||||
});
|
||||
test('show email settings modal on click', () => {
|
||||
expect(loadToggle().props.onClick).toEqual(props.emailSettings.show);
|
||||
});
|
||||
});
|
||||
testEmailSettingsDropdown();
|
||||
testFacebookShareButton();
|
||||
@@ -151,49 +194,42 @@ describe('SocialShareMenu', () => {
|
||||
});
|
||||
describe('only email enabled', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockHooks({ isEmailEnabled: true });
|
||||
renderComponent();
|
||||
render();
|
||||
});
|
||||
testEmailSettingsDropdown();
|
||||
it('does not render facebook or twitter controls', () => {
|
||||
const facebookShareButton = screen.queryByRole('button', { name: 'facebook' });
|
||||
expect(facebookShareButton).toBeNull();
|
||||
const twitterShareButton = screen.queryByRole('button', { name: 'twitter' });
|
||||
expect(twitterShareButton).toBeNull();
|
||||
expect(el.instance.findByType(ReactShare.FacebookShareButton).length).toEqual(0);
|
||||
expect(el.instance.findByType(ReactShare.TwitterShareButton).length).toEqual(0);
|
||||
});
|
||||
});
|
||||
describe('masquerading', () => {
|
||||
beforeEach(() => {
|
||||
mockHooks({ isEmailEnabled: true, isMasquerading: true });
|
||||
renderComponent();
|
||||
describe('masquerading', () => {
|
||||
beforeEach(() => {
|
||||
mockHooks({ isEmailEnabled: true, isMasquerading: true });
|
||||
render();
|
||||
});
|
||||
testEmailSettingsDropdown(true);
|
||||
});
|
||||
testEmailSettingsDropdown(true);
|
||||
});
|
||||
describe('only facebook enabled', () => {
|
||||
beforeEach(() => {
|
||||
mockHooks({ facebook: { isEnabled: true } });
|
||||
renderComponent();
|
||||
render();
|
||||
});
|
||||
testFacebookShareButton();
|
||||
it('does not render email or twitter controls', () => {
|
||||
const emailSettingsButton = screen.queryByRole('button', { name: messages.emailSettings.defaultMessage });
|
||||
expect(emailSettingsButton).toBeNull();
|
||||
const twitterShareButton = screen.queryByRole('button', { name: 'twitter' });
|
||||
expect(twitterShareButton).toBeNull();
|
||||
expect(el.instance.findByTestId(testIds.emailSettingsModalToggle).length).toEqual(0);
|
||||
expect(el.instance.findByType(ReactShare.TwitterShareButton).length).toEqual(0);
|
||||
});
|
||||
});
|
||||
describe('only twitter enabled', () => {
|
||||
beforeEach(() => {
|
||||
mockHooks({ twitter: { isEnabled: true } });
|
||||
renderComponent();
|
||||
render();
|
||||
});
|
||||
testTwitterShareButton();
|
||||
it('does not render email or facebook controls', () => {
|
||||
const emailSettingsButton = screen.queryByRole('button', { name: messages.emailSettings.defaultMessage });
|
||||
expect(emailSettingsButton).toBeNull();
|
||||
const facebookShareButton = screen.queryByRole('button', { name: 'facebook' });
|
||||
expect(facebookShareButton).toBeNull();
|
||||
expect(el.instance.findByTestId(testIds.emailSettingsModalToggle).length).toEqual(0);
|
||||
expect(el.instance.findByType(ReactShare.FacebookShareButton).length).toEqual(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`CourseCardMenu render show dropdown hide unenroll item and disable email snapshot 1`] = `
|
||||
<Fragment>
|
||||
<Dropdown
|
||||
onToggle={[MockFunction hooks.handleToggleDropdown]}
|
||||
>
|
||||
<Dropdown.Toggle
|
||||
alt="Course actions dropdown"
|
||||
as="IconButton"
|
||||
iconAs="Icon"
|
||||
id="course-actions-dropdown-test-card-id"
|
||||
src={[MockFunction icons.MoreVert]}
|
||||
variant="primary"
|
||||
/>
|
||||
<Dropdown.Menu>
|
||||
<SocialShareMenu
|
||||
cardId="test-card-id"
|
||||
emailSettings={
|
||||
{
|
||||
"hide": [MockFunction emailSettingHide],
|
||||
"isVisible": false,
|
||||
"show": [MockFunction emailSettingShow],
|
||||
}
|
||||
}
|
||||
/>
|
||||
</Dropdown.Menu>
|
||||
</Dropdown>
|
||||
<UnenrollConfirmModal
|
||||
cardId="test-card-id"
|
||||
closeModal={[MockFunction unenrollHide]}
|
||||
show={false}
|
||||
/>
|
||||
</Fragment>
|
||||
`;
|
||||
|
||||
exports[`CourseCardMenu render show dropdown show unenroll and enable email snapshot 1`] = `
|
||||
<Fragment>
|
||||
<Dropdown
|
||||
onToggle={[MockFunction hooks.handleToggleDropdown]}
|
||||
>
|
||||
<Dropdown.Toggle
|
||||
alt="Course actions dropdown"
|
||||
as="IconButton"
|
||||
iconAs="Icon"
|
||||
id="course-actions-dropdown-test-card-id"
|
||||
src={[MockFunction icons.MoreVert]}
|
||||
variant="primary"
|
||||
/>
|
||||
<Dropdown.Menu>
|
||||
<Dropdown.Item
|
||||
data-testid="unenrollModalToggle"
|
||||
disabled={false}
|
||||
onClick={[MockFunction unenrollShow]}
|
||||
>
|
||||
Unenroll
|
||||
</Dropdown.Item>
|
||||
<SocialShareMenu
|
||||
cardId="test-card-id"
|
||||
emailSettings={
|
||||
{
|
||||
"hide": [MockFunction emailSettingHide],
|
||||
"isVisible": false,
|
||||
"show": [MockFunction emailSettingShow],
|
||||
}
|
||||
}
|
||||
/>
|
||||
</Dropdown.Menu>
|
||||
</Dropdown>
|
||||
<UnenrollConfirmModal
|
||||
cardId="test-card-id"
|
||||
closeModal={[MockFunction unenrollHide]}
|
||||
show={false}
|
||||
/>
|
||||
<EmailSettingsModal
|
||||
cardId="test-card-id"
|
||||
closeModal={[MockFunction emailSettingHide]}
|
||||
show={false}
|
||||
/>
|
||||
</Fragment>
|
||||
`;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user