@edx/frontend-plugin-learner-dashboard 3.3.4 → 3.4.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/dynamic-experience-slot/DynamicExperienceSlot.js +7 -2
- package/dist/dynamic-experience-slot/DynamicExperienceSlot.js.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/package.json +6 -3
- package/dist/progressive-profiling-dashboard/api/service.js +32 -0
- package/dist/progressive-profiling-dashboard/api/service.js.map +1 -0
- package/dist/progressive-profiling-dashboard/data/progressiveProfilingFields.js +60 -0
- package/dist/progressive-profiling-dashboard/data/progressiveProfilingFields.js.map +1 -0
- package/dist/progressive-profiling-dashboard/field-renderer/FieldRenderer.js +86 -0
- package/dist/progressive-profiling-dashboard/field-renderer/FieldRenderer.js.map +1 -0
- package/dist/progressive-profiling-dashboard/field-renderer/index.js +14 -0
- package/dist/progressive-profiling-dashboard/field-renderer/index.js.map +1 -0
- package/dist/progressive-profiling-dashboard/hooks/useProgressiveProfilingForm.js +58 -0
- package/dist/progressive-profiling-dashboard/hooks/useProgressiveProfilingForm.js.map +1 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/ProgressiveProfiling.js +157 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/ProgressiveProfiling.js.map +1 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/ProgressiveProfilingPageModal.js +62 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/ProgressiveProfilingPageModal.js.map +1 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/components/welcome-page-layout/LargeLayout.js +101 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/components/welcome-page-layout/LargeLayout.js.map +1 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/components/welcome-page-layout/MediumLayout.js +125 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/components/welcome-page-layout/MediumLayout.js.map +1 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/components/welcome-page-layout/SmallLayout.js +106 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/components/welcome-page-layout/SmallLayout.js.map +1 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/components/welcome-page-layout/index.js +28 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/components/welcome-page-layout/index.js.map +1 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/components/welcome-page-layout/messages.js +40 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/components/welcome-page-layout/messages.js.map +1 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/index.js +59 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/index.js.map +1 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/index.js +14 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/index.js.map +1 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/index.scss +269 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/messages.js +68 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/messages.js.map +1 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/service/getThirdPartyAuthContext.js +28 -0
- package/dist/progressive-profiling-dashboard/progressive-profiling-authn-replica/service/getThirdPartyAuthContext.js.map +1 -0
- package/dist/progressive-profiling-dashboard/utils/constants.js +12 -0
- package/dist/progressive-profiling-dashboard/utils/constants.js.map +1 -0
- package/dist/tracking/constants.js +2 -1
- package/dist/tracking/constants.js.map +1 -1
- package/dist/tracking/trackers/progressiveProfiling.js +42 -0
- package/dist/tracking/trackers/progressiveProfiling.js.map +1 -0
- package/dist/tracking/utils.js +15 -2
- package/dist/tracking/utils.js.map +1 -1
- package/package.json +7 -4
- package/src/dynamic-experience-slot/DynamicExperienceSlot.jsx +9 -2
- package/src/index.jsx +2 -0
- package/src/progressive-profiling-dashboard/api/service.js +24 -0
- package/src/progressive-profiling-dashboard/data/progressiveProfilingFields.js +85 -0
- package/src/progressive-profiling-dashboard/field-renderer/FieldRenderer.jsx +87 -0
- package/src/progressive-profiling-dashboard/field-renderer/index.jsx +1 -0
- package/src/progressive-profiling-dashboard/hooks/useProgressiveProfilingForm.jsx +55 -0
- package/src/progressive-profiling-dashboard/progressive-profiling-authn-replica/ProgressiveProfiling.jsx +156 -0
- package/src/progressive-profiling-dashboard/progressive-profiling-authn-replica/ProgressiveProfilingPageModal.jsx +59 -0
- package/src/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/components/welcome-page-layout/LargeLayout.jsx +105 -0
- package/src/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/components/welcome-page-layout/MediumLayout.jsx +95 -0
- package/src/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/components/welcome-page-layout/SmallLayout.jsx +85 -0
- package/src/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/components/welcome-page-layout/index.jsx +3 -0
- package/src/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/components/welcome-page-layout/messages.js +35 -0
- package/src/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/index.jsx +46 -0
- package/src/progressive-profiling-dashboard/progressive-profiling-authn-replica/base-container/tests/BaseContainer.test.jsx +76 -0
- package/src/progressive-profiling-dashboard/progressive-profiling-authn-replica/index.jsx +1 -0
- package/src/progressive-profiling-dashboard/progressive-profiling-authn-replica/index.scss +269 -0
- package/src/progressive-profiling-dashboard/progressive-profiling-authn-replica/messages.jsx +62 -0
- package/src/progressive-profiling-dashboard/progressive-profiling-authn-replica/service/getThirdPartyAuthContext.js +24 -0
- package/src/progressive-profiling-dashboard/progressive-profiling-authn-replica/tests/ProgressiveProfiling.test.jsx +165 -0
- package/src/progressive-profiling-dashboard/utils/constants.jsx +5 -0
- package/src/tracking/constants.js +2 -0
- package/src/tracking/trackers/progressiveProfiling.js +38 -0
- package/src/tracking/utils.js +16 -2
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getConfig } from '@edx/frontend-platform';
|
|
2
|
+
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
|
3
|
+
|
|
4
|
+
export default async function getThirdPartyAuthContext(urlParams) {
|
|
5
|
+
const requestConfig = {
|
|
6
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
7
|
+
params: urlParams,
|
|
8
|
+
isPublic: true,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const { data } = await getAuthenticatedHttpClient()
|
|
12
|
+
.get(
|
|
13
|
+
`${getConfig().LMS_BASE_URL}/api/mfe_context`,
|
|
14
|
+
requestConfig,
|
|
15
|
+
)
|
|
16
|
+
.catch((e) => {
|
|
17
|
+
throw (e);
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
fieldDescriptions: data.registrationFields || {},
|
|
21
|
+
optionalFields: data.optionalFields || {},
|
|
22
|
+
thirdPartyAuthContext: data.contextData || {},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
act, render, screen, fireEvent, waitFor,
|
|
4
|
+
} from '@testing-library/react';
|
|
5
|
+
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
trackProgressiveProfilingSkipLinkClick,
|
|
9
|
+
trackProgressiveProfilingSubmitClick,
|
|
10
|
+
} from '../../../tracking/trackers/progressiveProfiling';
|
|
11
|
+
import getThirdPartyAuthContext from '../service/getThirdPartyAuthContext';
|
|
12
|
+
import useProgressiveProfilingForm from '../../hooks/useProgressiveProfilingForm';
|
|
13
|
+
import ProgressiveProfilingPage from '../ProgressiveProfiling';
|
|
14
|
+
|
|
15
|
+
const mockNavigate = jest.fn();
|
|
16
|
+
|
|
17
|
+
jest.mock('react-router-dom', () => ({
|
|
18
|
+
useNavigate: () => mockNavigate,
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
jest.mock('@edx/frontend-platform', () => ({
|
|
22
|
+
getConfig: () => ({
|
|
23
|
+
SITE_NAME: 'Test Site',
|
|
24
|
+
AUTHN_PROGRESSIVE_PROFILING_SUPPORT_LINK: null,
|
|
25
|
+
}),
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
jest.mock('@edx/frontend-platform/auth', () => ({
|
|
29
|
+
getAuthenticatedUser: () => ({ username: 'testuser', fullName: 'Test User' }),
|
|
30
|
+
getAuthenticatedHttpClient: () => ({}),
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
jest.mock('../../hooks/useProgressiveProfilingForm');
|
|
34
|
+
|
|
35
|
+
jest.mock('../service/getThirdPartyAuthContext');
|
|
36
|
+
|
|
37
|
+
jest.mock('../../../tracking/trackers/progressiveProfiling', () => ({
|
|
38
|
+
trackProgressiveProfilingSkipLinkClick: jest.fn(),
|
|
39
|
+
trackProgressiveProfilingSubmitClick: jest.fn(),
|
|
40
|
+
trackProgressiveProfilingSupportLinkClick: jest.fn(),
|
|
41
|
+
trackProgressiveProfilingPageViewed: jest.fn(),
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
// eslint-disable-next-line react/prop-types, func-names
|
|
45
|
+
jest.mock('../base-container', () => function ({ children }) {
|
|
46
|
+
return <div data-testid="base-container">{children}</div>;
|
|
47
|
+
});
|
|
48
|
+
// eslint-disable-next-line react/prop-types, func-names
|
|
49
|
+
jest.mock('../ProgressiveProfilingPageModal', () => function ({ isOpen }) {
|
|
50
|
+
return isOpen ? <div data-testid="skip-modal" /> : null;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const mockSubmit = jest.fn();
|
|
54
|
+
|
|
55
|
+
const defaultHookReturn = {
|
|
56
|
+
loadState: 'complete',
|
|
57
|
+
submitState: 'default',
|
|
58
|
+
error: null,
|
|
59
|
+
values: {},
|
|
60
|
+
fieldList: [],
|
|
61
|
+
onChangeHandler: jest.fn(),
|
|
62
|
+
submit: mockSubmit,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const renderPage = async () => {
|
|
66
|
+
let result;
|
|
67
|
+
await act(async () => {
|
|
68
|
+
result = render(
|
|
69
|
+
<IntlProvider locale="en">
|
|
70
|
+
<ProgressiveProfilingPage />
|
|
71
|
+
</IntlProvider>,
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
return result;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
describe('ProgressiveProfilingPage', () => {
|
|
78
|
+
beforeEach(() => {
|
|
79
|
+
jest.clearAllMocks();
|
|
80
|
+
useProgressiveProfilingForm.mockReturnValue(defaultHookReturn);
|
|
81
|
+
getThirdPartyAuthContext.mockResolvedValue({});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('renders the page heading', async () => {
|
|
85
|
+
await renderPage();
|
|
86
|
+
expect(screen.getByText('A few questions for you will help us get smarter.')).toBeInTheDocument();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('renders the Submit and Skip buttons', async () => {
|
|
90
|
+
await renderPage();
|
|
91
|
+
expect(screen.getByText('Submit')).toBeInTheDocument();
|
|
92
|
+
expect(screen.getByText('Skip for now')).toBeInTheDocument();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('calls getThirdPartyAuthContext on mount', async () => {
|
|
96
|
+
await renderPage();
|
|
97
|
+
expect(getThirdPartyAuthContext).toHaveBeenCalledTimes(1);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('navigates to / and fires tracking on successful submit', async () => {
|
|
101
|
+
mockSubmit.mockResolvedValue(true);
|
|
102
|
+
await renderPage();
|
|
103
|
+
|
|
104
|
+
fireEvent.click(screen.getByText('Submit'));
|
|
105
|
+
|
|
106
|
+
await waitFor(() => {
|
|
107
|
+
expect(trackProgressiveProfilingSubmitClick).toHaveBeenCalledWith({
|
|
108
|
+
isGenderSelected: false,
|
|
109
|
+
isYearOfBirthSelected: false,
|
|
110
|
+
isLevelOfEducationSelected: false,
|
|
111
|
+
isWorkExperienceSelected: false,
|
|
112
|
+
});
|
|
113
|
+
expect(mockNavigate).toHaveBeenCalledWith('/', { replace: true });
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('does not navigate when submit fails', async () => {
|
|
118
|
+
mockSubmit.mockResolvedValue(false);
|
|
119
|
+
await renderPage();
|
|
120
|
+
|
|
121
|
+
fireEvent.click(screen.getByText('Submit'));
|
|
122
|
+
|
|
123
|
+
await waitFor(() => expect(mockSubmit).toHaveBeenCalled());
|
|
124
|
+
expect(mockNavigate).not.toHaveBeenCalled();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('opens the skip modal when Skip is clicked', async () => {
|
|
128
|
+
await renderPage();
|
|
129
|
+
expect(screen.queryByTestId('skip-modal')).toBeNull();
|
|
130
|
+
|
|
131
|
+
fireEvent.click(screen.getByText('Skip for now'));
|
|
132
|
+
|
|
133
|
+
expect(trackProgressiveProfilingSkipLinkClick).toHaveBeenCalled();
|
|
134
|
+
expect(screen.getByTestId('skip-modal')).toBeInTheDocument();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('shows an error alert when the hook returns an error', async () => {
|
|
138
|
+
useProgressiveProfilingForm.mockReturnValue({
|
|
139
|
+
...defaultHookReturn,
|
|
140
|
+
error: new Error('Something went wrong'),
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
await renderPage();
|
|
144
|
+
|
|
145
|
+
expect(screen.getByText("We couldn't update your profile")).toBeInTheDocument();
|
|
146
|
+
expect(screen.getByText('An error occurred. You can complete your profile in settings at any time.')).toBeInTheDocument();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('disables submit when submitState is pending', async () => {
|
|
150
|
+
useProgressiveProfilingForm.mockReturnValue({
|
|
151
|
+
...defaultHookReturn,
|
|
152
|
+
submitState: 'pending',
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const { container } = await renderPage();
|
|
156
|
+
|
|
157
|
+
// In pending state Paragon replaces the label with a spinner; query by class instead
|
|
158
|
+
expect(container.querySelector('.pp-page__button-width')).toBeDisabled();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('does not render the support link when config is unset', async () => {
|
|
162
|
+
await renderPage();
|
|
163
|
+
expect(screen.queryByText('Learn more about how we use this information.')).toBeNull();
|
|
164
|
+
});
|
|
165
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/* eslint-disable function-paren-newline */
|
|
2
|
+
import { createEventTracker, createPageEventTracker } from '../utils';
|
|
3
|
+
|
|
4
|
+
export const eventNames = {
|
|
5
|
+
progressiveProfilingSubmitClick: 'edx.bi.welcome.page.submit.clicked',
|
|
6
|
+
progressiveProfilingSkipLinkClick: 'edx.bi.welcome.page.skip.link.clicked',
|
|
7
|
+
disablePostRegistrationRecommendations: 'edx.bi.user.recommendations.not.enabled',
|
|
8
|
+
progressiveProfilingSupportLinkClick: 'edx.bi.welcome.page.support.link.clicked',
|
|
9
|
+
loginAndRegistration: 'login_and_registration',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// Event link tracker for Progressive profiling skip button click
|
|
13
|
+
export const trackProgressiveProfilingSkipLinkClick = evenProperties => createEventTracker(
|
|
14
|
+
eventNames.progressiveProfilingSkipLinkClick, { ...evenProperties },
|
|
15
|
+
)();
|
|
16
|
+
|
|
17
|
+
// Event tracker for progressive profiling submit button click
|
|
18
|
+
export const trackProgressiveProfilingSubmitClick = (evenProperties) => createEventTracker(
|
|
19
|
+
eventNames.progressiveProfilingSubmitClick,
|
|
20
|
+
{ ...evenProperties },
|
|
21
|
+
)();
|
|
22
|
+
|
|
23
|
+
// Event tracker for progressive profiling submit button click
|
|
24
|
+
export const trackDisablePostRegistrationRecommendations = (evenProperties) => createEventTracker(
|
|
25
|
+
eventNames.disablePostRegistrationRecommendations,
|
|
26
|
+
{ ...evenProperties },
|
|
27
|
+
)();
|
|
28
|
+
|
|
29
|
+
// Tracks the progressive profiling page event.
|
|
30
|
+
export const trackProgressiveProfilingPageViewed = () => {
|
|
31
|
+
createPageEventTracker(eventNames.loginAndRegistration, 'welcome')();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Tracks the progressive profiling support link click.
|
|
35
|
+
export const trackProgressiveProfilingSupportLinkClick = () => createEventTracker(
|
|
36
|
+
eventNames.progressiveProfilingSupportLinkClick,
|
|
37
|
+
{},
|
|
38
|
+
)();
|
package/src/tracking/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getConfig } from '@edx/frontend-platform';
|
|
2
2
|
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
|
3
|
-
import { sendTrackEvent } from '@edx/frontend-platform/analytics';
|
|
3
|
+
import { sendTrackEvent, sendPageEvent } from '@edx/frontend-platform/analytics';
|
|
4
|
+
import { LEARNER_HOME_APP_NAME } from './constants';
|
|
4
5
|
|
|
5
6
|
const LINK_TIMEOUT = 300;
|
|
6
7
|
|
|
@@ -16,7 +17,20 @@ export const logEvent = ({ eventName, data, courseId }) => getAuthenticatedHttpC
|
|
|
16
17
|
|
|
17
18
|
export const createEventTracker = (name, options = {}) => () => sendTrackEvent(
|
|
18
19
|
name,
|
|
19
|
-
{ ...options, app_name:
|
|
20
|
+
{ ...options, app_name: LEARNER_HOME_APP_NAME },
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates an event tracker function that sends a tracking event with the given name and options.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} name - The name of the event to be tracked.
|
|
27
|
+
* @param {object} [options={}] - Additional options to be included with the event.
|
|
28
|
+
* @returns {function} - A function that, when called, sends the tracking event.
|
|
29
|
+
*/
|
|
30
|
+
export const createPageEventTracker = (name, options = null) => () => sendPageEvent(
|
|
31
|
+
name,
|
|
32
|
+
options,
|
|
33
|
+
{ app_name: LEARNER_HOME_APP_NAME },
|
|
20
34
|
);
|
|
21
35
|
|
|
22
36
|
export const createLinkTracker = (tracker, href) => (e) => {
|