@edx/frontend-plugin-learner-dashboard 1.6.1 → 1.7.1
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/cohesion-wrapper/CohesionWrapper.js +3 -0
- package/dist/cohesion-wrapper/CohesionWrapper.js.map +1 -1
- 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/cookie.js +12 -35
- package/dist/tracking/cookie.js.map +1 -1
- package/package.json +2 -1
- package/src/cohesion-wrapper/CohesionWrapper.jsx +3 -0
- package/src/cohesion-wrapper/CohesionWrapper.test.jsx +1 -0
- 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/cookie.js +10 -36
- package/src/tracking/cookie.test.js +2 -42
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
|
+
};
|
package/src/tracking/cookie.js
CHANGED
|
@@ -1,41 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (cookie.indexOf(name) === 0) {
|
|
9
|
-
return cookie.substring(name.length, cookie.length);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return '';
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const setCorrelationIDCookie = (correlationId) => {
|
|
17
|
-
const now = new Date();
|
|
18
|
-
const time = now.getTime();
|
|
19
|
-
|
|
20
|
-
// Cookie expires in 30 minutes, same as when set in marketing page
|
|
21
|
-
const expireTime = time + 1800;
|
|
22
|
-
now.setTime(expireTime);
|
|
23
|
-
document.cookie = `tglr_correlation_id=${correlationId}; expires=${now.toUTCString()}; path=/`;
|
|
24
|
-
};
|
|
1
|
+
// general cookie setter, expires after 30 minutes
|
|
2
|
+
export function setCookie(cookieName, cookieValue) {
|
|
3
|
+
const a = new Date();
|
|
4
|
+
// set to expire after 30 minutes, or 1.8 million milliseconds
|
|
5
|
+
a.setTime(a.getTime() + 1800000);
|
|
6
|
+
document.cookie = `${cookieName}\x3d${cookieValue}; expires\x3d${a.toGMTString()}; path\x3d/; domain\x3d.edx.org;`;
|
|
7
|
+
}
|
|
25
8
|
|
|
26
9
|
export const handleCorrelationIDCookie = () => {
|
|
27
|
-
//
|
|
28
|
-
const
|
|
29
|
-
const urlParams = new URLSearchParams(queryString);
|
|
30
|
-
const correlationCookie = getCorrelationIDCookie();
|
|
31
|
-
const randomUUID = window.crypto.randomUUID();
|
|
32
|
-
|
|
33
|
-
const correlationId = urlParams.get('correlationId') || correlationCookie || randomUUID;
|
|
34
|
-
|
|
35
|
-
// Set CorrelationID cookie if one wasn't set
|
|
36
|
-
if (correlationCookie !== correlationId) {
|
|
37
|
-
setCorrelationIDCookie(correlationId);
|
|
38
|
-
}
|
|
10
|
+
// set correlation ID to a random UUID
|
|
11
|
+
const correlationId = window.crypto.randomUUID();
|
|
39
12
|
|
|
13
|
+
setCookie('tglr_correlation_id', correlationId);
|
|
40
14
|
return correlationId;
|
|
41
15
|
};
|
|
@@ -12,63 +12,23 @@ describe('cookie functions for Correlation ID', () => {
|
|
|
12
12
|
randomUUID: jest.fn(() => 'mocked-random-uuid'),
|
|
13
13
|
},
|
|
14
14
|
});
|
|
15
|
-
|
|
16
|
-
jest.spyOn(global, 'decodeURIComponent').mockImplementation((val) => val);
|
|
17
15
|
});
|
|
18
16
|
|
|
19
17
|
afterEach(() => {
|
|
20
18
|
jest.restoreAllMocks(); // Restore the original document.cookie
|
|
21
19
|
});
|
|
22
20
|
|
|
23
|
-
describe('
|
|
24
|
-
it('returns the Correlation ID cookie if present', () => {
|
|
25
|
-
document.cookie = 'tglr_correlation_id=some_uuid_string;another_cookie=another_string';
|
|
26
|
-
decodeURIComponent.mockReturnValue(document.cookie);
|
|
27
|
-
|
|
28
|
-
expect(cookieFunctions.getCorrelationIDCookie()).toEqual('some_uuid_string');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('returns an empty string when there is no CorrelationID present', () => {
|
|
32
|
-
document.cookie = 'cookie=string';
|
|
33
|
-
decodeURIComponent.mockReturnValue(document.cookie);
|
|
34
|
-
|
|
35
|
-
expect(cookieFunctions.getCorrelationIDCookie()).toEqual('');
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('setCorrelationIDCookie', () => {
|
|
21
|
+
describe('setCookie', () => {
|
|
40
22
|
it('sets the Correlation ID cookie', () => {
|
|
41
23
|
const correlationCookie = 'some_uuid_string';
|
|
42
|
-
cookieFunctions.
|
|
24
|
+
cookieFunctions.setCookie('tglr_correlation_id', correlationCookie);
|
|
43
25
|
|
|
44
26
|
expect(document.cookie).toContain(`tglr_correlation_id=${correlationCookie}`);
|
|
45
27
|
});
|
|
46
28
|
});
|
|
47
29
|
|
|
48
30
|
describe('handleCorrelationIDCookie', () => {
|
|
49
|
-
it('returns the correlation ID from the URL parameters', () => {
|
|
50
|
-
jest.spyOn(URLSearchParams.prototype, 'get').mockReturnValueOnce('correlation_id_uuid');
|
|
51
|
-
|
|
52
|
-
expect(cookieFunctions.handleCorrelationIDCookie()).toEqual('correlation_id_uuid');
|
|
53
|
-
expect(document.cookie).toContain('tglr_correlation_id=correlation_id_uuid');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('returns the correlation ID from the cookies', () => {
|
|
57
|
-
Object.defineProperty(document, 'cookie', {
|
|
58
|
-
writable: true,
|
|
59
|
-
value: 'tglr_correlation_id=correlation_id_cookie',
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
jest.spyOn(URLSearchParams.prototype, 'get').mockReturnValueOnce('');
|
|
63
|
-
jest.spyOn(cookieFunctions, 'getCorrelationIDCookie').mockImplementation(() => 'correlation_id_cookie');
|
|
64
|
-
|
|
65
|
-
expect(cookieFunctions.handleCorrelationIDCookie()).toEqual('correlation_id_cookie');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
31
|
it('returns the correlation ID provided by a random UUID generator', () => {
|
|
69
|
-
jest.spyOn(URLSearchParams.prototype, 'get').mockReturnValueOnce('');
|
|
70
|
-
jest.spyOn(cookieFunctions, 'getCorrelationIDCookie').mockImplementation(() => '');
|
|
71
|
-
|
|
72
32
|
expect(cookieFunctions.handleCorrelationIDCookie()).toEqual('mocked-random-uuid');
|
|
73
33
|
});
|
|
74
34
|
});
|