@transferwise/components 0.0.0-experimental-468b85f → 0.0.0-experimental-a9e2e05
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/build/avatarLayout/AvatarLayout.js +9 -2
- package/build/avatarLayout/AvatarLayout.js.map +1 -1
- package/build/avatarLayout/AvatarLayout.mjs +9 -2
- package/build/avatarLayout/AvatarLayout.mjs.map +1 -1
- package/build/button/Button/src/Button.js +93 -0
- package/build/button/Button/src/Button.js.map +1 -0
- package/build/button/Button/src/Button.mjs +91 -0
- package/build/button/Button/src/Button.mjs.map +1 -0
- package/build/button/{Button.js → LegacyButton/Button.js} +25 -24
- package/build/button/LegacyButton/Button.js.map +1 -0
- package/build/button/{Button.mjs → LegacyButton/Button.mjs} +25 -24
- package/build/button/LegacyButton/Button.mjs.map +1 -0
- package/build/button/LegacyButton/classMap.js +42 -0
- package/build/button/LegacyButton/classMap.js.map +1 -0
- package/build/button/LegacyButton/classMap.mjs +39 -0
- package/build/button/LegacyButton/classMap.mjs.map +1 -0
- package/build/button/{legacyUtils → LegacyButton/legacyUtils}/legacyUtils.js +21 -21
- package/build/button/LegacyButton/legacyUtils/legacyUtils.js.map +1 -0
- package/build/button/{legacyUtils → LegacyButton/legacyUtils}/legacyUtils.mjs +21 -21
- package/build/button/LegacyButton/legacyUtils/legacyUtils.mjs.map +1 -0
- package/build/button/src/Button.js +66 -0
- package/build/button/src/Button.js.map +1 -0
- package/build/button/src/Button.mjs +64 -0
- package/build/button/src/Button.mjs.map +1 -0
- package/build/circularButton/CircularButton.js +1 -1
- package/build/circularButton/CircularButton.js.map +1 -1
- package/build/circularButton/CircularButton.mjs +1 -1
- package/build/circularButton/CircularButton.mjs.map +1 -1
- package/build/common/action/Action.js +1 -1
- package/build/common/action/Action.js.map +1 -1
- package/build/common/action/Action.mjs +1 -1
- package/build/common/action/Action.mjs.map +1 -1
- package/build/criticalBanner/CriticalCommsBanner.js +1 -1
- package/build/criticalBanner/CriticalCommsBanner.mjs +1 -1
- package/build/header/Header.js +1 -1
- package/build/header/Header.mjs +1 -1
- package/build/index.js +1 -1
- package/build/index.mjs +1 -1
- package/build/link/Link.js +8 -3
- package/build/link/Link.js.map +1 -1
- package/build/link/Link.mjs +8 -3
- package/build/link/Link.mjs.map +1 -1
- package/build/main.css +288 -29
- package/build/nudge/Nudge.js +1 -1
- package/build/nudge/Nudge.js.map +1 -1
- package/build/nudge/Nudge.mjs +1 -1
- package/build/nudge/Nudge.mjs.map +1 -1
- package/build/select/Select.js +1 -1
- package/build/select/Select.mjs +1 -1
- package/build/styles/avatarLayout/AvatarLayout.css +11 -0
- package/build/styles/button/Button/less/Button.css +253 -0
- package/build/styles/button/Button/less/Button.vars.css +57 -0
- package/build/styles/iconButton/IconButton.css +24 -29
- package/build/styles/main.css +288 -29
- package/build/types/avatarLayout/AvatarLayout.d.ts +1 -2
- package/build/types/avatarLayout/AvatarLayout.d.ts.map +1 -1
- package/build/types/avatarLayout/index.d.ts +1 -0
- package/build/types/avatarLayout/index.d.ts.map +1 -1
- package/build/types/button/Button/index.d.ts +3 -0
- package/build/types/button/Button/index.d.ts.map +1 -0
- package/build/types/button/Button/src/Button.d.ts +4 -0
- package/build/types/button/Button/src/Button.d.ts.map +1 -0
- package/build/types/button/Button/src/Button.types.d.ts +50 -0
- package/build/types/button/Button/src/Button.types.d.ts.map +1 -0
- package/build/types/button/Button/src/index.d.ts +2 -0
- package/build/types/button/Button/src/index.d.ts.map +1 -0
- package/build/types/button/{Button.d.ts → LegacyButton/Button.d.ts} +8 -5
- package/build/types/button/LegacyButton/Button.d.ts.map +1 -0
- package/build/types/button/LegacyButton/classMap.d.ts.map +1 -0
- package/build/types/button/LegacyButton/index.d.ts +3 -0
- package/build/types/button/LegacyButton/index.d.ts.map +1 -0
- package/build/types/button/LegacyButton/legacyUtils/index.d.ts.map +1 -0
- package/build/types/button/{legacyUtils → LegacyButton/legacyUtils}/legacyUtils.d.ts +1 -1
- package/build/types/button/LegacyButton/legacyUtils/legacyUtils.d.ts.map +1 -0
- package/build/types/button/index.d.ts +2 -2
- package/build/types/button/index.d.ts.map +1 -1
- package/build/types/button/src/Button.d.ts +47 -0
- package/build/types/button/src/Button.d.ts.map +1 -0
- package/build/types/button/src/index.d.ts +3 -0
- package/build/types/button/src/index.d.ts.map +1 -0
- package/build/types/link/Link.d.ts +2 -2
- package/build/types/link/Link.d.ts.map +1 -1
- package/build/types/test-utils/index.d.ts.map +1 -1
- package/build/upload/steps/completeStep/completeStep.js +1 -1
- package/build/upload/steps/completeStep/completeStep.mjs +1 -1
- package/build/upload/steps/processingStep/processingStep.js +1 -1
- package/build/upload/steps/processingStep/processingStep.mjs +1 -1
- package/build/uploadInput/UploadInput.js +1 -1
- package/build/uploadInput/UploadInput.mjs +1 -1
- package/package.json +3 -3
- package/src/avatarLayout/AvatarLayout.css +11 -0
- package/src/avatarLayout/AvatarLayout.less +18 -1
- package/src/avatarLayout/AvatarLayout.tsx +11 -3
- package/src/avatarLayout/index.ts +1 -0
- package/src/avatarWrapper/AvatarWrapper.story.tsx +2 -0
- package/src/button/Button/index.ts +2 -0
- package/src/button/Button/less/Button.css +253 -0
- package/src/button/Button/less/Button.less +221 -0
- package/src/button/Button/less/Button.vars.css +57 -0
- package/src/button/Button/less/Button.vars.less +65 -0
- package/src/button/Button/src/Button.tsx +116 -0
- package/src/button/Button/src/Button.types.ts +70 -0
- package/src/button/Button/src/index.ts +1 -0
- package/src/button/Button/stories/Button.story.tsx +314 -0
- package/src/button/Button/stories/Button.tests.story.tsx +288 -0
- package/src/button/Button/test/Button.spec.tsx +328 -0
- package/src/button/{Button.less → LegacyButton/Button.less} +1 -1
- package/src/button/{Button.spec.tsx → LegacyButton/Button.spec.tsx} +3 -3
- package/src/button/LegacyButton/Button.story.tsx +224 -0
- package/src/button/{Button.tsx → LegacyButton/Button.tsx} +14 -9
- package/src/button/{classMap.ts → LegacyButton/classMap.ts} +1 -1
- package/src/button/LegacyButton/index.ts +3 -0
- package/src/button/{legacyUtils → LegacyButton/legacyUtils}/legacyUtils.spec.tsx +2 -2
- package/src/button/{legacyUtils → LegacyButton/legacyUtils}/legacyUtils.ts +2 -2
- package/src/button/index.ts +2 -3
- package/src/button/src/Button.tsx +87 -0
- package/src/button/src/index.ts +2 -0
- package/src/button/test/Button.spec.tsx +32 -0
- package/src/circularButton/CircularButton.tsx +1 -1
- package/src/common/action/Action.tsx +1 -1
- package/src/iconButton/IconButton.css +24 -29
- package/src/iconButton/IconButton.less +4 -4
- package/src/link/Link.tsx +15 -6
- package/src/main.css +288 -29
- package/src/main.less +2 -1
- package/src/nudge/Nudge.tsx +1 -1
- package/src/phoneNumberInput/PhoneNumberInput.rtl.spec.tsx +32 -0
- package/src/phoneNumberInput/PhoneNumberInput.spec.js +356 -0
- package/src/primitives/PrimitiveAnchor/stories/PrimitiveAnchor.story.tsx +1 -1
- package/src/primitives/PrimitiveAnchor/test/PrimitiveAnchor.spec.tsx +1 -1
- package/src/primitives/PrimitiveButton/stories/PrimitiveButton.story.tsx +1 -1
- package/src/primitives/PrimitiveButton/test/PrimitiveButton.spec.tsx +2 -3
- package/src/test-utils/index.tsx +0 -1
- package/build/button/Button.js.map +0 -1
- package/build/button/Button.mjs.map +0 -1
- package/build/button/classMap.js +0 -42
- package/build/button/classMap.js.map +0 -1
- package/build/button/classMap.mjs +0 -39
- package/build/button/classMap.mjs.map +0 -1
- package/build/button/legacyUtils/legacyUtils.js.map +0 -1
- package/build/button/legacyUtils/legacyUtils.mjs.map +0 -1
- package/build/types/button/Button.d.ts.map +0 -1
- package/build/types/button/classMap.d.ts.map +0 -1
- package/build/types/button/legacyUtils/index.d.ts.map +0 -1
- package/build/types/button/legacyUtils/legacyUtils.d.ts.map +0 -1
- package/src/button/Button.story.tsx +0 -163
- package/src/phoneNumberInput/PhoneNumberInput.spec.tsx +0 -300
- /package/build/styles/button/{Button.css → LegacyButton/Button.css} +0 -0
- /package/build/types/button/{classMap.d.ts → LegacyButton/classMap.d.ts} +0 -0
- /package/build/types/button/{legacyUtils → LegacyButton/legacyUtils}/index.d.ts +0 -0
- /package/src/button/{Button.css → LegacyButton/Button.css} +0 -0
- /package/src/button/{__snapshots__ → LegacyButton/__snapshots__}/Button.spec.tsx.snap +0 -0
- /package/src/button/{legacyUtils → LegacyButton/legacyUtils}/index.ts +0 -0
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { userEvent, within, fn } from '@storybook/test';
|
|
3
|
-
|
|
4
|
-
import { ControlType, Priority } from '../common';
|
|
5
|
-
import { storyConfig } from '../test-utils';
|
|
6
|
-
|
|
7
|
-
import Button from './Button';
|
|
8
|
-
|
|
9
|
-
export default {
|
|
10
|
-
component: Button,
|
|
11
|
-
title: 'Actions/Button',
|
|
12
|
-
args: {
|
|
13
|
-
children: 'Button text',
|
|
14
|
-
loading: false,
|
|
15
|
-
onClick: fn(),
|
|
16
|
-
onBlur: fn(),
|
|
17
|
-
onFocus: fn(),
|
|
18
|
-
},
|
|
19
|
-
argTypes: {
|
|
20
|
-
as: {
|
|
21
|
-
type: {
|
|
22
|
-
name: 'enum',
|
|
23
|
-
value: ['button', 'a'],
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
tags: ['autodocs'],
|
|
28
|
-
} satisfies Meta<typeof Button>;
|
|
29
|
-
|
|
30
|
-
type Story = StoryObj<typeof Button>;
|
|
31
|
-
|
|
32
|
-
export const Basic: Story = {};
|
|
33
|
-
|
|
34
|
-
export const Focused = storyConfig<Story>(
|
|
35
|
-
{
|
|
36
|
-
parameters: {
|
|
37
|
-
chromatic: {
|
|
38
|
-
delay: 1000,
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
play: async ({ canvasElement }) => {
|
|
42
|
-
const canvas = within(canvasElement);
|
|
43
|
-
await userEvent.click(canvas.getByRole('button'));
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
variants: ['dark'],
|
|
48
|
-
},
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
export const Variants = storyConfig<Story>(
|
|
52
|
-
{
|
|
53
|
-
render: (args) => {
|
|
54
|
-
return (
|
|
55
|
-
<>
|
|
56
|
-
<div className="m-b-2">
|
|
57
|
-
<div className="title-4 m-b-1">Accent</div>
|
|
58
|
-
<div className="d-flex flex-wrap" style={{ gap: 'var(--size-16)' }}>
|
|
59
|
-
<Button {...args} priority={Priority.PRIMARY} type={ControlType.ACCENT} />
|
|
60
|
-
<Button {...args} priority={Priority.SECONDARY} type={ControlType.ACCENT} />
|
|
61
|
-
<Button {...args} priority={Priority.TERTIARY} type={ControlType.ACCENT} />
|
|
62
|
-
</div>
|
|
63
|
-
</div>
|
|
64
|
-
<div className="m-b-2">
|
|
65
|
-
<div className="title-4 m-b-1">Positive</div>
|
|
66
|
-
<div className="d-flex flex-wrap" style={{ gap: 'var(--size-16)' }}>
|
|
67
|
-
<Button {...args} priority={Priority.PRIMARY} type={ControlType.POSITIVE} />
|
|
68
|
-
<Button {...args} priority={Priority.SECONDARY} type={ControlType.POSITIVE} />
|
|
69
|
-
</div>
|
|
70
|
-
</div>
|
|
71
|
-
<div className="m-b-2">
|
|
72
|
-
<div className="title-4 m-b-1">Negative</div>
|
|
73
|
-
<div className="d-flex flex-wrap" style={{ gap: 'var(--size-16)' }}>
|
|
74
|
-
<Button {...args} priority={Priority.PRIMARY} type={ControlType.NEGATIVE} />
|
|
75
|
-
<Button {...args} priority={Priority.SECONDARY} type={ControlType.NEGATIVE} />
|
|
76
|
-
</div>
|
|
77
|
-
</div>
|
|
78
|
-
<div className="m-b-2">
|
|
79
|
-
<div className="title-4 m-b-1">Disabled</div>
|
|
80
|
-
<div className="d-flex flex-wrap" style={{ gap: 'var(--size-16)' }}>
|
|
81
|
-
<Button {...args} priority={Priority.PRIMARY} disabled />
|
|
82
|
-
<Button {...args} priority={Priority.SECONDARY} disabled />
|
|
83
|
-
<Button {...args} priority={Priority.TERTIARY} disabled />
|
|
84
|
-
</div>
|
|
85
|
-
</div>
|
|
86
|
-
</>
|
|
87
|
-
);
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
{ variants: ['default', 'dark', 'rtl'] },
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* The purpose of the `loading` mode is to convey a message to the
|
|
95
|
-
* user that some asynchronous process has been triggered, likely
|
|
96
|
-
* in response to their previous action.
|
|
97
|
-
*
|
|
98
|
-
* Although it carries some similarities with the `disabled` mode
|
|
99
|
-
* (users cannot activate a loading button), it's not hidden from
|
|
100
|
-
* the keyboard and assistive tech users (users can focus on it,
|
|
101
|
-
* and it's announced by screen readers), and is also much more
|
|
102
|
-
* accessible to sighted users due to its default, high contrast.
|
|
103
|
-
*/
|
|
104
|
-
export const Loading = storyConfig<Story>(
|
|
105
|
-
{
|
|
106
|
-
render: (args) => {
|
|
107
|
-
return (
|
|
108
|
-
<div className="d-flex flex-wrap" style={{ gap: 'var(--size-16)' }}>
|
|
109
|
-
<Button {...args} loading priority={Priority.PRIMARY} />
|
|
110
|
-
<Button {...args} loading priority={Priority.SECONDARY} />
|
|
111
|
-
<Button {...args} loading priority={Priority.TERTIARY} />
|
|
112
|
-
<Button {...args} loading priority={Priority.PRIMARY} type={ControlType.NEGATIVE} />
|
|
113
|
-
<Button {...args} loading priority={Priority.SECONDARY} type={ControlType.NEGATIVE} />
|
|
114
|
-
</div>
|
|
115
|
-
);
|
|
116
|
-
},
|
|
117
|
-
args: {
|
|
118
|
-
loading: true,
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
{ variants: ['default', 'dark', 'rtl'] },
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
export const SocialMedia = storyConfig<Story>(
|
|
125
|
-
{
|
|
126
|
-
render: () => {
|
|
127
|
-
return (
|
|
128
|
-
<>
|
|
129
|
-
<div className="m-b-2">
|
|
130
|
-
<button type="button" className="btn btn-google">
|
|
131
|
-
Login with Google
|
|
132
|
-
</button>
|
|
133
|
-
</div>
|
|
134
|
-
<div className="m-b-2">
|
|
135
|
-
<button type="button" className="btn btn-facebook">
|
|
136
|
-
Login with Facebook
|
|
137
|
-
</button>
|
|
138
|
-
</div>
|
|
139
|
-
<div className="m-b-2">
|
|
140
|
-
<button type="button" className="btn btn-lg btn-facebook">
|
|
141
|
-
Large Button
|
|
142
|
-
</button>
|
|
143
|
-
</div>
|
|
144
|
-
<div className="m-b-2">
|
|
145
|
-
<button type="button" className="btn btn-block btn-facebook">
|
|
146
|
-
Block Button
|
|
147
|
-
</button>
|
|
148
|
-
</div>
|
|
149
|
-
<div className="m-b-2">
|
|
150
|
-
<button type="button" className="btn btn-lg btn-block btn-facebook">
|
|
151
|
-
Large Block Button
|
|
152
|
-
</button>
|
|
153
|
-
</div>
|
|
154
|
-
</>
|
|
155
|
-
);
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
{ variants: ['default', 'dark', 'rtl'] },
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
export const SocialMediaMobile = storyConfig<Story>(SocialMedia, {
|
|
162
|
-
variants: ['default', 'dark', 'rtl', 'mobile'],
|
|
163
|
-
});
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
import { Field } from '../field/Field';
|
|
2
|
-
import {
|
|
3
|
-
mockMatchMedia,
|
|
4
|
-
mockResizeObserver,
|
|
5
|
-
render,
|
|
6
|
-
screen,
|
|
7
|
-
within,
|
|
8
|
-
userEvent,
|
|
9
|
-
} from '../test-utils';
|
|
10
|
-
|
|
11
|
-
import PhoneNumberInput, { PhoneNumberInputProps } from './PhoneNumberInput';
|
|
12
|
-
import { useIntl } from 'react-intl';
|
|
13
|
-
|
|
14
|
-
const formatMessage = (message: { id?: string }) => String(message.id);
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
16
|
-
jest.mock('react-intl', () => ({
|
|
17
|
-
...jest.requireActual('react-intl'),
|
|
18
|
-
useIntl: jest.fn(() => ({ formatMessage, locale: 'en-GB' })),
|
|
19
|
-
}));
|
|
20
|
-
const mockUseIntl = useIntl as jest.Mock;
|
|
21
|
-
|
|
22
|
-
mockMatchMedia();
|
|
23
|
-
mockResizeObserver();
|
|
24
|
-
|
|
25
|
-
describe('PhoneNumberInput', () => {
|
|
26
|
-
afterEach(jest.clearAllMocks);
|
|
27
|
-
|
|
28
|
-
const props = { onChange: jest.fn() };
|
|
29
|
-
|
|
30
|
-
const customRender = (overrides: Partial<PhoneNumberInputProps> = {}) =>
|
|
31
|
-
render(<PhoneNumberInput {...props} {...overrides} />);
|
|
32
|
-
|
|
33
|
-
const getPrefixEl = () => screen.getByRole('combobox');
|
|
34
|
-
const getInputEl = () => screen.getByRole('textbox');
|
|
35
|
-
|
|
36
|
-
describe('defaults', () => {
|
|
37
|
-
it('should set prefix control to default UK value', () => {
|
|
38
|
-
customRender();
|
|
39
|
-
expect(getPrefixEl()).toHaveTextContent('+44');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should set number control to empty', () => {
|
|
43
|
-
customRender();
|
|
44
|
-
expect(getInputEl()).toHaveValue('');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should not disable the select', () => {
|
|
48
|
-
customRender();
|
|
49
|
-
expect(getPrefixEl()).toBeEnabled();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should not disable the input', () => {
|
|
53
|
-
customRender();
|
|
54
|
-
expect(getInputEl()).toBeEnabled();
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should propagate `initialValue`', () => {
|
|
59
|
-
const prefix = '+39';
|
|
60
|
-
const number = '123456789';
|
|
61
|
-
customRender({ initialValue: `${prefix}${number}` });
|
|
62
|
-
expect(getPrefixEl()).toHaveTextContent(prefix);
|
|
63
|
-
expect(getInputEl()).toHaveValue(number);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('id prop', () => {
|
|
67
|
-
it('should not render id by default', () => {
|
|
68
|
-
customRender();
|
|
69
|
-
expect(getPrefixEl()).not.toHaveAttribute('id');
|
|
70
|
-
expect(getInputEl()).not.toHaveAttribute('id');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should respect `id` for the input and ignore the select', () => {
|
|
74
|
-
const id = 'component-id';
|
|
75
|
-
customRender({ id });
|
|
76
|
-
expect(getPrefixEl()).not.toHaveAttribute('id');
|
|
77
|
-
expect(getInputEl()).toHaveAttribute('id', id);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('pasting', () => {
|
|
82
|
-
const initialPrefix = '+48';
|
|
83
|
-
const initialNumber = '987654321';
|
|
84
|
-
|
|
85
|
-
const renderAndPaste = async (value: string) => {
|
|
86
|
-
customRender({ initialValue: `${initialPrefix}${initialNumber}` });
|
|
87
|
-
await userEvent.tab();
|
|
88
|
-
await userEvent.tab();
|
|
89
|
-
await userEvent.paste(value);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
[
|
|
93
|
-
{ number: '+36303932551', countryCode: '+36', localNumber: '303932551' },
|
|
94
|
-
{ number: '+39123456781', countryCode: '+39', localNumber: '123456781' },
|
|
95
|
-
{ number: '+44 7700 900415', countryCode: '+44', localNumber: '7700900415' },
|
|
96
|
-
{ number: '+2975557308515', countryCode: '+297', localNumber: '5557308515' },
|
|
97
|
-
{ number: '+297-555-7217-360', countryCode: '+297', localNumber: '5557217360' },
|
|
98
|
-
{ number: '+213-555-5160-67', countryCode: '+213', localNumber: '555516067' },
|
|
99
|
-
{ number: '+246-387-5553', countryCode: '+246', localNumber: '3875553' },
|
|
100
|
-
{ number: '+852-940-5558--6', countryCode: '+852', localNumber: '94055586' },
|
|
101
|
-
{ number: '+228 253 5558 4', countryCode: '+228', localNumber: '25355584' },
|
|
102
|
-
].forEach(({ number, countryCode, localNumber }) => {
|
|
103
|
-
it(`'${number}' number should update the value properly`, async () => {
|
|
104
|
-
await renderAndPaste(number);
|
|
105
|
-
|
|
106
|
-
expect(getPrefixEl()).toHaveTextContent(countryCode);
|
|
107
|
-
expect(getInputEl()).toHaveValue(localNumber);
|
|
108
|
-
expect(props.onChange).toHaveBeenCalledWith(number.replace(/[\s-]+/g, ''), countryCode);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('should not paste invalid characters', async () => {
|
|
113
|
-
await renderAndPaste('+36asdasdasd');
|
|
114
|
-
expect(getPrefixEl()).toHaveTextContent(initialPrefix);
|
|
115
|
-
expect(getInputEl()).toHaveValue(initialNumber);
|
|
116
|
-
expect(props.onChange).not.toHaveBeenCalled();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('should not paste countries which are not in the select', async () => {
|
|
120
|
-
await renderAndPaste('+9992342343423');
|
|
121
|
-
expect(getPrefixEl()).toHaveTextContent(initialPrefix);
|
|
122
|
-
expect(getInputEl()).toHaveValue(initialNumber);
|
|
123
|
-
expect(props.onChange).not.toHaveBeenCalled();
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("should not paste numbers which doesn't start with the country code", async () => {
|
|
127
|
-
await renderAndPaste('0+36303932551');
|
|
128
|
-
expect(getPrefixEl()).toHaveTextContent(initialPrefix);
|
|
129
|
-
expect(getInputEl()).toHaveValue(initialNumber);
|
|
130
|
-
expect(props.onChange).not.toHaveBeenCalled();
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("should allow pasting numbers which don't contain a country code", async () => {
|
|
134
|
-
const newNumber = '06303932551';
|
|
135
|
-
await renderAndPaste(newNumber);
|
|
136
|
-
expect(getPrefixEl()).toHaveTextContent(initialPrefix);
|
|
137
|
-
expect(getInputEl()).toHaveValue(newNumber);
|
|
138
|
-
expect(props.onChange).toHaveBeenCalledWith(`${initialPrefix}${newNumber}`, initialPrefix);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
describe('initialValue', () => {
|
|
143
|
-
describe('when a model is supplied that could match more than one prefix', () => {
|
|
144
|
-
const initialProps = { initialValue: '+1868123456789' };
|
|
145
|
-
|
|
146
|
-
it('should set the select to the longest matching prefix', () => {
|
|
147
|
-
customRender(initialProps);
|
|
148
|
-
expect(getPrefixEl()).toHaveTextContent('+1868');
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('should set the number input to the rest of the number', () => {
|
|
152
|
-
customRender(initialProps);
|
|
153
|
-
expect(getInputEl()).toHaveValue('123456789');
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
describe('when a model is supplied with no matching prefix', () => {
|
|
158
|
-
const initialProps = { initialValue: '+999123456789' };
|
|
159
|
-
|
|
160
|
-
it('should empty the select', () => {
|
|
161
|
-
customRender(initialProps);
|
|
162
|
-
expect(getPrefixEl()).toHaveTextContent('neptune.PhoneNumberInput.SelectInput.placeholder');
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('should put the whole value in the input without the plus', () => {
|
|
166
|
-
customRender(initialProps);
|
|
167
|
-
expect(getInputEl()).toHaveValue('999123456789');
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
describe('when an invalid model is supplied', () => {
|
|
172
|
-
it('should not re-explode model', () => {
|
|
173
|
-
customRender({ initialValue: '+123' });
|
|
174
|
-
expect(getPrefixEl()).toHaveTextContent('+44');
|
|
175
|
-
expect(getInputEl()).toHaveValue('');
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
describe('when disabled is true', () => {
|
|
181
|
-
it('should disable both controls', () => {
|
|
182
|
-
customRender({ disabled: true });
|
|
183
|
-
expect(getPrefixEl()).toBeDisabled();
|
|
184
|
-
expect(getInputEl()).toBeDisabled();
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
describe('placeholders', () => {
|
|
189
|
-
it('should use the provided placeholder', () => {
|
|
190
|
-
const placeholder = 'custom placeholder';
|
|
191
|
-
customRender({ placeholder });
|
|
192
|
-
expect(getInputEl()).toHaveAttribute('placeholder', placeholder);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it('should use the provided searchPlaceholder', async () => {
|
|
196
|
-
const searchPlaceholder = 'search placeholder';
|
|
197
|
-
customRender({ searchPlaceholder });
|
|
198
|
-
await userEvent.click(getPrefixEl());
|
|
199
|
-
expect(screen.getByRole('combobox', { name: searchPlaceholder })).toBeInTheDocument();
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
describe('when supplied with a locale', () => {
|
|
204
|
-
beforeEach(() => {
|
|
205
|
-
mockUseIntl.mockReturnValue({ locale: 'es-ES', formatMessage });
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
afterEach(() => {
|
|
209
|
-
mockUseIntl.mockReturnValue({ locale: 'en-GB', formatMessage });
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
describe('and a value', () => {
|
|
213
|
-
it('should use the prefix of the supplied value', () => {
|
|
214
|
-
customRender({ initialValue: '+12345678' });
|
|
215
|
-
expect(getPrefixEl()).toHaveTextContent('+1');
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
describe('and no value', () => {
|
|
220
|
-
describe('and no country code', () => {
|
|
221
|
-
it('should default the prefix to the local country', () => {
|
|
222
|
-
customRender();
|
|
223
|
-
expect(getPrefixEl()).toHaveTextContent('+34');
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
describe('and country code', () => {
|
|
228
|
-
it('should override locale prefix with country specific prefix', () => {
|
|
229
|
-
customRender({ countryCode: 'US' });
|
|
230
|
-
expect(getPrefixEl()).toHaveTextContent('+1');
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
describe('user input', () => {
|
|
237
|
-
describe('valid number', () => {
|
|
238
|
-
it('should trigger onChange handler', async () => {
|
|
239
|
-
customRender();
|
|
240
|
-
await userEvent.type(getInputEl(), '123');
|
|
241
|
-
expect(props.onChange).toHaveBeenCalledWith('+44123', '+44');
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
describe('invalid number', () => {
|
|
246
|
-
it('should trigger onChange with null value', async () => {
|
|
247
|
-
customRender({ initialValue: '+1234' });
|
|
248
|
-
await userEvent.type(getInputEl(), '{Backspace}{Backspace}{Backspace}1');
|
|
249
|
-
expect(props.onChange).toHaveBeenCalledWith(null, '+1');
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
describe('when user insert invalid character', () => {
|
|
254
|
-
it('should strip them', async () => {
|
|
255
|
-
customRender({ initialValue: '+12345678' });
|
|
256
|
-
await userEvent.type(getInputEl(), '123--');
|
|
257
|
-
expect(props.onChange).toHaveBeenCalledWith('+12345678123', '+1');
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
describe('overlapping prefix and suffix numbers', () => {
|
|
262
|
-
it("shouldn't change the prefix number on matching suffix input", async () => {
|
|
263
|
-
customRender({ countryCode: 'eg' });
|
|
264
|
-
await userEvent.type(getInputEl(), '1111111');
|
|
265
|
-
expect(getInputEl()).toHaveValue('1111111');
|
|
266
|
-
expect(props.onChange).toHaveBeenCalledWith('+201111111', '+20');
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
describe('when selectProps is supplied', () => {
|
|
272
|
-
it('renders Select component with expected props', () => {
|
|
273
|
-
customRender({ selectProps: { className: 'custom-class' } });
|
|
274
|
-
expect(getPrefixEl().parentElement).toHaveClass('custom-class');
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it('supports custom `aria-labelledby` attribute', () => {
|
|
279
|
-
render(
|
|
280
|
-
<>
|
|
281
|
-
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
|
|
282
|
-
<label id="prioritized-label">Prioritized label</label>
|
|
283
|
-
<PhoneNumberInput aria-labelledby="prioritized-label" onChange={() => {}} />
|
|
284
|
-
</>,
|
|
285
|
-
);
|
|
286
|
-
|
|
287
|
-
expect(
|
|
288
|
-
within(screen.getByLabelText('Prioritized label')).getByRole('textbox'),
|
|
289
|
-
).toBeInTheDocument();
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
it('supports `Field` for labeling', () => {
|
|
293
|
-
render(
|
|
294
|
-
<Field label="Phone number">
|
|
295
|
-
<PhoneNumberInput initialValue="+12345678" onChange={() => {}} />
|
|
296
|
-
</Field>,
|
|
297
|
-
);
|
|
298
|
-
expect(screen.getAllByRole('group')[0]).toHaveAccessibleName(/^Phone number/);
|
|
299
|
-
});
|
|
300
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|