@edx/frontend-plugin-learner-dashboard 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/course-banner/Banner.js +40 -0
- package/dist/course-banner/Banner.js.map +1 -0
- package/dist/course-banner/CourseBanner.js +71 -0
- package/dist/course-banner/CourseBanner.js.map +1 -0
- package/dist/course-banner/formatDate.js +25 -0
- package/dist/course-banner/formatDate.js.map +1 -0
- package/dist/course-banner/index.js +35 -0
- package/dist/course-banner/index.js.map +1 -0
- package/dist/course-banner/messages.js +46 -0
- package/dist/course-banner/messages.js.map +1 -0
- package/dist/data/redux/app/selectors/courseCard.js +4 -0
- package/dist/data/redux/app/selectors/courseCard.js.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -0
- package/dist/setupTest.js +12 -23
- package/dist/setupTest.js.map +1 -1
- package/dist/testUtils.js +26 -1
- package/dist/testUtils.js.map +1 -1
- package/dist/tracking/trackers/upgradeButton.js +1 -1
- package/dist/tracking/trackers/upgradeButton.js.map +1 -1
- package/package.json +2 -1
- package/src/course-banner/Banner.jsx +26 -0
- package/src/course-banner/Banner.test.jsx +36 -0
- package/src/course-banner/CourseBanner.jsx +76 -0
- package/src/course-banner/CourseBanner.test.jsx +172 -0
- package/src/course-banner/__snapshots__/Banner.test.jsx.snap +31 -0
- package/src/course-banner/__snapshots__/CourseBanner.test.jsx.snap +63 -0
- package/src/course-banner/formatDate.js +14 -0
- package/src/course-banner/index.jsx +22 -0
- package/src/course-banner/messages.js +41 -0
- package/src/data/redux/app/selectors/courseCard.js +6 -0
- package/src/data/redux/app/selectors/courseCard.test.js +16 -0
- package/src/index.jsx +8 -1
- package/src/setupTest.js +11 -21
- package/src/testUtils.js +20 -0
- package/src/tracking/trackers/upgradeButton.js +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// TODO: search for and remove all of these eslint lint disables now that it is disables in eslintrc
|
|
2
|
+
/* eslint-disable import/no-named-as-default */
|
|
3
|
+
import { shallow } from '@edx/react-unit-test-utils';
|
|
4
|
+
|
|
5
|
+
import { Alert } from '@openedx/paragon';
|
|
6
|
+
|
|
7
|
+
import Banner from './Banner';
|
|
8
|
+
|
|
9
|
+
jest.mock('@openedx/paragon', () => ({
|
|
10
|
+
...jest.requireActual('@openedx/paragon'),
|
|
11
|
+
Alert: () => 'Alert',
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
describe('Banner', () => {
|
|
15
|
+
const props = {
|
|
16
|
+
children: 'Hello, world!',
|
|
17
|
+
};
|
|
18
|
+
describe('snapshot', () => {
|
|
19
|
+
test('renders default banner', () => {
|
|
20
|
+
const wrapper = shallow(<Banner {...props} />);
|
|
21
|
+
expect(wrapper.snapshot).toMatchSnapshot();
|
|
22
|
+
|
|
23
|
+
expect(wrapper.instance.findByType(Alert)[0].props.variant).toEqual('info');
|
|
24
|
+
});
|
|
25
|
+
test('renders with variants', () => {
|
|
26
|
+
const wrapper = shallow(<Banner {...props} variant="success" />);
|
|
27
|
+
expect(wrapper.snapshot).toMatchSnapshot();
|
|
28
|
+
|
|
29
|
+
expect(wrapper.instance.findByType(Alert)[0].props.variant).toEqual('success');
|
|
30
|
+
});
|
|
31
|
+
test('renders with custom class', () => {
|
|
32
|
+
const wrapper = shallow(<Banner {...props} className="custom-class" />);
|
|
33
|
+
expect(wrapper.snapshot).toMatchSnapshot();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/* eslint-disable import/no-named-as-default-member */
|
|
2
|
+
/* eslint-disable import/no-named-as-default */
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
|
|
6
|
+
import { Hyperlink } from '@openedx/paragon';
|
|
7
|
+
import { useIntl } from '@edx/frontend-platform/i18n';
|
|
8
|
+
|
|
9
|
+
import reduxHooks from '../data/redux/hooks';
|
|
10
|
+
import { useFormatDate } from './formatDate';
|
|
11
|
+
import Banner from './Banner';
|
|
12
|
+
import messages from './messages';
|
|
13
|
+
|
|
14
|
+
const CourseBanner = ({ cardId }) => {
|
|
15
|
+
const {
|
|
16
|
+
isVerified,
|
|
17
|
+
isAuditAccessExpired,
|
|
18
|
+
canUpgrade,
|
|
19
|
+
coursewareAccess = {},
|
|
20
|
+
} = reduxHooks.useCardEnrollmentData(cardId);
|
|
21
|
+
const courseRun = reduxHooks.useCardCourseRunData(cardId);
|
|
22
|
+
const { formatMessage } = useIntl();
|
|
23
|
+
const formatDate = useFormatDate();
|
|
24
|
+
|
|
25
|
+
const { hasUnmetPrerequisites, isStaff, isTooEarly } = coursewareAccess;
|
|
26
|
+
|
|
27
|
+
if (isVerified) { return null; }
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<>
|
|
31
|
+
{isAuditAccessExpired
|
|
32
|
+
&& (canUpgrade ? (
|
|
33
|
+
<Banner>
|
|
34
|
+
{formatMessage(messages.auditAccessExpired)}
|
|
35
|
+
{' '}
|
|
36
|
+
{formatMessage(messages.upgradeToAccess)}
|
|
37
|
+
</Banner>
|
|
38
|
+
) : (
|
|
39
|
+
<Banner>
|
|
40
|
+
{formatMessage(messages.auditAccessExpired)}
|
|
41
|
+
{' '}
|
|
42
|
+
<Hyperlink isInline destination="">
|
|
43
|
+
{formatMessage(messages.findAnotherCourse)}
|
|
44
|
+
</Hyperlink>
|
|
45
|
+
</Banner>
|
|
46
|
+
))}
|
|
47
|
+
|
|
48
|
+
{courseRun.isActive && !canUpgrade && (
|
|
49
|
+
<Banner>
|
|
50
|
+
{formatMessage(messages.upgradeDeadlinePassed)}
|
|
51
|
+
{' '}
|
|
52
|
+
<Hyperlink isInline destination={courseRun.marketingUrl || ''}>
|
|
53
|
+
{formatMessage(messages.exploreCourseDetails)}
|
|
54
|
+
</Hyperlink>
|
|
55
|
+
</Banner>
|
|
56
|
+
)}
|
|
57
|
+
|
|
58
|
+
{(!isStaff && isTooEarly && courseRun.startDate) && (
|
|
59
|
+
<Banner>
|
|
60
|
+
{formatMessage(messages.courseHasNotStarted, {
|
|
61
|
+
startDate: formatDate(courseRun.startDate),
|
|
62
|
+
})}
|
|
63
|
+
</Banner>
|
|
64
|
+
)}
|
|
65
|
+
{(!isStaff && hasUnmetPrerequisites) && (
|
|
66
|
+
<Banner>{formatMessage(messages.prerequisitesNotMet)}</Banner>
|
|
67
|
+
)}
|
|
68
|
+
</>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
CourseBanner.propTypes = {
|
|
73
|
+
cardId: PropTypes.string.isRequired,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export default CourseBanner;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { shallow } from '@edx/react-unit-test-utils';
|
|
3
|
+
import { Hyperlink } from '@openedx/paragon';
|
|
4
|
+
|
|
5
|
+
import { useCardCourseRunData, useCardEnrollmentData } from '../data/redux/hooks';
|
|
6
|
+
import { formatMessage } from '../testUtils';
|
|
7
|
+
import CourseBanner from './CourseBanner';
|
|
8
|
+
|
|
9
|
+
import messages from './messages';
|
|
10
|
+
|
|
11
|
+
jest.mock('@openedx/paragon', () => ({
|
|
12
|
+
...jest.requireActual('@openedx/paragon'),
|
|
13
|
+
Hyperlink: () => 'Hyperlink',
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
jest.mock('moment', () => ({
|
|
17
|
+
__esModule: true,
|
|
18
|
+
default: (date) => ({
|
|
19
|
+
toDate: jest.fn().mockReturnValue(date),
|
|
20
|
+
}),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
jest.mock('./Banner', () => 'Banner');
|
|
24
|
+
jest.mock('../data/redux/hooks', () => ({
|
|
25
|
+
useCardCourseRunData: jest.fn(),
|
|
26
|
+
useCardEnrollmentData: jest.fn(),
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
const cardId = 'my-test-course-number';
|
|
30
|
+
|
|
31
|
+
let el;
|
|
32
|
+
|
|
33
|
+
const enrollmentData = {
|
|
34
|
+
isVerified: false,
|
|
35
|
+
canUpgrade: false,
|
|
36
|
+
isAuditAccessExpired: false,
|
|
37
|
+
coursewareAccess: {
|
|
38
|
+
hasUnmetPrerequisites: false,
|
|
39
|
+
isStaff: false,
|
|
40
|
+
isTooEarly: false,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const courseRunData = {
|
|
44
|
+
isActive: false,
|
|
45
|
+
startDate: '11/11/3030',
|
|
46
|
+
marketingUrl: 'marketing-url',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const render = (overrides = {}) => {
|
|
50
|
+
const {
|
|
51
|
+
courseRun = {},
|
|
52
|
+
enrollment = {},
|
|
53
|
+
} = overrides;
|
|
54
|
+
useCardCourseRunData.mockReturnValueOnce({
|
|
55
|
+
...courseRunData,
|
|
56
|
+
...courseRun,
|
|
57
|
+
});
|
|
58
|
+
useCardEnrollmentData.mockReturnValueOnce({
|
|
59
|
+
...enrollmentData,
|
|
60
|
+
...enrollment,
|
|
61
|
+
});
|
|
62
|
+
el = shallow(<CourseBanner cardId={cardId} />);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
describe('CourseBanner', () => {
|
|
66
|
+
test('initializes data with course number from enrollment, course and course run data', () => {
|
|
67
|
+
render();
|
|
68
|
+
expect(useCardCourseRunData).toHaveBeenCalledWith(cardId);
|
|
69
|
+
expect(useCardEnrollmentData).toHaveBeenCalledWith(cardId);
|
|
70
|
+
});
|
|
71
|
+
test('no display if learner is verified', () => {
|
|
72
|
+
render({ enrollment: { isVerified: true } });
|
|
73
|
+
expect(el.isEmptyRender()).toEqual(true);
|
|
74
|
+
});
|
|
75
|
+
describe('audit access expired, can upgrade', () => {
|
|
76
|
+
beforeEach(() => {
|
|
77
|
+
render({ enrollment: { isAuditAccessExpired: true, canUpgrade: true } });
|
|
78
|
+
});
|
|
79
|
+
test('snapshot: (auditAccessExpired, upgradeToAccess)', () => {
|
|
80
|
+
expect(el.snapshot).toMatchSnapshot();
|
|
81
|
+
});
|
|
82
|
+
test('messages: (auditAccessExpired, upgradeToAccess)', () => {
|
|
83
|
+
expect(el.instance.children[0].children[0].el).toContain(messages.auditAccessExpired.defaultMessage);
|
|
84
|
+
expect(el.instance.children[0].children[2].el).toContain(messages.upgradeToAccess.defaultMessage);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
describe('audit access expired, cannot upgrade', () => {
|
|
88
|
+
beforeEach(() => {
|
|
89
|
+
render({ enrollment: { isAuditAccessExpired: true } });
|
|
90
|
+
});
|
|
91
|
+
test('snapshot: (auditAccessExpired, findAnotherCourse hyperlink)', () => {
|
|
92
|
+
expect(el.snapshot).toMatchSnapshot();
|
|
93
|
+
});
|
|
94
|
+
test('messages: (auditAccessExpired, upgradeToAccess)', () => {
|
|
95
|
+
expect(el.instance.children[0].children[0].el).toContain(messages.auditAccessExpired.defaultMessage);
|
|
96
|
+
expect(el.instance.findByType(Hyperlink)[0].children[0].el).toEqual(messages.findAnotherCourse.defaultMessage);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
describe('course run active and cannot upgrade', () => {
|
|
100
|
+
beforeEach(() => {
|
|
101
|
+
render({ courseRun: { isActive: true } });
|
|
102
|
+
});
|
|
103
|
+
test('snapshot: (upgradseDeadlinePassed, exploreCourseDetails hyperlink)', () => {
|
|
104
|
+
expect(el.snapshot).toMatchSnapshot();
|
|
105
|
+
});
|
|
106
|
+
test('messages: (upgradseDeadlinePassed, exploreCourseDetails hyperlink)', () => {
|
|
107
|
+
expect(el.instance.children[0].children[0].el).toContain(messages.upgradeDeadlinePassed.defaultMessage);
|
|
108
|
+
const link = el.instance.findByType(Hyperlink);
|
|
109
|
+
expect(link[0].children[0].el).toEqual(messages.exploreCourseDetails.defaultMessage);
|
|
110
|
+
expect(link[0].props.destination).toEqual(courseRunData.marketingUrl);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
test('no display if audit access not expired and (course is not active or can upgrade)', () => {
|
|
114
|
+
render();
|
|
115
|
+
// isEmptyRender() isn't true because the minimal is <Fragment />
|
|
116
|
+
expect(el.instance.children).toEqual([]);
|
|
117
|
+
render({ enrollment: { canUpgrade: true }, courseRun: { isActive: true } });
|
|
118
|
+
expect(el.instance.children).toEqual([]);
|
|
119
|
+
});
|
|
120
|
+
describe('unmet prerequisites', () => {
|
|
121
|
+
beforeEach(() => {
|
|
122
|
+
render({ enrollment: { coursewareAccess: { hasUnmetPrerequisites: true } } });
|
|
123
|
+
});
|
|
124
|
+
test('snapshot: unmetPrerequisites', () => {
|
|
125
|
+
expect(el.snapshot).toMatchSnapshot();
|
|
126
|
+
});
|
|
127
|
+
test('messages: prerequisitesNotMet', () => {
|
|
128
|
+
expect(el.instance.children[0].children[0].el).toContain(messages.prerequisitesNotMet.defaultMessage);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
describe('too early', () => {
|
|
132
|
+
describe('no start date', () => {
|
|
133
|
+
beforeEach(() => {
|
|
134
|
+
render({ enrollment: { coursewareAccess: { isTooEarly: true } }, courseRun: { startDate: null } });
|
|
135
|
+
});
|
|
136
|
+
test('snapshot', () => expect(el.snapshot).toMatchSnapshot());
|
|
137
|
+
test('messages', () => expect(el.instance.children).toEqual([]));
|
|
138
|
+
});
|
|
139
|
+
describe('has start date', () => {
|
|
140
|
+
beforeEach(() => {
|
|
141
|
+
render({ enrollment: { coursewareAccess: { isTooEarly: true } } });
|
|
142
|
+
});
|
|
143
|
+
test('snapshot', () => expect(el.snapshot).toMatchSnapshot());
|
|
144
|
+
|
|
145
|
+
test('messages: courseHasNotStarted', () => {
|
|
146
|
+
expect(el.instance.children[0].children[0].el).toContain(
|
|
147
|
+
formatMessage(messages.courseHasNotStarted, { startDate: courseRunData.startDate }),
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
describe('staff', () => {
|
|
153
|
+
beforeEach(() => {
|
|
154
|
+
render({ enrollment: { coursewareAccess: { isStaff: true } } });
|
|
155
|
+
});
|
|
156
|
+
test('snapshot: isStaff', () => {
|
|
157
|
+
expect(el.snapshot).toMatchSnapshot();
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
test('snapshot: stacking banners', () => {
|
|
161
|
+
render({
|
|
162
|
+
enrollment: {
|
|
163
|
+
coursewareAccess: {
|
|
164
|
+
isStaff: true,
|
|
165
|
+
isTooEarly: true,
|
|
166
|
+
hasUnmetPrerequisites: true,
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
expect(el.snapshot).toMatchSnapshot();
|
|
171
|
+
});
|
|
172
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Banner snapshot renders default banner 1`] = `
|
|
4
|
+
<Alert
|
|
5
|
+
className="mb-0"
|
|
6
|
+
icon={[Function]}
|
|
7
|
+
variant="info"
|
|
8
|
+
>
|
|
9
|
+
Hello, world!
|
|
10
|
+
</Alert>
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
exports[`Banner snapshot renders with custom class 1`] = `
|
|
14
|
+
<Alert
|
|
15
|
+
className="custom-class"
|
|
16
|
+
icon={[Function]}
|
|
17
|
+
variant="info"
|
|
18
|
+
>
|
|
19
|
+
Hello, world!
|
|
20
|
+
</Alert>
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
exports[`Banner snapshot renders with variants 1`] = `
|
|
24
|
+
<Alert
|
|
25
|
+
className="mb-0"
|
|
26
|
+
icon={[Function]}
|
|
27
|
+
variant="success"
|
|
28
|
+
>
|
|
29
|
+
Hello, world!
|
|
30
|
+
</Alert>
|
|
31
|
+
`;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`CourseBanner audit access expired, can upgrade snapshot: (auditAccessExpired, upgradeToAccess) 1`] = `
|
|
4
|
+
<Fragment>
|
|
5
|
+
<Banner>
|
|
6
|
+
Your audit access to this course has expired.
|
|
7
|
+
|
|
8
|
+
Upgrade now to access your course again.
|
|
9
|
+
</Banner>
|
|
10
|
+
</Fragment>
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
exports[`CourseBanner audit access expired, cannot upgrade snapshot: (auditAccessExpired, findAnotherCourse hyperlink) 1`] = `
|
|
14
|
+
<Fragment>
|
|
15
|
+
<Banner>
|
|
16
|
+
Your audit access to this course has expired.
|
|
17
|
+
|
|
18
|
+
<Hyperlink
|
|
19
|
+
destination=""
|
|
20
|
+
isInline={true}
|
|
21
|
+
>
|
|
22
|
+
Find another course
|
|
23
|
+
</Hyperlink>
|
|
24
|
+
</Banner>
|
|
25
|
+
</Fragment>
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
exports[`CourseBanner course run active and cannot upgrade snapshot: (upgradseDeadlinePassed, exploreCourseDetails hyperlink) 1`] = `
|
|
29
|
+
<Fragment>
|
|
30
|
+
<Banner>
|
|
31
|
+
Your upgrade deadline for this course has passed. To upgrade, enroll in a session that is farther in the future.
|
|
32
|
+
|
|
33
|
+
<Hyperlink
|
|
34
|
+
destination="marketing-url"
|
|
35
|
+
isInline={true}
|
|
36
|
+
>
|
|
37
|
+
Explore course details.
|
|
38
|
+
</Hyperlink>
|
|
39
|
+
</Banner>
|
|
40
|
+
</Fragment>
|
|
41
|
+
`;
|
|
42
|
+
|
|
43
|
+
exports[`CourseBanner snapshot: stacking banners 1`] = `<Fragment />`;
|
|
44
|
+
|
|
45
|
+
exports[`CourseBanner staff snapshot: isStaff 1`] = `<Fragment />`;
|
|
46
|
+
|
|
47
|
+
exports[`CourseBanner too early has start date snapshot 1`] = `
|
|
48
|
+
<Fragment>
|
|
49
|
+
<Banner>
|
|
50
|
+
You can't access this course just yet because the course hasn't started yet. The course will start on 11/11/3030.
|
|
51
|
+
</Banner>
|
|
52
|
+
</Fragment>
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
exports[`CourseBanner too early no start date snapshot 1`] = `<Fragment />`;
|
|
56
|
+
|
|
57
|
+
exports[`CourseBanner unmet prerequisites snapshot: unmetPrerequisites 1`] = `
|
|
58
|
+
<Fragment>
|
|
59
|
+
<Banner>
|
|
60
|
+
You can't access this course just yet because you have not met the pre-requisites.
|
|
61
|
+
</Banner>
|
|
62
|
+
</Fragment>
|
|
63
|
+
`;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import moment from 'moment';
|
|
2
|
+
import { useIntl } from '@edx/frontend-platform/i18n';
|
|
3
|
+
|
|
4
|
+
export const dateFormatter = (formatDate, date) => formatDate(moment(date).toDate(), {
|
|
5
|
+
year: 'numeric',
|
|
6
|
+
month: 'long',
|
|
7
|
+
day: 'numeric',
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// Hook
|
|
11
|
+
export const useFormatDate = () => {
|
|
12
|
+
const { formatDate } = useIntl();
|
|
13
|
+
return (date) => dateFormatter(formatDate, date);
|
|
14
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Provider } from 'react-redux';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import CourseBanner from './CourseBanner';
|
|
5
|
+
|
|
6
|
+
const CourseBannerWithProvider = ({ content, cardId }) => {
|
|
7
|
+
const { store } = content;
|
|
8
|
+
return (
|
|
9
|
+
<Provider store={store}>
|
|
10
|
+
<CourseBanner cardId={cardId} />
|
|
11
|
+
</Provider>
|
|
12
|
+
);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
CourseBannerWithProvider.propTypes = {
|
|
16
|
+
content: PropTypes.shape({
|
|
17
|
+
store: PropTypes.shape({}),
|
|
18
|
+
}),
|
|
19
|
+
cardId: PropTypes.string.isRequired,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default CourseBannerWithProvider;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { defineMessages } from '@edx/frontend-platform/i18n';
|
|
2
|
+
|
|
3
|
+
const messages = defineMessages({
|
|
4
|
+
auditAccessExpired: {
|
|
5
|
+
id: 'learner-dash.courseCard.banners.auditAccessExpired',
|
|
6
|
+
description: 'Audit access expiration banner message',
|
|
7
|
+
defaultMessage: 'Your audit access to this course has expired.',
|
|
8
|
+
},
|
|
9
|
+
upgradeToAccess: {
|
|
10
|
+
id: 'learner-dash.courseCard.banners.upgradeToAccess',
|
|
11
|
+
description: 'Upgrade prompt for audit-expired learners that can still upgrade',
|
|
12
|
+
defaultMessage: 'Upgrade now to access your course again.',
|
|
13
|
+
},
|
|
14
|
+
findAnotherCourse: {
|
|
15
|
+
id: 'learner-dash.courseCard.banners.findAnotherCourse',
|
|
16
|
+
description: 'Action prompt taking learners to course exploration',
|
|
17
|
+
defaultMessage: 'Find another course',
|
|
18
|
+
},
|
|
19
|
+
upgradeDeadlinePassed: {
|
|
20
|
+
id: 'learner-dash.courseCard.banners.upgradeDeadlinePassed',
|
|
21
|
+
description: 'Audit upgrade deadline passed banner message',
|
|
22
|
+
defaultMessage: 'Your upgrade deadline for this course has passed. To upgrade, enroll in a session that is farther in the future.',
|
|
23
|
+
},
|
|
24
|
+
exploreCourseDetails: {
|
|
25
|
+
id: 'learner-dash.courseCard.banners.exploreCourseDetails',
|
|
26
|
+
description: 'Action prompt taking learners to course details page',
|
|
27
|
+
defaultMessage: 'Explore course details.',
|
|
28
|
+
},
|
|
29
|
+
prerequisitesNotMet: {
|
|
30
|
+
id: 'learner-dash.courseCard.banners.prerequisitesNotMet',
|
|
31
|
+
description: 'Message to learners with unmet prerequisites',
|
|
32
|
+
defaultMessage: 'You can\'t access this course just yet because you have not met the pre-requisites.',
|
|
33
|
+
},
|
|
34
|
+
courseHasNotStarted: {
|
|
35
|
+
id: 'learner-dash.courseCard.banners.courseHasNotStarted',
|
|
36
|
+
description: 'Course has not started message',
|
|
37
|
+
defaultMessage: 'You can\'t access this course just yet because the course hasn\'t started yet. The course will start on {startDate}.',
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export default messages;
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
import { EXECUTIVE_EDUCATION_COURSE_MODES } from '../constants';
|
|
4
4
|
import { cardSimpleSelectors, mkCardSelector } from './simpleSelectors';
|
|
5
5
|
|
|
6
|
+
const loadDateVal = (date) => (date ? new Date(date) : null);
|
|
7
|
+
|
|
6
8
|
export const courseCard = {
|
|
7
9
|
course: mkCardSelector(
|
|
8
10
|
cardSimpleSelectors.course,
|
|
@@ -13,6 +15,7 @@ export const courseCard = {
|
|
|
13
15
|
courseRun: mkCardSelector(
|
|
14
16
|
cardSimpleSelectors.courseRun,
|
|
15
17
|
(courseRun) => (courseRun === null ? {} : {
|
|
18
|
+
startDate: loadDateVal(courseRun.startDate),
|
|
16
19
|
upgradeUrl: courseRun.upgradeUrl,
|
|
17
20
|
courseId: courseRun.courseId,
|
|
18
21
|
}),
|
|
@@ -35,7 +38,10 @@ export const courseCard = {
|
|
|
35
38
|
return { isEnrolled: false };
|
|
36
39
|
}
|
|
37
40
|
return {
|
|
41
|
+
coursewareAccess: enrollment.coursewareAccess,
|
|
38
42
|
isEnrolled: enrollment.isEnrolled,
|
|
43
|
+
|
|
44
|
+
isAuditAccessExpired: enrollment.isAuditAccessExpired,
|
|
39
45
|
isVerified: enrollment.isVerified,
|
|
40
46
|
isExecEd2UCourse: EXECUTIVE_EDUCATION_COURSE_MODES.includes(enrollment.mode),
|
|
41
47
|
canUpgrade: enrollment.canUpgrade,
|
|
@@ -32,6 +32,7 @@ describe('courseCard selectors module', () => {
|
|
|
32
32
|
describe('courseRun selector', () => {
|
|
33
33
|
beforeEach(() => {
|
|
34
34
|
loadSelector(courseCard.courseRun, {
|
|
35
|
+
startDate: '2000-10-20',
|
|
35
36
|
upgradeUrl: 'test-upgrade-url',
|
|
36
37
|
courseId: 'test-course-id',
|
|
37
38
|
});
|
|
@@ -42,6 +43,9 @@ describe('courseCard selectors module', () => {
|
|
|
42
43
|
it('returns {} object if null courseRun received', () => {
|
|
43
44
|
expect(selector(null)).toEqual({});
|
|
44
45
|
});
|
|
46
|
+
it('passes startDate converted to date', () => {
|
|
47
|
+
expect(selected.startDate).toEqual(new Date(testData.startDate));
|
|
48
|
+
});
|
|
45
49
|
it('passes upgradeUrl', () => {
|
|
46
50
|
expect(selected.upgradeUrl).toEqual(testData.upgradeUrl);
|
|
47
51
|
});
|
|
@@ -51,6 +55,12 @@ describe('courseCard selectors module', () => {
|
|
|
51
55
|
});
|
|
52
56
|
describe('enrollment selector', () => {
|
|
53
57
|
const defaultData = {
|
|
58
|
+
coursewareAccess: {
|
|
59
|
+
isStaff: false,
|
|
60
|
+
hasUnmetPrereqs: false,
|
|
61
|
+
isTooEarly: false,
|
|
62
|
+
},
|
|
63
|
+
isAuditAccessExpired: 'test-is-audit-access-expired',
|
|
54
64
|
isEnrolled: 'test-is-enrolled',
|
|
55
65
|
isVerified: 'test-is-verified',
|
|
56
66
|
mode: 'default',
|
|
@@ -65,6 +75,9 @@ describe('courseCard selectors module', () => {
|
|
|
65
75
|
it('returns { isEnrolled: false } object if null enrollment received', () => {
|
|
66
76
|
expect(selector(null)).toEqual({ isEnrolled: false });
|
|
67
77
|
});
|
|
78
|
+
it('passes coursewareAccess', () => {
|
|
79
|
+
expect(selected.coursewareAccess).toEqual(testData.coursewareAccess);
|
|
80
|
+
});
|
|
68
81
|
it('passes isEnrolled', () => {
|
|
69
82
|
expect(selected.isEnrolled).toEqual(testData.isEnrolled);
|
|
70
83
|
});
|
|
@@ -74,6 +87,9 @@ describe('courseCard selectors module', () => {
|
|
|
74
87
|
it('passes canUpgrade', () => {
|
|
75
88
|
expect(selected.canUpgrade).toEqual(testData.canUpgrade);
|
|
76
89
|
});
|
|
90
|
+
it('passes isAuditAccessExpired', () => {
|
|
91
|
+
expect(selected.isAuditAccessExpired).toEqual(testData.isAuditAccessExpired);
|
|
92
|
+
});
|
|
77
93
|
it('returns isExecEd2UCourse: false if mode is not in EXECUTIVE_EDUCATION_COURSE_MODES', () => {
|
|
78
94
|
expect(selected.isExecEd2UCourse).toEqual(false);
|
|
79
95
|
});
|
package/src/index.jsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import CohesionWrapper from './cohesion-wrapper/index';
|
|
2
|
+
import CourseBanner from './course-banner';
|
|
2
3
|
import EnterpriseDashboardModal from './dashboard-modal/index';
|
|
3
4
|
import HelpChatbot from './chatbot/index';
|
|
4
5
|
import UpgradeButton from './upgrade-button';
|
|
@@ -6,5 +7,11 @@ import UserCareerMenu from './career-menu/index';
|
|
|
6
7
|
import UserDashboardMenu from './dashboard-menu/index';
|
|
7
8
|
|
|
8
9
|
export {
|
|
9
|
-
CohesionWrapper,
|
|
10
|
+
CohesionWrapper,
|
|
11
|
+
CourseBanner,
|
|
12
|
+
EnterpriseDashboardModal,
|
|
13
|
+
HelpChatbot,
|
|
14
|
+
UpgradeButton,
|
|
15
|
+
UserCareerMenu,
|
|
16
|
+
UserDashboardMenu,
|
|
10
17
|
};
|
package/src/setupTest.js
CHANGED
|
@@ -16,27 +16,17 @@ jest.mock('@src/generic/messages', () => jest.fn(() => { }), { virtual: true });
|
|
|
16
16
|
|
|
17
17
|
// Mock the `formatMessage` utility from i18n
|
|
18
18
|
// For working with shallow renders in tests via @edx/react-unit-test-utils
|
|
19
|
-
jest.mock('@edx/frontend-platform/i18n', () =>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return <format-message-function {...{ message: msg, values }} />;
|
|
31
|
-
}
|
|
32
|
-
Object.keys(values).forEach((key) => {
|
|
33
|
-
// eslint-disable-next-line
|
|
34
|
-
message = message.replaceAll(`{${key}}`, values[key]);
|
|
35
|
-
});
|
|
36
|
-
return message;
|
|
37
|
-
},
|
|
38
|
-
}),
|
|
39
|
-
}));
|
|
19
|
+
jest.mock('@edx/frontend-platform/i18n', () => {
|
|
20
|
+
const { formatMessage } = jest.requireActual('./testUtils');
|
|
21
|
+
const formatDate = jest.fn(date => new Date(date).toLocaleDateString()).mockName('useIntl.formatDate');
|
|
22
|
+
return {
|
|
23
|
+
...jest.requireActual('@edx/frontend-platform/i18n'),
|
|
24
|
+
useIntl: () => ({
|
|
25
|
+
formatMessage,
|
|
26
|
+
formatDate,
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
29
|
+
});
|
|
40
30
|
|
|
41
31
|
/* eslint-disable no-console */
|
|
42
32
|
const supressWarningBlock = (callback) => {
|
package/src/testUtils.js
CHANGED
|
@@ -82,3 +82,23 @@ export class MockUseState {
|
|
|
82
82
|
return { ...this.hooks.state };
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Mocked formatMessage provided by react-intl
|
|
88
|
+
*/
|
|
89
|
+
export const formatMessage = (msg, values) => {
|
|
90
|
+
let message = msg.defaultMessage;
|
|
91
|
+
if (values === undefined) {
|
|
92
|
+
return message;
|
|
93
|
+
}
|
|
94
|
+
// check if value is not a primitive type.
|
|
95
|
+
if (Object.values(values).filter(value => Object(value) === value).length) {
|
|
96
|
+
// eslint-disable-next-line react/jsx-filename-extension
|
|
97
|
+
return <format-message-function {...{ message: msg, values }} />;
|
|
98
|
+
}
|
|
99
|
+
Object.keys(values).forEach((key) => {
|
|
100
|
+
// eslint-disable-next-line
|
|
101
|
+
message = message.replaceAll(`{${key}}`, values[key]);
|
|
102
|
+
});
|
|
103
|
+
return message;
|
|
104
|
+
};
|