@blaze-cms/react-page-builder 0.125.0-auth-updates.5 → 0.125.0-core-styles.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/CHANGELOG.md +2 -30
- package/README.md +1 -2
- package/lib/components/Card/Card.js +22 -31
- package/lib/components/Card/Card.js.map +1 -1
- package/lib/components/Card/CardContainer.js +1 -2
- package/lib/components/Card/CardContainer.js.map +1 -1
- package/lib/components/List/components/Cards/CardsRender.js.map +1 -1
- package/lib/components/List/components/Cards/CardsRenderItem.js +1 -2
- package/lib/components/List/components/Cards/CardsRenderItem.js.map +1 -1
- package/lib/components/Login/LoggedInMessage.js +28 -0
- package/lib/components/Login/LoggedInMessage.js.map +1 -0
- package/lib/components/Login/Login.js +135 -0
- package/lib/components/Login/Login.js.map +1 -0
- package/lib/components/Login/LoginForm.js +112 -0
- package/lib/components/Login/LoginForm.js.map +1 -0
- package/lib/components/Login/helpers/check-gtm-children.js +42 -0
- package/lib/components/Login/helpers/check-gtm-children.js.map +1 -0
- package/lib/components/Login/helpers/get-url-to-use.js +18 -0
- package/lib/components/Login/helpers/get-url-to-use.js.map +1 -0
- package/lib/components/Login/helpers/index.js +22 -0
- package/lib/components/Login/helpers/index.js.map +1 -0
- package/lib/components/Login/index.js +12 -0
- package/lib/components/Login/index.js.map +1 -0
- package/lib/components/PasswordReset/PasswordReset.js +172 -0
- package/lib/components/PasswordReset/PasswordReset.js.map +1 -0
- package/lib/components/PasswordReset/helpers/index.js +15 -0
- package/lib/components/PasswordReset/helpers/index.js.map +1 -0
- package/lib/components/PasswordReset/helpers/validatePassword.js +16 -0
- package/lib/components/PasswordReset/helpers/validatePassword.js.map +1 -0
- package/lib/components/PasswordReset/index.js +12 -0
- package/lib/components/PasswordReset/index.js.map +1 -0
- package/lib/components/PasswordResetRequest/PasswordResetRequest.js +114 -0
- package/lib/components/PasswordResetRequest/PasswordResetRequest.js.map +1 -0
- package/lib/components/PasswordResetRequest/index.js +12 -0
- package/lib/components/PasswordResetRequest/index.js.map +1 -0
- package/lib/components/index.js +15 -0
- package/lib/components/index.js.map +1 -1
- package/lib/constants/index.js +14 -2
- package/lib/constants/index.js.map +1 -1
- package/lib/index.js +0 -6
- package/lib/index.js.map +1 -1
- package/lib-es/components/Card/Card.js +5 -15
- package/lib-es/components/Card/Card.js.map +1 -1
- package/lib-es/components/Card/CardContainer.js +1 -2
- package/lib-es/components/Card/CardContainer.js.map +1 -1
- package/lib-es/components/List/components/Cards/CardsRender.js.map +1 -1
- package/lib-es/components/List/components/Cards/CardsRenderItem.js +1 -2
- package/lib-es/components/List/components/Cards/CardsRenderItem.js.map +1 -1
- package/lib-es/components/Login/LoggedInMessage.js +18 -0
- package/lib-es/components/Login/LoggedInMessage.js.map +1 -0
- package/lib-es/components/Login/Login.js +83 -0
- package/lib-es/components/Login/Login.js.map +1 -0
- package/lib-es/components/Login/LoginForm.js +89 -0
- package/lib-es/components/Login/LoginForm.js.map +1 -0
- package/lib-es/components/Login/helpers/check-gtm-children.js +35 -0
- package/lib-es/components/Login/helpers/check-gtm-children.js.map +1 -0
- package/lib-es/components/Login/helpers/get-url-to-use.js +10 -0
- package/lib-es/components/Login/helpers/get-url-to-use.js.map +1 -0
- package/lib-es/components/Login/helpers/index.js +4 -0
- package/lib-es/components/Login/helpers/index.js.map +1 -0
- package/lib-es/components/Login/index.js +3 -0
- package/lib-es/components/Login/index.js.map +1 -0
- package/lib-es/components/PasswordReset/PasswordReset.js +144 -0
- package/lib-es/components/PasswordReset/PasswordReset.js.map +1 -0
- package/lib-es/components/PasswordReset/helpers/index.js +3 -0
- package/lib-es/components/PasswordReset/helpers/index.js.map +1 -0
- package/lib-es/components/PasswordReset/helpers/validatePassword.js +7 -0
- package/lib-es/components/PasswordReset/helpers/validatePassword.js.map +1 -0
- package/lib-es/components/PasswordReset/index.js +3 -0
- package/lib-es/components/PasswordReset/index.js.map +1 -0
- package/lib-es/components/PasswordResetRequest/PasswordResetRequest.js +92 -0
- package/lib-es/components/PasswordResetRequest/PasswordResetRequest.js.map +1 -0
- package/lib-es/components/PasswordResetRequest/index.js +3 -0
- package/lib-es/components/PasswordResetRequest/index.js.map +1 -0
- package/lib-es/components/index.js +3 -0
- package/lib-es/components/index.js.map +1 -1
- package/lib-es/constants/index.js +7 -1
- package/lib-es/constants/index.js.map +1 -1
- package/lib-es/index.js +1 -1
- package/lib-es/index.js.map +1 -1
- package/package.json +7 -7
- package/src/components/Card/Card.js +3 -13
- package/src/components/Card/CardContainer.js +1 -2
- package/src/components/List/components/Cards/CardsRender.js +0 -1
- package/src/components/List/components/Cards/CardsRenderItem.js +1 -2
- package/src/components/Login/LoggedInMessage.js +24 -0
- package/src/components/Login/Login.js +74 -0
- package/src/components/Login/LoginForm.js +81 -0
- package/src/components/Login/helpers/check-gtm-children.js +30 -0
- package/src/components/Login/helpers/get-url-to-use.js +6 -0
- package/src/components/Login/helpers/index.js +4 -0
- package/src/components/Login/index.js +3 -0
- package/src/components/PasswordReset/PasswordReset.js +120 -0
- package/src/components/PasswordReset/helpers/index.js +3 -0
- package/src/components/PasswordReset/helpers/validatePassword.js +8 -0
- package/src/components/PasswordReset/index.js +3 -0
- package/src/components/PasswordResetRequest/PasswordResetRequest.js +82 -0
- package/src/components/PasswordResetRequest/index.js +3 -0
- package/src/components/index.js +7 -1
- package/src/constants/index.js +13 -0
- package/src/index.js +1 -1
- package/tests/unit/src/components/Card/Card.test.js +7 -18
- package/tests/unit/src/components/Card/__snapshots__/Card.test.js.snap +0 -5
- package/tests/unit/src/components/Login/Login.test.js +36 -0
- package/tests/unit/src/components/Login/__snapshots__/Login.test.js.snap +103 -0
- package/tests/unit/src/components/Login/helpers/check-gtm-children.test.js +60 -0
- package/tests/unit/src/components/Login/helpers/get-url-to-use.test.js +15 -0
- package/tests/unit/src/components/PasswordReset/PasswordReset.test.js +85 -0
- package/tests/unit/src/components/PasswordReset/__snapshots__/PasswordReset.test.js.snap +83 -0
- package/tests/unit/src/components/PasswordReset/helpers/validatePassword.test.js +21 -0
- package/tests/unit/src/components/PasswordResetRequest/PasswordResetRequest.test.js +79 -0
- package/tests/unit/src/components/PasswordResetRequest/__snapshots__/PasswordResetRequest.test.js.snap +39 -0
- package/tests/unit/src/components/__snapshots__/index.test.js.snap +12 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import Input from '@blaze-react/input';
|
|
4
|
+
import Button from '@blaze-react/button';
|
|
5
|
+
import { useMutation } from '@apollo/client';
|
|
6
|
+
import { useRouter } from 'next/router';
|
|
7
|
+
import { checkIfLoggedIn, REQUEST_USER_PASSWORD_RESET_MUTATION } from '@blaze-cms/core-auth-ui';
|
|
8
|
+
import { GRAPH_QL_ERROR } from '../../constants';
|
|
9
|
+
import { hasChildren } from '../../helpers';
|
|
10
|
+
|
|
11
|
+
const PasswordResetRequest = ({ children, modifier }) => {
|
|
12
|
+
const { id: userId } = checkIfLoggedIn();
|
|
13
|
+
const router = useRouter();
|
|
14
|
+
const { asPath } = router;
|
|
15
|
+
const [displayChildren, setShouldDisplayChildren] = useState(false);
|
|
16
|
+
const [errorMessageToDisplay, setErrorMessage] = useState(null);
|
|
17
|
+
const [email, setEmail] = useState('');
|
|
18
|
+
|
|
19
|
+
const [requestUserPasswordResetMutation] = useMutation(REQUEST_USER_PASSWORD_RESET_MUTATION, {
|
|
20
|
+
onCompleted: () => {
|
|
21
|
+
setShouldDisplayChildren(true);
|
|
22
|
+
setErrorMessage(null);
|
|
23
|
+
},
|
|
24
|
+
onError: ({ message }) => {
|
|
25
|
+
const parsedMessage = message.replace(GRAPH_QL_ERROR, '');
|
|
26
|
+
setErrorMessage(parsedMessage);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const isDisabled = !email;
|
|
31
|
+
const displayValidChildren = displayChildren && hasChildren(children);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div className={modifier}>
|
|
35
|
+
{!displayChildren && (
|
|
36
|
+
<form
|
|
37
|
+
id="passwordResetRequest"
|
|
38
|
+
onSubmit={e => {
|
|
39
|
+
e.preventDefault();
|
|
40
|
+
if (isDisabled) return;
|
|
41
|
+
requestUserPasswordResetMutation({
|
|
42
|
+
variables: { input: { email, userId, extras: { redirectUrl: asPath } } }
|
|
43
|
+
});
|
|
44
|
+
}}>
|
|
45
|
+
<Input
|
|
46
|
+
key="email"
|
|
47
|
+
type="email"
|
|
48
|
+
name="email"
|
|
49
|
+
label="Email"
|
|
50
|
+
required
|
|
51
|
+
onChange={({ event }) => {
|
|
52
|
+
const {
|
|
53
|
+
target: { value }
|
|
54
|
+
} = event;
|
|
55
|
+
setEmail(value);
|
|
56
|
+
}}
|
|
57
|
+
value={email}
|
|
58
|
+
/>
|
|
59
|
+
</form>
|
|
60
|
+
)}
|
|
61
|
+
{!displayChildren && (
|
|
62
|
+
<Button type="submit" name="button" form="passwordResetRequest" disabled={isDisabled}>
|
|
63
|
+
Request Password Reset
|
|
64
|
+
</Button>
|
|
65
|
+
)}
|
|
66
|
+
{!!errorMessageToDisplay && <div className="error_message">{errorMessageToDisplay}</div>}
|
|
67
|
+
{displayValidChildren && <div>{children}</div>}
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
PasswordResetRequest.propTypes = {
|
|
73
|
+
modifier: PropTypes.string,
|
|
74
|
+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
PasswordResetRequest.defaultProps = {
|
|
78
|
+
modifier: '',
|
|
79
|
+
children: null
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export default PasswordResetRequest;
|
package/src/components/index.js
CHANGED
|
@@ -28,13 +28,19 @@ export default {
|
|
|
28
28
|
),
|
|
29
29
|
modal: dynamic(() => import(/* webpackChunkName: "blazePbModal" */ './Modal')),
|
|
30
30
|
code: dynamic(() => import(/* webpackChunkName: "blazePbCode" */ './Code')),
|
|
31
|
+
login: dynamic(() => import(/* webpackChunkName: "blazePbLogin" */ './Login')),
|
|
31
32
|
menu: dynamic(() => import(/* webpackChunkName: "blazePbMenu" */ './Menu')),
|
|
32
33
|
menuitem: dynamic(() => import(/* webpackChunkName: "blazePbMenuItem" */ './MenuItem')),
|
|
33
34
|
submenu: dynamic(() => import(/* webpackChunkName: "blazePbSubMenu" */ './SubMenu')),
|
|
34
35
|
emailconfirm: dynamic(() =>
|
|
35
36
|
import(/* webpackChunkName: "blazePbEmailConfirm" */ './EmailConfirm')
|
|
36
37
|
),
|
|
37
|
-
|
|
38
|
+
passwordreset: dynamic(() =>
|
|
39
|
+
import(/* webpackChunkName: "blazePbPasswordReset" */ './PasswordReset')
|
|
40
|
+
),
|
|
41
|
+
passwordresetrequest: dynamic(() =>
|
|
42
|
+
import(/* webpackChunkName: "blazePbPasswordResetRequest" */ './PasswordResetRequest')
|
|
43
|
+
),
|
|
38
44
|
breadcrumb: dynamic(() => import(/* webpackChunkName: "blazePbBreadcrumb" */ './Breadcrumb')),
|
|
39
45
|
itemlistbutton: dynamic(() =>
|
|
40
46
|
import(/* webpackChunkName: "blazePbItemListButton" */ './ItemList/ItemListButton')
|
package/src/constants/index.js
CHANGED
|
@@ -35,7 +35,10 @@ const CATEGORY_ID = 'categoryId';
|
|
|
35
35
|
const PUBLISHED = 'published';
|
|
36
36
|
const ID = 'id';
|
|
37
37
|
const LINK = 'link';
|
|
38
|
+
const EMAIL = 'email';
|
|
39
|
+
const PASSWORD = 'password';
|
|
38
40
|
const LOGOUT = 'logout';
|
|
41
|
+
const LOGIN_FORM = 'loginForm';
|
|
39
42
|
const GRAPH_QL_ERROR = 'GraphQL error: ';
|
|
40
43
|
const HOVER = 'hover';
|
|
41
44
|
const MOUSE_ENTER = 'mouseenter';
|
|
@@ -127,6 +130,10 @@ const BREAKPOINT_SIZES = {
|
|
|
127
130
|
|
|
128
131
|
const MAX_BANNER_HEIGHT = 250;
|
|
129
132
|
const MIN_BANNER_HEIGHT = 90;
|
|
133
|
+
const PASSWORD_REGEX = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\s).{8,}$/;
|
|
134
|
+
const PASSWORD_VALIDATION_MESSAGE =
|
|
135
|
+
'Must contain 8 or more characters with a mix of upper & lower case letters, numbers & symbols and no spaces';
|
|
136
|
+
const PASSWORD_CONFIRM_MESSAGE = 'Passwords must match';
|
|
130
137
|
const ALLOWED_BLOCK_TYPES = ['p', 'ul', 'ol'];
|
|
131
138
|
|
|
132
139
|
const PREHEADER_PROP = 'alternativePreHeader';
|
|
@@ -280,6 +287,8 @@ export {
|
|
|
280
287
|
LOAD_MORE,
|
|
281
288
|
CLASSIC,
|
|
282
289
|
BREAKPOINT_SIZES,
|
|
290
|
+
EMAIL,
|
|
291
|
+
PASSWORD,
|
|
283
292
|
LOGOUT,
|
|
284
293
|
MIN_BANNER_HEIGHT,
|
|
285
294
|
MAX_BANNER_HEIGHT,
|
|
@@ -296,6 +305,10 @@ export {
|
|
|
296
305
|
HIDDEN,
|
|
297
306
|
MENU_ITEM,
|
|
298
307
|
SUB_MENU,
|
|
308
|
+
LOGIN_FORM,
|
|
309
|
+
PASSWORD_REGEX,
|
|
310
|
+
PASSWORD_VALIDATION_MESSAGE,
|
|
311
|
+
PASSWORD_CONFIRM_MESSAGE,
|
|
299
312
|
ELEMENT,
|
|
300
313
|
ALLOWED_BLOCK_TYPES,
|
|
301
314
|
PREHEADER_PROP,
|
package/src/index.js
CHANGED
|
@@ -11,7 +11,7 @@ export {
|
|
|
11
11
|
getSingleEntitySchema,
|
|
12
12
|
getUser
|
|
13
13
|
} from './application/query';
|
|
14
|
-
export { buildPropsQuery, getUnpublishedEntityName, renderChildren
|
|
14
|
+
export { buildPropsQuery, getUnpublishedEntityName, renderChildren } from './helpers';
|
|
15
15
|
export { withTitle } from './HOC';
|
|
16
16
|
export { useGetEntitySchema, useGetEntitySchemasAsObj, useGetSingleEntitySchema } from './hooks';
|
|
17
17
|
export { summaryComponents } from './components/DataSummary/DataSummaryTypes';
|
|
@@ -16,17 +16,8 @@ const render = async (Component, props) => {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
const CATEGORY = 'category-name';
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
{
|
|
22
|
-
htmlAttribute: 'data-testid'
|
|
23
|
-
}
|
|
24
|
-
];
|
|
25
|
-
const getMockedParsedProp = children => <>{children}</>;
|
|
26
|
-
const firstPropValue = 'some description';
|
|
27
|
-
const secondPropValue = 'extra props';
|
|
28
|
-
const firstPropToDisplay = getMockedParsedProp(['', '', firstPropValue, '', '']);
|
|
29
|
-
const secondPropToDisplay = getMockedParsedProp(['', '', secondPropValue, '', '']);
|
|
19
|
+
const firstPropToDisplay = 'some description';
|
|
20
|
+
const secondPropToDisplay = 'extra props';
|
|
30
21
|
|
|
31
22
|
const componentProps = {
|
|
32
23
|
id: 'id',
|
|
@@ -50,8 +41,7 @@ const componentProps = {
|
|
|
50
41
|
displayCategory: true,
|
|
51
42
|
displayThumbnail: true,
|
|
52
43
|
displayTitle: true,
|
|
53
|
-
propsToDisplay,
|
|
54
|
-
parsedPropsToDisplay: [firstPropToDisplay, secondPropToDisplay]
|
|
44
|
+
propsToDisplay: [firstPropToDisplay, secondPropToDisplay]
|
|
55
45
|
};
|
|
56
46
|
|
|
57
47
|
const preHeaderName = 'Pre header';
|
|
@@ -64,8 +54,7 @@ jest.mock('../../../../../src/components/LazyImage', () => ({ src, alt }) => (
|
|
|
64
54
|
|
|
65
55
|
describe('Card component', () => {
|
|
66
56
|
it('should render without throwing an error and match snapshot', async () => {
|
|
67
|
-
const { asFragment
|
|
68
|
-
expect(getByTestId(encodeURIComponent(firstPropValue))).toBeDefined();
|
|
57
|
+
const { asFragment } = await render(Card, componentProps);
|
|
69
58
|
expect(asFragment()).toMatchSnapshot();
|
|
70
59
|
});
|
|
71
60
|
|
|
@@ -170,8 +159,8 @@ describe('Card component', () => {
|
|
|
170
159
|
const { getByText } = await render(Card, componentProps);
|
|
171
160
|
|
|
172
161
|
await waitFor(() => {
|
|
173
|
-
expect(getByText(
|
|
174
|
-
expect(getByText(
|
|
162
|
+
expect(getByText(firstPropToDisplay)).toBeInTheDocument();
|
|
163
|
+
expect(getByText(secondPropToDisplay)).toBeInTheDocument();
|
|
175
164
|
});
|
|
176
165
|
});
|
|
177
166
|
|
|
@@ -181,7 +170,7 @@ describe('Card component', () => {
|
|
|
181
170
|
const { getByText } = await render(Card, { ...componentProps, ...propsToDisplayModifiers });
|
|
182
171
|
|
|
183
172
|
await waitFor(() => {
|
|
184
|
-
const span = getByText(
|
|
173
|
+
const span = getByText(firstPropToDisplay).closest('span');
|
|
185
174
|
expect(span).not.toHaveAttribute(modifier);
|
|
186
175
|
});
|
|
187
176
|
});
|
|
@@ -44,7 +44,6 @@ exports[`Card component should not render alternative headline if alternativePre
|
|
|
44
44
|
>
|
|
45
45
|
<span
|
|
46
46
|
class=""
|
|
47
|
-
data-testid="some%20description"
|
|
48
47
|
>
|
|
49
48
|
some description
|
|
50
49
|
</span>
|
|
@@ -113,7 +112,6 @@ exports[`Card component should not render alternative headline if displayCategor
|
|
|
113
112
|
>
|
|
114
113
|
<span
|
|
115
114
|
class=""
|
|
116
|
-
data-testid="some%20description"
|
|
117
115
|
>
|
|
118
116
|
some description
|
|
119
117
|
</span>
|
|
@@ -188,7 +186,6 @@ exports[`Card component should not render preHeader if alternativeHeadline is no
|
|
|
188
186
|
>
|
|
189
187
|
<span
|
|
190
188
|
class=""
|
|
191
|
-
data-testid="some%20description"
|
|
192
189
|
>
|
|
193
190
|
some description
|
|
194
191
|
</span>
|
|
@@ -262,7 +259,6 @@ exports[`Card component should render customPreheader and alternativeHeadline in
|
|
|
262
259
|
>
|
|
263
260
|
<span
|
|
264
261
|
class=""
|
|
265
|
-
data-testid="some%20description"
|
|
266
262
|
>
|
|
267
263
|
some description
|
|
268
264
|
</span>
|
|
@@ -337,7 +333,6 @@ exports[`Card component should render without throwing an error and match snapsh
|
|
|
337
333
|
>
|
|
338
334
|
<span
|
|
339
335
|
class=""
|
|
340
|
-
data-testid="some%20description"
|
|
341
336
|
>
|
|
342
337
|
some description
|
|
343
338
|
</span>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { render } from '@blaze-cms/tools/test-helpers/test-functions';
|
|
2
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
3
|
+
import Login from '../../../../../src/components/Login';
|
|
4
|
+
|
|
5
|
+
jest.mock('@blaze-cms/core-auth-ui', () => ({
|
|
6
|
+
checkIfLoggedIn: jest
|
|
7
|
+
.fn()
|
|
8
|
+
.mockImplementationOnce(() => ({ isLoggedIn: false }))
|
|
9
|
+
.mockImplementationOnce(() => ({ isLoggedIn: true }))
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
jest.mock('@apollo/client', () => ({
|
|
13
|
+
...jest.requireActual('@apollo/client'),
|
|
14
|
+
useMutation: jest.fn(() => [variables => variables, { client: { resetStore: null } }])
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
jest.mock('next/router', () => ({
|
|
18
|
+
useRouter: jest.fn().mockImplementation(() => ({
|
|
19
|
+
asPath: ''
|
|
20
|
+
}))
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
const props = {};
|
|
24
|
+
|
|
25
|
+
describe('Login component', () => {
|
|
26
|
+
it('should render without throwing an error and match snapshot', () => {
|
|
27
|
+
const { asFragment } = render(Login, props);
|
|
28
|
+
expect(asFragment()).toMatchSnapshot();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should render rederict link if logged in', () => {
|
|
32
|
+
const { asFragment, container } = render(Login, props);
|
|
33
|
+
expect(asFragment()).toMatchSnapshot();
|
|
34
|
+
expect(container.firstChild).toContainHTML('span');
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Login component should render rederict link if logged in 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<span>
|
|
6
|
+
You are already logged in please
|
|
7
|
+
<a
|
|
8
|
+
href=""
|
|
9
|
+
>
|
|
10
|
+
click here
|
|
11
|
+
</a>
|
|
12
|
+
to reload your content access
|
|
13
|
+
</span>
|
|
14
|
+
</DocumentFragment>
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
exports[`Login component should render without throwing an error and match snapshot 1`] = `
|
|
18
|
+
<DocumentFragment>
|
|
19
|
+
<form
|
|
20
|
+
class=""
|
|
21
|
+
id="loginForm"
|
|
22
|
+
>
|
|
23
|
+
<div
|
|
24
|
+
class="form-field form-field--input "
|
|
25
|
+
>
|
|
26
|
+
<label
|
|
27
|
+
class="required"
|
|
28
|
+
>
|
|
29
|
+
Email
|
|
30
|
+
</label>
|
|
31
|
+
<input
|
|
32
|
+
data-testid="input"
|
|
33
|
+
name="email"
|
|
34
|
+
placeholder="example@email.com"
|
|
35
|
+
required=""
|
|
36
|
+
type="email"
|
|
37
|
+
value=""
|
|
38
|
+
/>
|
|
39
|
+
</div>
|
|
40
|
+
<div
|
|
41
|
+
class="form-field form-field--input form-field--password"
|
|
42
|
+
>
|
|
43
|
+
<label
|
|
44
|
+
class="required"
|
|
45
|
+
>
|
|
46
|
+
Password
|
|
47
|
+
</label>
|
|
48
|
+
<input
|
|
49
|
+
data-testid="input"
|
|
50
|
+
name="password"
|
|
51
|
+
required=""
|
|
52
|
+
type="password"
|
|
53
|
+
value=""
|
|
54
|
+
/>
|
|
55
|
+
<span
|
|
56
|
+
class="show-hide-password active"
|
|
57
|
+
data-testid="toggle-input-type"
|
|
58
|
+
role="button"
|
|
59
|
+
>
|
|
60
|
+
Show
|
|
61
|
+
<i
|
|
62
|
+
class="material-icons"
|
|
63
|
+
>
|
|
64
|
+
visibility_off
|
|
65
|
+
</i>
|
|
66
|
+
</span>
|
|
67
|
+
</div>
|
|
68
|
+
<div
|
|
69
|
+
class="form-field form-field--checkbox"
|
|
70
|
+
role="button"
|
|
71
|
+
>
|
|
72
|
+
<input
|
|
73
|
+
class="form-checkbox"
|
|
74
|
+
id="remember-me-checkbox"
|
|
75
|
+
name="rememberme"
|
|
76
|
+
readonly=""
|
|
77
|
+
type="checkbox"
|
|
78
|
+
value=""
|
|
79
|
+
/>
|
|
80
|
+
<div
|
|
81
|
+
class=""
|
|
82
|
+
>
|
|
83
|
+
<label
|
|
84
|
+
for="remember-me-checkbox"
|
|
85
|
+
>
|
|
86
|
+
<span>
|
|
87
|
+
Remember Me
|
|
88
|
+
</span>
|
|
89
|
+
</label>
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
</form>
|
|
93
|
+
<button
|
|
94
|
+
class="button "
|
|
95
|
+
disabled=""
|
|
96
|
+
form="loginForm"
|
|
97
|
+
name="button"
|
|
98
|
+
type="submit"
|
|
99
|
+
>
|
|
100
|
+
Login
|
|
101
|
+
</button>
|
|
102
|
+
</DocumentFragment>
|
|
103
|
+
`;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { checkGtmChildren } from '../../../../../../src/components/Login/helpers';
|
|
2
|
+
|
|
3
|
+
const mockedChildren = [
|
|
4
|
+
{
|
|
5
|
+
props: {
|
|
6
|
+
children: [false, [{ props: { component: { settings: {} } } }]]
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
props: {
|
|
11
|
+
children: [
|
|
12
|
+
false,
|
|
13
|
+
[{ props: { component: { settings: { gtmEvents: [{ eventTrigger: 'onLoad' }] } } } }]
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
props: {
|
|
19
|
+
children: [
|
|
20
|
+
false,
|
|
21
|
+
[{ props: { component: { settings: { gtmEvents: [{ eventTrigger: 'onSuccess' }] } } } }]
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
describe('checkGtmChildrenhelper', () => {
|
|
28
|
+
const noParams = checkGtmChildren();
|
|
29
|
+
const emptyChildren = checkGtmChildren([]);
|
|
30
|
+
const childrenWithNoGtm = checkGtmChildren(mockedChildren[0]);
|
|
31
|
+
const childrenWithGtm = checkGtmChildren(mockedChildren[1]);
|
|
32
|
+
const childrenWithOnSuccessGtm = checkGtmChildren(mockedChildren[2], () => {});
|
|
33
|
+
|
|
34
|
+
it('should always return an array with 2 elements', () => {
|
|
35
|
+
expect(Array.isArray(noParams)).toEqual(true);
|
|
36
|
+
expect(noParams.length).toEqual(2);
|
|
37
|
+
expect(Array.isArray(emptyChildren)).toEqual(true);
|
|
38
|
+
expect(emptyChildren.length).toEqual(2);
|
|
39
|
+
expect(Array.isArray(childrenWithNoGtm)).toEqual(true);
|
|
40
|
+
expect(childrenWithNoGtm.length).toEqual(2);
|
|
41
|
+
expect(Array.isArray(childrenWithGtm)).toEqual(true);
|
|
42
|
+
expect(childrenWithGtm.length).toEqual(2);
|
|
43
|
+
expect(Array.isArray(childrenWithOnSuccessGtm)).toEqual(true);
|
|
44
|
+
expect(childrenWithOnSuccessGtm.length).toEqual(2);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('if no valid onSuccess children are passed the first value in the array should be false', () => {
|
|
48
|
+
expect(noParams[0]).toEqual(false);
|
|
49
|
+
expect(emptyChildren[0]).toEqual(false);
|
|
50
|
+
expect(childrenWithNoGtm[0]).toEqual(false);
|
|
51
|
+
expect(childrenWithGtm[0]).toEqual(false);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('otherwise first value should be true and children should be updated with the handleOnSuccess function', () => {
|
|
55
|
+
expect(childrenWithOnSuccessGtm[0]).toEqual(true);
|
|
56
|
+
expect(
|
|
57
|
+
childrenWithOnSuccessGtm[1].props.children[1][0].props.component.settings.gtmEvents[0]
|
|
58
|
+
).toHaveProperty('handleOnSuccess');
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getUrlToUse } from '../../../../../../src/components/Login/helpers';
|
|
2
|
+
|
|
3
|
+
describe('Get url to use helper', () => {
|
|
4
|
+
it('should return url to use based on props passed', () => {
|
|
5
|
+
const singleRedirect = getUrlToUse({ redirectUrl: 'redirect' });
|
|
6
|
+
const arrayRedirect = getUrlToUse({ redirectUrl: ['multi-redirect'] });
|
|
7
|
+
const baseUrl = getUrlToUse({ redirectUrl: 'base' });
|
|
8
|
+
const asPathUrl = getUrlToUse({ redirectUrl: 'asPath' });
|
|
9
|
+
|
|
10
|
+
expect(singleRedirect).toEqual('redirect');
|
|
11
|
+
expect(arrayRedirect).toEqual('multi-redirect');
|
|
12
|
+
expect(baseUrl).toEqual('base');
|
|
13
|
+
expect(asPathUrl).toEqual('asPath');
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { RESET_USER_PASSWORD_MUTATION } from '@blaze-cms/core-auth-ui';
|
|
4
|
+
import { fireEvent, render, queryByAttribute, waitFor } from '@testing-library/react';
|
|
5
|
+
import { MockedProvider } from '@apollo/client/testing';
|
|
6
|
+
import PasswordReset from '../../../../../src/components/PasswordReset';
|
|
7
|
+
|
|
8
|
+
jest.mock('next/router', () => ({
|
|
9
|
+
useRouter: jest.fn(() => ({ asPath: 'test-url?token=123' }))
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
const getById = queryByAttribute.bind(null, 'id');
|
|
13
|
+
const validPassword = 'NewPassword$123';
|
|
14
|
+
const mocks = [
|
|
15
|
+
{
|
|
16
|
+
request: {
|
|
17
|
+
query: RESET_USER_PASSWORD_MUTATION,
|
|
18
|
+
variables: {
|
|
19
|
+
input: { token: '123', password: validPassword }
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
result: {
|
|
23
|
+
data: {
|
|
24
|
+
resetUserPasswordResult: {
|
|
25
|
+
result: { result: true, extras: { redirectUrl: 'redirect-url' } }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const setup = () => {
|
|
33
|
+
const resetComponent = render(
|
|
34
|
+
<MockedProvider mocks={mocks}>
|
|
35
|
+
<PasswordReset>
|
|
36
|
+
<div>child</div>
|
|
37
|
+
</PasswordReset>
|
|
38
|
+
</MockedProvider>
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const passWordInput = getById(resetComponent.container, 'password');
|
|
42
|
+
const passWordConfirmInput = getById(resetComponent.container, 'passwordConfirm');
|
|
43
|
+
const button = resetComponent.getByText('Reset Password');
|
|
44
|
+
|
|
45
|
+
return { resetComponent, button, passWordInput, passWordConfirmInput };
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
describe('PasswordResetRequest component', () => {
|
|
49
|
+
it('should render without throwing an error if token is present', () => {
|
|
50
|
+
const {
|
|
51
|
+
resetComponent: { asFragment }
|
|
52
|
+
} = setup();
|
|
53
|
+
expect(asFragment()).toMatchSnapshot();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('button should be disabled if no passord or passwordConfirm is entered', () => {
|
|
57
|
+
const { button } = setup();
|
|
58
|
+
expect(button).toHaveAttribute('disabled');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('button should not be disabled if both password fields have value', () => {
|
|
62
|
+
const { passWordInput, passWordConfirmInput, button } = setup();
|
|
63
|
+
fireEvent.change(passWordInput, { target: { value: '123' } });
|
|
64
|
+
fireEvent.change(passWordConfirmInput, { target: { value: '234' } });
|
|
65
|
+
expect(button).not.toBeDisabled();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should call PasswordReset mutation and render children if password and passwordConfirm match', async () => {
|
|
69
|
+
const { passWordInput, passWordConfirmInput, button, resetComponent } = setup();
|
|
70
|
+
fireEvent.change(passWordInput, { target: { value: validPassword } });
|
|
71
|
+
fireEvent.change(passWordConfirmInput, { target: { value: validPassword } });
|
|
72
|
+
fireEvent(
|
|
73
|
+
button,
|
|
74
|
+
new MouseEvent('click', {
|
|
75
|
+
bubbles: true,
|
|
76
|
+
cancelable: true
|
|
77
|
+
})
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
await waitFor(() => {
|
|
81
|
+
const renderedChildren = resetComponent.getByText('child');
|
|
82
|
+
expect(renderedChildren).toBeDefined();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`PasswordResetRequest component should render without throwing an error if token is present 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<div
|
|
6
|
+
class=""
|
|
7
|
+
>
|
|
8
|
+
<form
|
|
9
|
+
id="passwordReset"
|
|
10
|
+
>
|
|
11
|
+
<div
|
|
12
|
+
class="form-field form-field--input form-field--password"
|
|
13
|
+
>
|
|
14
|
+
<label
|
|
15
|
+
class="required"
|
|
16
|
+
for="password"
|
|
17
|
+
>
|
|
18
|
+
Password
|
|
19
|
+
</label>
|
|
20
|
+
<input
|
|
21
|
+
data-testid="input"
|
|
22
|
+
id="password"
|
|
23
|
+
name="password"
|
|
24
|
+
required=""
|
|
25
|
+
type="password"
|
|
26
|
+
value=""
|
|
27
|
+
/>
|
|
28
|
+
<span
|
|
29
|
+
class="show-hide-password active"
|
|
30
|
+
data-testid="toggle-input-type"
|
|
31
|
+
role="button"
|
|
32
|
+
>
|
|
33
|
+
Show
|
|
34
|
+
<i
|
|
35
|
+
class="material-icons"
|
|
36
|
+
>
|
|
37
|
+
visibility_off
|
|
38
|
+
</i>
|
|
39
|
+
</span>
|
|
40
|
+
</div>
|
|
41
|
+
<div
|
|
42
|
+
class="form-field form-field--input form-field--password"
|
|
43
|
+
>
|
|
44
|
+
<label
|
|
45
|
+
class="required"
|
|
46
|
+
for="passwordConfirm"
|
|
47
|
+
>
|
|
48
|
+
Confirm New Password
|
|
49
|
+
</label>
|
|
50
|
+
<input
|
|
51
|
+
data-testid="input"
|
|
52
|
+
id="passwordConfirm"
|
|
53
|
+
name="passwordConfirm"
|
|
54
|
+
required=""
|
|
55
|
+
type="password"
|
|
56
|
+
value=""
|
|
57
|
+
/>
|
|
58
|
+
<span
|
|
59
|
+
class="show-hide-password active"
|
|
60
|
+
data-testid="toggle-input-type"
|
|
61
|
+
role="button"
|
|
62
|
+
>
|
|
63
|
+
Show
|
|
64
|
+
<i
|
|
65
|
+
class="material-icons"
|
|
66
|
+
>
|
|
67
|
+
visibility_off
|
|
68
|
+
</i>
|
|
69
|
+
</span>
|
|
70
|
+
</div>
|
|
71
|
+
</form>
|
|
72
|
+
<button
|
|
73
|
+
class="button "
|
|
74
|
+
disabled=""
|
|
75
|
+
form="passwordReset"
|
|
76
|
+
name="button"
|
|
77
|
+
type="submit"
|
|
78
|
+
>
|
|
79
|
+
Reset Password
|
|
80
|
+
</button>
|
|
81
|
+
</div>
|
|
82
|
+
</DocumentFragment>
|
|
83
|
+
`;
|