richie-education 2.34.1-dev34 → 2.34.1-dev37
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.
|
@@ -15,7 +15,7 @@ import { OpenEdxApiProfileFactory } from 'utils/test/factories/openEdx';
|
|
|
15
15
|
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
|
|
16
16
|
import { setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper';
|
|
17
17
|
import { AppWrapperProps } from 'utils/test/wrappers/types';
|
|
18
|
-
import {
|
|
18
|
+
import { expectAlertError, expectAlertWarning, expectNoAlertWarning } from 'utils/test/expectAlert';
|
|
19
19
|
|
|
20
20
|
jest.mock('utils/context', () => ({
|
|
21
21
|
__esModule: true,
|
|
@@ -71,7 +71,7 @@ describe('OpenEdxFullNameForm', () => {
|
|
|
71
71
|
wrapper: Wrapper,
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
const $input = await screen.findByRole('textbox', { name: '
|
|
74
|
+
const $input = await screen.findByRole('textbox', { name: 'First name and last name' });
|
|
75
75
|
expect($input).toHaveValue('');
|
|
76
76
|
});
|
|
77
77
|
|
|
@@ -93,7 +93,7 @@ describe('OpenEdxFullNameForm', () => {
|
|
|
93
93
|
wrapper: Wrapper,
|
|
94
94
|
});
|
|
95
95
|
|
|
96
|
-
const $input = await screen.findByRole('textbox', { name: '
|
|
96
|
+
const $input = await screen.findByRole('textbox', { name: 'First name and last name' });
|
|
97
97
|
expect($input).toHaveValue(user.full_name);
|
|
98
98
|
});
|
|
99
99
|
|
|
@@ -119,15 +119,25 @@ describe('OpenEdxFullNameForm', () => {
|
|
|
119
119
|
|
|
120
120
|
expect(submitCallbacks.hasOwnProperty('openEdxFullNameForm')).toBe(true);
|
|
121
121
|
|
|
122
|
-
const $input = await screen.findByRole('textbox', { name: '
|
|
122
|
+
const $input = await screen.findByRole('textbox', { name: 'First name and last name' });
|
|
123
123
|
expect($input).toHaveValue('');
|
|
124
124
|
|
|
125
|
+
await expectAlertWarning(
|
|
126
|
+
'Please check that your first name and last name are correct. They will be used on official document (e.g: certificate, contract, etc.)',
|
|
127
|
+
);
|
|
128
|
+
|
|
125
129
|
// Submit the form
|
|
126
130
|
await act(async () => {
|
|
127
131
|
await expect(submitCallbacks.openEdxFullNameForm()).rejects.not.toBeUndefined();
|
|
128
132
|
});
|
|
129
133
|
|
|
130
134
|
screen.getByText('This field is required.');
|
|
135
|
+
await expectNoAlertWarning(
|
|
136
|
+
'Please check that your first name and last name are correct. They will be used on official document (e.g: certificate, contract, etc.)',
|
|
137
|
+
);
|
|
138
|
+
await expectAlertError(
|
|
139
|
+
'Please check that your first name and last name are correct. They will be used on official document (e.g: certificate, contract, etc.)',
|
|
140
|
+
);
|
|
131
141
|
});
|
|
132
142
|
|
|
133
143
|
it('should require a value with at least 3 chars to submit the form', async () => {
|
|
@@ -152,7 +162,7 @@ describe('OpenEdxFullNameForm', () => {
|
|
|
152
162
|
|
|
153
163
|
expect(submitCallbacks.hasOwnProperty('openEdxFullNameForm')).toBe(true);
|
|
154
164
|
|
|
155
|
-
const $input = await screen.findByRole('textbox', { name: '
|
|
165
|
+
const $input = await screen.findByRole('textbox', { name: 'First name and last name' });
|
|
156
166
|
expect($input).toHaveValue('');
|
|
157
167
|
|
|
158
168
|
const eventHandler = userEvent.setup();
|
|
@@ -189,7 +199,7 @@ describe('OpenEdxFullNameForm', () => {
|
|
|
189
199
|
|
|
190
200
|
expect(submitCallbacks.hasOwnProperty('openEdxFullNameForm')).toBe(true);
|
|
191
201
|
|
|
192
|
-
const $input = await screen.findByRole('textbox', { name: '
|
|
202
|
+
const $input = await screen.findByRole('textbox', { name: 'First name and last name' });
|
|
193
203
|
expect($input).toHaveValue('');
|
|
194
204
|
|
|
195
205
|
const eventHandler = userEvent.setup();
|
|
@@ -224,6 +234,6 @@ describe('OpenEdxFullNameForm', () => {
|
|
|
224
234
|
wrapper: Wrapper,
|
|
225
235
|
});
|
|
226
236
|
|
|
227
|
-
await
|
|
237
|
+
await expectAlertError('An error occurred while fetching your profile. Please retry later.');
|
|
228
238
|
});
|
|
229
239
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ButtonElement, Input } from '@openfun/cunningham-react';
|
|
1
|
+
import { ButtonElement, Input, Alert, VariantType } from '@openfun/cunningham-react';
|
|
2
2
|
import { FormattedMessage, defineMessages, useIntl } from 'react-intl';
|
|
3
3
|
import { FormProvider, useForm } from 'react-hook-form';
|
|
4
4
|
import * as Yup from 'yup';
|
|
@@ -8,7 +8,6 @@ import { useSession } from 'contexts/SessionContext';
|
|
|
8
8
|
import useOpenEdxProfile from 'hooks/useOpenEdxProfile';
|
|
9
9
|
import Form, { getLocalizedCunninghamErrorProp } from 'components/Form';
|
|
10
10
|
import { Spinner } from 'components/Spinner';
|
|
11
|
-
import Banner, { BannerType } from 'components/Banner';
|
|
12
11
|
import { useSaleTunnelContext } from 'components/SaleTunnel/GenericSaleTunnel';
|
|
13
12
|
|
|
14
13
|
const messages = defineMessages({
|
|
@@ -19,14 +18,15 @@ const messages = defineMessages({
|
|
|
19
18
|
},
|
|
20
19
|
fullNameInputLabel: {
|
|
21
20
|
id: 'components.OpenEdxFullNameForm.fullNameInputLabel',
|
|
22
|
-
description: 'Label of "
|
|
23
|
-
defaultMessage: '
|
|
21
|
+
description: 'Label of "First name and last name" field of the openEdx full name form',
|
|
22
|
+
defaultMessage: 'First name and last name',
|
|
24
23
|
},
|
|
25
24
|
fullNameInputDescription: {
|
|
26
25
|
id: 'components.OpenEdxFullNameForm.fullNameInputDescription',
|
|
27
|
-
description:
|
|
26
|
+
description:
|
|
27
|
+
'Description about the "First name and last name" field of the openEdx full name form.',
|
|
28
28
|
defaultMessage:
|
|
29
|
-
'Please check that your
|
|
29
|
+
'Please check that your first name and last name are correct. They will be used on official document (e.g: certificate, contract, etc.)',
|
|
30
30
|
},
|
|
31
31
|
submitButtonLabel: {
|
|
32
32
|
id: 'components.OpenEdxFullNameForm.submitButtonLabel',
|
|
@@ -128,27 +128,24 @@ const OpenEdxFullNameForm = () => {
|
|
|
128
128
|
|
|
129
129
|
if (error) {
|
|
130
130
|
// display get error message
|
|
131
|
-
return <
|
|
131
|
+
return <Alert type={VariantType.ERROR}>{error}</Alert>;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
return (
|
|
135
135
|
<FormProvider {...form}>
|
|
136
136
|
<Form name="openedx-fullname-form" noValidate>
|
|
137
|
+
<Alert type={formState.errors.name?.message ? VariantType.ERROR : VariantType.WARNING}>
|
|
138
|
+
<FormattedMessage {...messages.fullNameInputDescription} />
|
|
139
|
+
</Alert>
|
|
137
140
|
<Input
|
|
138
141
|
{...register('name')}
|
|
139
|
-
className="form-field"
|
|
142
|
+
className="form-field mt-s"
|
|
140
143
|
required
|
|
141
144
|
fullWidth
|
|
142
145
|
label={intl.formatMessage(messages.fullNameInputLabel)}
|
|
143
146
|
value={formState.defaultValues?.name}
|
|
144
|
-
state={
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
text={
|
|
148
|
-
error ||
|
|
149
|
-
getLocalizedCunninghamErrorProp(intl, formState.errors.name?.message).text ||
|
|
150
|
-
intl.formatMessage(messages.fullNameInputDescription)
|
|
151
|
-
}
|
|
147
|
+
state={error || formState.errors.name?.message ? 'error' : 'default'}
|
|
148
|
+
text={error || getLocalizedCunninghamErrorProp(intl, formState.errors.name?.message).text}
|
|
152
149
|
/>
|
|
153
150
|
</Form>
|
|
154
151
|
</FormProvider>
|
|
@@ -184,7 +184,7 @@ describe('SaleTunnel', () => {
|
|
|
184
184
|
*/
|
|
185
185
|
screen.getByText('Information');
|
|
186
186
|
|
|
187
|
-
const nameInput = screen.getByLabelText('
|
|
187
|
+
const nameInput = screen.getByLabelText('First name and last name');
|
|
188
188
|
await user.type(nameInput, 'John Doe');
|
|
189
189
|
|
|
190
190
|
/**
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { waitFor } from '@testing-library/react';
|
|
2
|
+
import { VariantType } from '@openfun/cunningham-react';
|
|
3
|
+
|
|
4
|
+
export const expectAlertError = (message: string, rootElement: ParentNode = document) => {
|
|
5
|
+
return expectAlert(VariantType.ERROR, message, rootElement);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const expectAlertInfo = (message: string, rootElement: ParentNode = document) => {
|
|
9
|
+
return expectAlert(VariantType.INFO, message, rootElement);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const expectAlertSuccess = (message: string, rootElement: ParentNode = document) => {
|
|
13
|
+
return expectAlert(VariantType.SUCCESS, message, rootElement);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const expectAlertWarning = (message: string, rootElement: ParentNode = document) => {
|
|
17
|
+
return expectAlert(VariantType.WARNING, message, rootElement);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const expectAlert = (
|
|
21
|
+
type: VariantType,
|
|
22
|
+
message: string,
|
|
23
|
+
rootElement: ParentNode = document,
|
|
24
|
+
) => {
|
|
25
|
+
return waitFor(async () => {
|
|
26
|
+
// Cunningham Alert has a class with the alert variant type
|
|
27
|
+
const alert = rootElement.querySelector(`.c__alert--${type}`) as HTMLElement;
|
|
28
|
+
expect(alert).not.toBeNull();
|
|
29
|
+
expect(alert).toHaveTextContent(message);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const expectNoAlert = (
|
|
34
|
+
type: VariantType,
|
|
35
|
+
message: string,
|
|
36
|
+
rootElement: ParentNode = document,
|
|
37
|
+
) => {
|
|
38
|
+
return waitFor(() => {
|
|
39
|
+
// Check that no alert exists with this message and type
|
|
40
|
+
const alerts = rootElement.querySelectorAll('.c__alert');
|
|
41
|
+
const matchingAlert = Array.from(alerts).find(
|
|
42
|
+
(alert) =>
|
|
43
|
+
alert.classList.contains(`c__alert--${type}`) && alert.textContent?.includes(message),
|
|
44
|
+
);
|
|
45
|
+
expect(matchingAlert).toBeUndefined();
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const expectNoAlertError = (message: string, rootElement: ParentNode = document) => {
|
|
50
|
+
return expectNoAlert(VariantType.ERROR, message, rootElement);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const expectNoAlertInfo = (message: string, rootElement: ParentNode = document) => {
|
|
54
|
+
return expectNoAlert(VariantType.INFO, message, rootElement);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const expectNoAlertSuccess = (message: string, rootElement: ParentNode = document) => {
|
|
58
|
+
return expectNoAlert(VariantType.SUCCESS, message, rootElement);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const expectNoAlertWarning = (message: string, rootElement: ParentNode = document) => {
|
|
62
|
+
return expectNoAlert(VariantType.WARNING, message, rootElement);
|
|
63
|
+
};
|