@edx/frontend-plugin-learner-dashboard 3.0.4 → 3.2.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/.github/workflows/ci.yml +1 -1
- package/.github/workflows/release.yml +1 -1
- package/.nvmrc +1 -1
- package/dist/course-banner/Banner.js +11 -14
- package/dist/course-banner/Banner.js.map +1 -1
- package/dist/course-banner/CourseBanner.js +3 -4
- package/dist/course-banner/CourseBanner.js.map +1 -1
- package/dist/course-banner/index.js +4 -5
- package/dist/course-banner/index.js.map +1 -1
- package/dist/dashboard-modal/index.js +3 -4
- package/dist/dashboard-modal/index.js.map +1 -1
- package/dist/data/redux/app/selectors/simpleSelectors.js +15 -30
- package/dist/data/redux/app/selectors/simpleSelectors.js.map +1 -1
- package/dist/data/redux/hooks.js +1 -4
- package/dist/data/redux/hooks.js.map +1 -1
- package/dist/data/redux/requests/selectors.js +15 -30
- package/dist/data/redux/requests/selectors.js.map +1 -1
- package/dist/dynamic-experience-slot/DynamicExperienceSlot.js +81 -0
- package/dist/dynamic-experience-slot/DynamicExperienceSlot.js.map +1 -0
- package/dist/dynamic-experience-slot/index.js +10 -0
- package/dist/dynamic-experience-slot/index.js.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -1
- package/dist/mocks/optimizely/index.js +5 -8
- package/dist/mocks/optimizely/index.js.map +1 -1
- package/dist/notices-redirect/api.js +38 -0
- package/dist/notices-redirect/api.js.map +1 -0
- package/dist/notices-redirect/hooks.js +44 -0
- package/dist/notices-redirect/hooks.js.map +1 -0
- package/dist/notices-redirect/index.js +22 -0
- package/dist/notices-redirect/index.js.map +1 -0
- package/dist/notices-redirect/messages.js +16 -0
- package/dist/notices-redirect/messages.js.map +1 -0
- package/dist/package.json +4 -2
- package/dist/setupTest.js +10 -15
- package/dist/setupTest.js.map +1 -1
- package/dist/tracking/trackers/upgradeButton.js +9 -12
- package/dist/tracking/trackers/upgradeButton.js.map +1 -1
- package/dist/tracking/utils.js +13 -19
- package/dist/tracking/utils.js.map +1 -1
- package/dist/ucl-wrapper/UclWrapper.js +42 -0
- package/dist/ucl-wrapper/UclWrapper.js.map +1 -0
- package/dist/ucl-wrapper/index.js +10 -0
- package/dist/ucl-wrapper/index.js.map +1 -0
- package/dist/upgrade-button/UpgradeButton.js +3 -4
- package/dist/upgrade-button/UpgradeButton.js.map +1 -1
- package/dist/upgrade-button/UpgradeButtonWrapper.js +3 -4
- package/dist/upgrade-button/UpgradeButtonWrapper.js.map +1 -1
- package/dist/upgrade-button/index.js +4 -5
- package/dist/upgrade-button/index.js.map +1 -1
- package/package.json +5 -3
- package/src/dashboard-modal/EnterpriseDashboardModalWrapper.test.jsx +2 -1
- package/src/dynamic-experience-slot/DynamicExperienceSlot.jsx +54 -0
- package/src/dynamic-experience-slot/DynamicExperienceSlot.test.jsx +108 -0
- package/src/dynamic-experience-slot/index.jsx +3 -0
- package/src/index.jsx +6 -0
- package/src/notices-redirect/api.js +25 -0
- package/src/notices-redirect/api.test.js +65 -0
- package/src/notices-redirect/hooks.js +35 -0
- package/src/notices-redirect/hooks.test.js +90 -0
- package/src/notices-redirect/index.jsx +15 -0
- package/src/notices-redirect/index.test.jsx +22 -0
- package/src/notices-redirect/messages.js +11 -0
- package/src/ucl-wrapper/UclWrapper.jsx +43 -0
- package/src/ucl-wrapper/UclWrapper.test.jsx +17 -0
- package/src/ucl-wrapper/index.jsx +3 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/* eslint-disable react/prop-types */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { render, screen, act } from '@testing-library/react';
|
|
4
|
+
import '@testing-library/jest-dom';
|
|
5
|
+
import { ErrorBoundary } from 'react-error-boundary';
|
|
6
|
+
import DynamicExperienceSlot from './DynamicExperienceSlot';
|
|
7
|
+
|
|
8
|
+
// Helper to catch the custom error signals thrown by the component
|
|
9
|
+
const ErrorFallback = ({ error }) => (
|
|
10
|
+
<span>Fallback Triggered: {error.name}</span>
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
describe('DynamicExperienceSlot', () => {
|
|
14
|
+
let mockUcl;
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
jest.useFakeTimers();
|
|
18
|
+
// Reset window.UCL before each test
|
|
19
|
+
delete window.UCL;
|
|
20
|
+
|
|
21
|
+
mockUcl = {
|
|
22
|
+
mount: jest.fn(),
|
|
23
|
+
unmount: jest.fn(),
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
jest.runOnlyPendingTimers();
|
|
29
|
+
jest.useRealTimers();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('waits for window.UCL and calls mount when available', async () => {
|
|
33
|
+
render(<DynamicExperienceSlot widgetName="test-widget" />);
|
|
34
|
+
|
|
35
|
+
// Initially UCL is undefined, so mount shouldn't be called
|
|
36
|
+
expect(mockUcl.mount).not.toHaveBeenCalled();
|
|
37
|
+
|
|
38
|
+
// Simulate UCL loading onto the window
|
|
39
|
+
window.UCL = mockUcl;
|
|
40
|
+
|
|
41
|
+
// Advance timers to trigger the setInterval in useUCL
|
|
42
|
+
act(() => {
|
|
43
|
+
jest.advanceTimersByTime(100);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
expect(mockUcl.mount).toHaveBeenCalledWith(
|
|
47
|
+
'test-widget',
|
|
48
|
+
expect.any(HTMLDivElement),
|
|
49
|
+
expect.objectContaining({
|
|
50
|
+
onFallbackShouldRender: expect.any(Function),
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('passes additional props through to UCL.mount', () => {
|
|
56
|
+
window.UCL = mockUcl;
|
|
57
|
+
|
|
58
|
+
// We pass 'theme' and 'userId' which should end up in the 'rest' object
|
|
59
|
+
render(
|
|
60
|
+
<DynamicExperienceSlot
|
|
61
|
+
widgetName="test-widget"
|
|
62
|
+
theme="dark"
|
|
63
|
+
userId="12345"
|
|
64
|
+
/>,
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
expect(mockUcl.mount).toHaveBeenCalledWith(
|
|
68
|
+
'test-widget',
|
|
69
|
+
expect.any(HTMLDivElement),
|
|
70
|
+
expect.objectContaining({
|
|
71
|
+
theme: 'dark',
|
|
72
|
+
userId: '12345',
|
|
73
|
+
onFallbackShouldRender: expect.any(Function),
|
|
74
|
+
}),
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('triggers fallback signal when requested by widget', () => {
|
|
79
|
+
window.UCL = mockUcl;
|
|
80
|
+
let triggerFallback;
|
|
81
|
+
|
|
82
|
+
mockUcl.mount.mockImplementation((name, el, props) => {
|
|
83
|
+
triggerFallback = props.onFallbackShouldRender;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
render(
|
|
87
|
+
// You use their component instead of writing your own class
|
|
88
|
+
<ErrorBoundary FallbackComponent={ErrorFallback}>
|
|
89
|
+
<DynamicExperienceSlot widgetName="test-widget" />
|
|
90
|
+
</ErrorBoundary>,
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
act(() => {
|
|
94
|
+
triggerFallback(true);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
expect(screen.getByText(/Fallback Triggered: RenderFallbackSignal/i)).toBeInTheDocument();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('calls unmount on cleanup', () => {
|
|
101
|
+
window.UCL = mockUcl;
|
|
102
|
+
const { unmount } = render(<DynamicExperienceSlot widgetName="test-widget" />);
|
|
103
|
+
|
|
104
|
+
unmount();
|
|
105
|
+
|
|
106
|
+
expect(mockUcl.unmount).toHaveBeenCalled();
|
|
107
|
+
});
|
|
108
|
+
});
|
package/src/index.jsx
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import CohesionWrapper from './cohesion-wrapper/index';
|
|
2
2
|
import CourseBanner from './course-banner';
|
|
3
|
+
import DynamicExperienceSlot from './dynamic-experience-slot';
|
|
3
4
|
import EnterpriseDashboardModal from './dashboard-modal/index';
|
|
4
5
|
import HelpChatbot from './chatbot/index';
|
|
6
|
+
import UclWrapper from './ucl-wrapper';
|
|
5
7
|
import UpgradeButton from './upgrade-button';
|
|
6
8
|
import UserCareerMenu from './career-menu/index';
|
|
7
9
|
import UserDashboardMenu from './dashboard-menu/index';
|
|
10
|
+
import NoticesRedirect from './notices-redirect/index';
|
|
8
11
|
|
|
9
12
|
export {
|
|
10
13
|
CohesionWrapper,
|
|
11
14
|
CourseBanner,
|
|
15
|
+
DynamicExperienceSlot,
|
|
12
16
|
EnterpriseDashboardModal,
|
|
13
17
|
HelpChatbot,
|
|
18
|
+
NoticesRedirect,
|
|
19
|
+
UclWrapper,
|
|
14
20
|
UpgradeButton,
|
|
15
21
|
UserCareerMenu,
|
|
16
22
|
UserDashboardMenu,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getConfig } from '@edx/frontend-platform';
|
|
2
|
+
import { getAuthenticatedHttpClient, getAuthenticatedUser } from '@edx/frontend-platform/auth';
|
|
3
|
+
import { logError, logInfo } from '@edx/frontend-platform/logging';
|
|
4
|
+
|
|
5
|
+
export const noticesUrl = `${getConfig().LMS_BASE_URL}/notices/api/v1/unacknowledged`;
|
|
6
|
+
|
|
7
|
+
export const getNotices = ({ onLoad, notFoundMessage }) => {
|
|
8
|
+
const authenticatedUser = getAuthenticatedUser();
|
|
9
|
+
|
|
10
|
+
const handleError = async (e) => {
|
|
11
|
+
// Error probably means that notices is not installed, which is fine.
|
|
12
|
+
const { customAttributes: { httpErrorStatus } } = e;
|
|
13
|
+
if (httpErrorStatus === 404) {
|
|
14
|
+
logInfo(`${e}. ${notFoundMessage}`);
|
|
15
|
+
} else {
|
|
16
|
+
logError(e);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
if (authenticatedUser) {
|
|
20
|
+
return getAuthenticatedHttpClient().get(noticesUrl, {}).then(onLoad).catch(handleError);
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default { getNotices };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { getAuthenticatedHttpClient, getAuthenticatedUser } from '@edx/frontend-platform/auth';
|
|
2
|
+
import { logError, logInfo } from '@edx/frontend-platform/logging';
|
|
3
|
+
|
|
4
|
+
import * as api from './api';
|
|
5
|
+
|
|
6
|
+
jest.mock('@edx/frontend-platform', () => ({
|
|
7
|
+
getConfig: jest.fn(() => ({
|
|
8
|
+
LMS_BASE_URL: 'test-lms-url',
|
|
9
|
+
})),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
jest.mock('@edx/frontend-platform/auth', () => ({
|
|
13
|
+
getAuthenticatedHttpClient: jest.fn(),
|
|
14
|
+
getAuthenticatedUser: jest.fn(),
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
jest.mock('@edx/frontend-platform/logging', () => ({
|
|
18
|
+
logError: jest.fn(),
|
|
19
|
+
logInfo: jest.fn(),
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
const testData = 'test-data';
|
|
23
|
+
const successfulGet = () => Promise.resolve(testData);
|
|
24
|
+
const error404 = { customAttributes: { httpErrorStatus: 404 }, test: 'error' };
|
|
25
|
+
const error404Get = () => Promise.reject(error404);
|
|
26
|
+
const error500 = { customAttributes: { httpErrorStatus: 500 }, test: 'error' };
|
|
27
|
+
const error500Get = () => Promise.reject(error500);
|
|
28
|
+
|
|
29
|
+
const get = jest.fn().mockImplementation(successfulGet);
|
|
30
|
+
getAuthenticatedHttpClient.mockReturnValue({ get });
|
|
31
|
+
const authenticatedUser = { fake: 'user' };
|
|
32
|
+
getAuthenticatedUser.mockReturnValue(authenticatedUser);
|
|
33
|
+
|
|
34
|
+
const onLoad = jest.fn();
|
|
35
|
+
describe('getNotices api method', () => {
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
jest.clearAllMocks();
|
|
38
|
+
});
|
|
39
|
+
describe('behavior', () => {
|
|
40
|
+
describe('not authenticated', () => {
|
|
41
|
+
it('does not fetch anything', () => {
|
|
42
|
+
getAuthenticatedUser.mockReturnValueOnce(null);
|
|
43
|
+
api.getNotices({ onLoad });
|
|
44
|
+
expect(get).not.toHaveBeenCalled();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe('authenticated', () => {
|
|
48
|
+
it('fetches noticesUrl with onLoad behavior', async () => {
|
|
49
|
+
await api.getNotices({ onLoad });
|
|
50
|
+
expect(get).toHaveBeenCalledWith(api.noticesUrl, {});
|
|
51
|
+
expect(onLoad).toHaveBeenCalledWith(testData);
|
|
52
|
+
});
|
|
53
|
+
it('calls logInfo if fetch fails with 404', async () => {
|
|
54
|
+
get.mockImplementation(error404Get);
|
|
55
|
+
await api.getNotices({ onLoad });
|
|
56
|
+
expect(logInfo).toHaveBeenCalledWith(`${error404}. ${api.error404Message}`);
|
|
57
|
+
});
|
|
58
|
+
it('calls logError if fetch fails with non-404 error', async () => {
|
|
59
|
+
get.mockImplementation(error500Get);
|
|
60
|
+
await api.getNotices({ onLoad });
|
|
61
|
+
expect(logError).toHaveBeenCalledWith(error500);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { getConfig } from '@edx/frontend-platform';
|
|
3
|
+
import { useIntl } from '@edx/frontend-platform/i18n';
|
|
4
|
+
|
|
5
|
+
import { getNotices } from './api';
|
|
6
|
+
import messages from './messages';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This component uses the platform-plugin-notices plugin to function.
|
|
10
|
+
* If the user has an unacknowledged notice, they will be rerouted off
|
|
11
|
+
* course home and onto a full-screen notice page. If the plugin is not
|
|
12
|
+
* installed, or there are no notices, we just passthrough this component.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const useNoticesRedirectData = () => {
|
|
16
|
+
const [isRedirected, setIsRedirected] = React.useState(false);
|
|
17
|
+
const { formatMessage } = useIntl();
|
|
18
|
+
|
|
19
|
+
React.useEffect(() => {
|
|
20
|
+
if (getConfig().ENABLE_NOTICES) {
|
|
21
|
+
getNotices({
|
|
22
|
+
onLoad: (data) => {
|
|
23
|
+
if (data?.data?.results?.length > 0) {
|
|
24
|
+
setIsRedirected(true);
|
|
25
|
+
window.location.replace(`${data.data.results[0]}?next=${window.location.href}`);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
notFoundMessage: formatMessage(messages.error404Message),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}, [setIsRedirected, formatMessage]);
|
|
32
|
+
return { isRedirected };
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default useNoticesRedirectData;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { renderHook, waitFor } from '@testing-library/react';
|
|
2
|
+
import { getConfig } from '@edx/frontend-platform';
|
|
3
|
+
import { useNoticesRedirectData } from './hooks';
|
|
4
|
+
import { getNotices } from './api';
|
|
5
|
+
|
|
6
|
+
jest.mock('@edx/frontend-platform', () => ({
|
|
7
|
+
getConfig: jest.fn(),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
jest.mock('./api', () => ({
|
|
11
|
+
getNotices: jest.fn(),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
jest.mock('@edx/frontend-platform/i18n', () => {
|
|
15
|
+
const { formatMessage: fn } = jest.requireActual('testUtils');
|
|
16
|
+
return {
|
|
17
|
+
...jest.requireActual('@edx/frontend-platform/i18n'),
|
|
18
|
+
useIntl: () => ({
|
|
19
|
+
formatMessage: fn,
|
|
20
|
+
}),
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
jest.mock('react-router-dom', () => ({
|
|
25
|
+
redirect: jest.fn(),
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
describe('useNoticesRedirectData', () => {
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
jest.clearAllMocks();
|
|
31
|
+
getConfig.mockReturnValue({ ENABLE_NOTICES: true });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should initialize with isRedirected set to false', () => {
|
|
35
|
+
getConfig.mockReturnValueOnce({ ENABLE_NOTICES: false });
|
|
36
|
+
const { result } = renderHook(() => useNoticesRedirectData());
|
|
37
|
+
|
|
38
|
+
expect(result.current.isRedirected).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should call getNotices API if ENABLE_NOTICES is true', () => {
|
|
42
|
+
renderHook(() => useNoticesRedirectData());
|
|
43
|
+
|
|
44
|
+
expect(getNotices).toHaveBeenCalledTimes(1);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should NOT call getNotices API if ENABLE_NOTICES is false', () => {
|
|
48
|
+
getConfig.mockReturnValueOnce({ ENABLE_NOTICES: false });
|
|
49
|
+
renderHook(() => useNoticesRedirectData());
|
|
50
|
+
|
|
51
|
+
expect(getNotices).not.toHaveBeenCalled();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should NOT redirect or set isRedirected if API returns no results or empty data', () => {
|
|
55
|
+
const apiResponses = [
|
|
56
|
+
{ data: { results: [] } }, // Empty array
|
|
57
|
+
{ data: {} }, // Missing results property
|
|
58
|
+
{}, // Missing data property
|
|
59
|
+
{ data: { results: null } }, // Null results
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
apiResponses.forEach((response) => {
|
|
63
|
+
getNotices.mockImplementation(({ onLoad }) => {
|
|
64
|
+
onLoad(response);
|
|
65
|
+
});
|
|
66
|
+
const { result } = renderHook(() => useNoticesRedirectData());
|
|
67
|
+
|
|
68
|
+
expect(result.current.isRedirected).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should redirect and set isRedirected to true if API returns results', async () => {
|
|
73
|
+
const targetUrl = 'http://notices.example.com/notice';
|
|
74
|
+
const apiResponse = {
|
|
75
|
+
data: {
|
|
76
|
+
results: [targetUrl, 'extra-url-ignored'], // Only the first URL is used
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
getNotices.mockImplementation(({ onLoad }) => {
|
|
81
|
+
onLoad(apiResponse);
|
|
82
|
+
});
|
|
83
|
+
const { result } = renderHook(() => useNoticesRedirectData());
|
|
84
|
+
|
|
85
|
+
// Wait for the asynchronous effect hook to run and trigger state update/redirect
|
|
86
|
+
await waitFor(() => {
|
|
87
|
+
expect(result.current.isRedirected).toBe(true);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-named-as-default
|
|
2
|
+
import useNoticesRedirectData from './hooks';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This component uses the platform-plugin-notices plugin to function.
|
|
6
|
+
* If the user has an unacknowledged notice, they will be rerouted off
|
|
7
|
+
* course home and onto a full-screen notice page. If the plugin is not
|
|
8
|
+
* installed, or there are no notices, we just passthrough this component.
|
|
9
|
+
*/
|
|
10
|
+
const NoticesRedirect = () => {
|
|
11
|
+
useNoticesRedirectData();
|
|
12
|
+
return null;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default NoticesRedirect;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line import/no-named-as-default
|
|
4
|
+
import useNoticesRedirectData from './hooks';
|
|
5
|
+
import NoticesRedirect from '.';
|
|
6
|
+
|
|
7
|
+
jest.mock('./hooks', () => jest.fn());
|
|
8
|
+
|
|
9
|
+
const hookProps = { isRedirected: false };
|
|
10
|
+
|
|
11
|
+
describe('NoticesRedirect component', () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
useNoticesRedirectData.mockClear();
|
|
14
|
+
});
|
|
15
|
+
describe('behavior', () => {
|
|
16
|
+
it('initializes hooks', () => {
|
|
17
|
+
useNoticesRedirectData.mockReturnValue(hookProps);
|
|
18
|
+
render(<NoticesRedirect />);
|
|
19
|
+
expect(useNoticesRedirectData).toHaveBeenCalled();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineMessages } from '@edx/frontend-platform/i18n';
|
|
2
|
+
|
|
3
|
+
const messages = defineMessages({
|
|
4
|
+
error404Message: {
|
|
5
|
+
id: 'learner-dash.notices.error404Message',
|
|
6
|
+
defaultMessage: 'This probably happened because the notices plugin is not installed on platform.',
|
|
7
|
+
description: 'Error message when notices API returns 404',
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export default messages;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { logError, logInfo } from '@edx/frontend-platform/logging';
|
|
3
|
+
|
|
4
|
+
const UclWrapper = () => {
|
|
5
|
+
const [isLoaded, setLoaded] = useState(false);
|
|
6
|
+
|
|
7
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
8
|
+
window._UCL = {
|
|
9
|
+
identity: '2u-edx-learner-dashboard',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (isLoaded) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const head = document.getElementsByTagName('head')[0];
|
|
18
|
+
const script = document.createElement('script');
|
|
19
|
+
script.src = 'https://affiliate-bundle.api.highereducation.com/latest/UCL.adapter.js';
|
|
20
|
+
script.dataset.testId = 'ucl-test';
|
|
21
|
+
script.async = true;
|
|
22
|
+
|
|
23
|
+
script.onload = () => {
|
|
24
|
+
if (window.UCL && typeof window.UCL === 'function') {
|
|
25
|
+
logInfo('UCL script loaded successfully!');
|
|
26
|
+
} else {
|
|
27
|
+
// in the case that the script successfully loaded but UCL is still not found
|
|
28
|
+
logError('window.UCL not found after UCL script load.');
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
script.onerror = (e) => {
|
|
33
|
+
logError('UCL script failed to load', e);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
head.appendChild(script);
|
|
37
|
+
setLoaded(true);
|
|
38
|
+
}, [isLoaded]);
|
|
39
|
+
|
|
40
|
+
return null;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default UclWrapper;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
render,
|
|
4
|
+
} from '@testing-library/react';
|
|
5
|
+
|
|
6
|
+
import UclWrapper from './UclWrapper';
|
|
7
|
+
|
|
8
|
+
describe('UCL Wrapper loads', () => {
|
|
9
|
+
it('should load the UCL wrapper into the head', () => {
|
|
10
|
+
render(<UclWrapper />);
|
|
11
|
+
const script = document.querySelector('[data-test-id="ucl-test"]');
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
14
|
+
expect(window._UCL.identity).toEqual('2u-edx-learner-dashboard');
|
|
15
|
+
expect(script.dataset.testId).toEqual('ucl-test');
|
|
16
|
+
});
|
|
17
|
+
});
|