@transferwise/components 0.0.0-experimental-a9e2e05 → 0.0.0-experimental-e92f7ac
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 +2 -9
- package/build/avatarLayout/AvatarLayout.js.map +1 -1
- package/build/avatarLayout/AvatarLayout.mjs +2 -9
- package/build/avatarLayout/AvatarLayout.mjs.map +1 -1
- package/build/button/{LegacyButton/Button.js → Button.js} +24 -25
- package/build/button/Button.js.map +1 -0
- package/build/button/{LegacyButton/Button.mjs → Button.mjs} +24 -25
- package/build/button/Button.mjs.map +1 -0
- package/build/button/classMap.js +42 -0
- package/build/button/classMap.js.map +1 -0
- package/build/button/classMap.mjs +39 -0
- package/build/button/classMap.mjs.map +1 -0
- package/build/button/{LegacyButton/legacyUtils → legacyUtils}/legacyUtils.js +21 -21
- package/build/button/legacyUtils/legacyUtils.js.map +1 -0
- package/build/button/{LegacyButton/legacyUtils → legacyUtils}/legacyUtils.mjs +21 -21
- package/build/button/legacyUtils/legacyUtils.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 +3 -8
- package/build/link/Link.js.map +1 -1
- package/build/link/Link.mjs +3 -8
- package/build/link/Link.mjs.map +1 -1
- package/build/main.css +29 -288
- 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 +0 -11
- package/build/styles/iconButton/IconButton.css +29 -24
- package/build/styles/main.css +29 -288
- package/build/types/avatarLayout/AvatarLayout.d.ts +2 -1
- package/build/types/avatarLayout/AvatarLayout.d.ts.map +1 -1
- package/build/types/avatarLayout/index.d.ts +0 -1
- package/build/types/avatarLayout/index.d.ts.map +1 -1
- package/build/types/button/{LegacyButton/Button.d.ts → Button.d.ts} +5 -8
- package/build/types/button/Button.d.ts.map +1 -0
- package/build/types/button/classMap.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/legacyUtils/index.d.ts.map +1 -0
- package/build/types/button/{LegacyButton/legacyUtils → legacyUtils}/legacyUtils.d.ts +1 -1
- package/build/types/button/legacyUtils/legacyUtils.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 +0 -11
- package/src/avatarLayout/AvatarLayout.less +1 -18
- package/src/avatarLayout/AvatarLayout.tsx +3 -11
- package/src/avatarLayout/index.ts +0 -1
- package/src/avatarWrapper/AvatarWrapper.story.tsx +0 -2
- package/src/button/{LegacyButton/Button.less → Button.less} +1 -1
- package/src/button/{LegacyButton/Button.spec.tsx → Button.spec.tsx} +3 -3
- package/src/button/Button.story.tsx +163 -0
- package/src/button/{LegacyButton/Button.tsx → Button.tsx} +9 -14
- package/src/button/{LegacyButton/classMap.ts → classMap.ts} +1 -1
- package/src/button/index.ts +3 -2
- package/src/button/{LegacyButton/legacyUtils → legacyUtils}/legacyUtils.spec.tsx +2 -2
- package/src/button/{LegacyButton/legacyUtils → legacyUtils}/legacyUtils.ts +2 -2
- package/src/circularButton/CircularButton.tsx +1 -1
- package/src/common/action/Action.tsx +1 -1
- package/src/iconButton/IconButton.css +29 -24
- package/src/iconButton/IconButton.less +4 -4
- package/src/link/Link.tsx +6 -15
- package/src/main.css +29 -288
- package/src/main.less +1 -2
- package/src/nudge/Nudge.tsx +1 -1
- package/src/phoneNumberInput/PhoneNumberInput.spec.tsx +283 -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 +3 -2
- package/src/test-utils/index.tsx +1 -0
- package/build/button/Button/src/Button.js +0 -93
- package/build/button/Button/src/Button.js.map +0 -1
- package/build/button/Button/src/Button.mjs +0 -91
- package/build/button/Button/src/Button.mjs.map +0 -1
- package/build/button/LegacyButton/Button.js.map +0 -1
- package/build/button/LegacyButton/Button.mjs.map +0 -1
- package/build/button/LegacyButton/classMap.js +0 -42
- package/build/button/LegacyButton/classMap.js.map +0 -1
- package/build/button/LegacyButton/classMap.mjs +0 -39
- package/build/button/LegacyButton/classMap.mjs.map +0 -1
- package/build/button/LegacyButton/legacyUtils/legacyUtils.js.map +0 -1
- package/build/button/LegacyButton/legacyUtils/legacyUtils.mjs.map +0 -1
- package/build/button/src/Button.js +0 -66
- package/build/button/src/Button.js.map +0 -1
- package/build/button/src/Button.mjs +0 -64
- package/build/button/src/Button.mjs.map +0 -1
- package/build/styles/button/Button/less/Button.css +0 -253
- package/build/styles/button/Button/less/Button.vars.css +0 -57
- package/build/types/button/Button/index.d.ts +0 -3
- package/build/types/button/Button/index.d.ts.map +0 -1
- package/build/types/button/Button/src/Button.d.ts +0 -4
- package/build/types/button/Button/src/Button.d.ts.map +0 -1
- package/build/types/button/Button/src/Button.types.d.ts +0 -50
- package/build/types/button/Button/src/Button.types.d.ts.map +0 -1
- package/build/types/button/Button/src/index.d.ts +0 -2
- package/build/types/button/Button/src/index.d.ts.map +0 -1
- package/build/types/button/LegacyButton/Button.d.ts.map +0 -1
- package/build/types/button/LegacyButton/classMap.d.ts.map +0 -1
- package/build/types/button/LegacyButton/index.d.ts +0 -3
- package/build/types/button/LegacyButton/index.d.ts.map +0 -1
- package/build/types/button/LegacyButton/legacyUtils/index.d.ts.map +0 -1
- package/build/types/button/LegacyButton/legacyUtils/legacyUtils.d.ts.map +0 -1
- package/build/types/button/src/Button.d.ts +0 -47
- package/build/types/button/src/Button.d.ts.map +0 -1
- package/build/types/button/src/index.d.ts +0 -3
- package/build/types/button/src/index.d.ts.map +0 -1
- package/src/button/Button/index.ts +0 -2
- package/src/button/Button/less/Button.css +0 -253
- package/src/button/Button/less/Button.less +0 -221
- package/src/button/Button/less/Button.vars.css +0 -57
- package/src/button/Button/less/Button.vars.less +0 -65
- package/src/button/Button/src/Button.tsx +0 -116
- package/src/button/Button/src/Button.types.ts +0 -70
- package/src/button/Button/src/index.ts +0 -1
- package/src/button/Button/stories/Button.story.tsx +0 -314
- package/src/button/Button/stories/Button.tests.story.tsx +0 -288
- package/src/button/Button/test/Button.spec.tsx +0 -328
- package/src/button/LegacyButton/Button.story.tsx +0 -224
- package/src/button/LegacyButton/index.ts +0 -3
- package/src/button/src/Button.tsx +0 -87
- package/src/button/src/index.ts +0 -2
- package/src/button/test/Button.spec.tsx +0 -32
- package/src/phoneNumberInput/PhoneNumberInput.rtl.spec.tsx +0 -32
- package/src/phoneNumberInput/PhoneNumberInput.spec.js +0 -356
- /package/build/styles/button/{LegacyButton/Button.css → Button.css} +0 -0
- /package/build/types/button/{LegacyButton/classMap.d.ts → classMap.d.ts} +0 -0
- /package/build/types/button/{LegacyButton/legacyUtils → legacyUtils}/index.d.ts +0 -0
- /package/src/button/{LegacyButton/Button.css → Button.css} +0 -0
- /package/src/button/{LegacyButton/__snapshots__ → __snapshots__}/Button.spec.tsx.snap +0 -0
- /package/src/button/{LegacyButton/legacyUtils → legacyUtils}/index.ts +0 -0
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
2
|
-
import { userEvent, within, expect, waitFor } from '@storybook/test';
|
|
3
|
-
import { Meta, StoryObj } from '@storybook/react';
|
|
4
|
-
import Button from '../../src';
|
|
5
|
-
import { Freeze } from '@transferwise/icons';
|
|
6
|
-
|
|
7
|
-
const meta = {
|
|
8
|
-
title: 'Actions/Button/Tests',
|
|
9
|
-
component: Button,
|
|
10
|
-
args: {
|
|
11
|
-
children: 'Button text',
|
|
12
|
-
as: 'button',
|
|
13
|
-
},
|
|
14
|
-
} satisfies Meta<typeof Button>;
|
|
15
|
-
|
|
16
|
-
export default meta;
|
|
17
|
-
|
|
18
|
-
type Story = StoryObj<typeof meta>;
|
|
19
|
-
|
|
20
|
-
const wait = async (duration = 500) =>
|
|
21
|
-
new Promise<void>((resolve) => {
|
|
22
|
-
setTimeout(resolve, duration);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
export const ClickInteraction: Story = {
|
|
26
|
-
play: async ({ canvasElement, step }) => {
|
|
27
|
-
const canvas = within(canvasElement);
|
|
28
|
-
const button = canvas.getByRole('button');
|
|
29
|
-
|
|
30
|
-
await step('Click the button', async () => {
|
|
31
|
-
await userEvent.click(button);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
await step('Check if button text changes to "Clicked!"', async () => {
|
|
35
|
-
await waitFor(async () => expect(button).toHaveTextContent('Clicked!'));
|
|
36
|
-
});
|
|
37
|
-
},
|
|
38
|
-
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
39
|
-
const [clicked, setClicked] = useState(false);
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<Button {...args} onClick={() => setClicked(true)}>
|
|
43
|
-
{clicked ? 'Clicked!' : 'Button text'}
|
|
44
|
-
</Button>
|
|
45
|
-
);
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const FocusInteraction: Story = {
|
|
50
|
-
play: async ({ canvasElement, step }) => {
|
|
51
|
-
const canvas = within(canvasElement);
|
|
52
|
-
const button = canvas.getByRole('button');
|
|
53
|
-
|
|
54
|
-
await step('Tab to the button', async () => {
|
|
55
|
-
await userEvent.tab();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
await step('Check if button has focus and text changes to "Focused!"', async () => {
|
|
59
|
-
await waitFor(async () => expect(button).toHaveFocus());
|
|
60
|
-
await waitFor(async () => expect(button).toHaveTextContent('Focused!'));
|
|
61
|
-
});
|
|
62
|
-
},
|
|
63
|
-
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
64
|
-
const [focused, setFocused] = useState(false);
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<Button {...args} onFocus={() => setFocused(true)}>
|
|
68
|
-
{focused ? 'Focused!' : 'Button text'}
|
|
69
|
-
</Button>
|
|
70
|
-
);
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export const BlurInteraction: Story = {
|
|
75
|
-
play: async ({ canvasElement, step }) => {
|
|
76
|
-
const canvas = within(canvasElement);
|
|
77
|
-
const button = canvas.getByRole('button');
|
|
78
|
-
|
|
79
|
-
await step('Tab to the button', async () => {
|
|
80
|
-
await userEvent.tab();
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
await step('Check if button has focus', async () => {
|
|
84
|
-
await waitFor(async () => expect(button).toHaveFocus());
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
await step('Tab away from the button', async () => {
|
|
88
|
-
await userEvent.tab();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
await step('Check if button loses focus and text changes to "Blurred!"', async () => {
|
|
92
|
-
await waitFor(async () => expect(button).not.toHaveFocus());
|
|
93
|
-
await waitFor(async () => expect(button).toHaveTextContent('Blurred!'));
|
|
94
|
-
});
|
|
95
|
-
},
|
|
96
|
-
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
97
|
-
const [blurred, setBlurred] = useState(false);
|
|
98
|
-
|
|
99
|
-
return (
|
|
100
|
-
<Button {...args} onBlur={() => setBlurred(true)}>
|
|
101
|
-
{blurred ? 'Blurred!' : 'Button text'}
|
|
102
|
-
</Button>
|
|
103
|
-
);
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export const MouseEnterInteraction: Story = {
|
|
108
|
-
play: async ({ canvasElement, step }) => {
|
|
109
|
-
const canvas = within(canvasElement);
|
|
110
|
-
const button = canvas.getByRole('button');
|
|
111
|
-
|
|
112
|
-
await step('Hover over the button', async () => {
|
|
113
|
-
await userEvent.hover(button);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
await step('Check if button text changes to "Hovered!"', async () => {
|
|
117
|
-
await waitFor(async () => expect(button).toHaveTextContent('Hovered!'));
|
|
118
|
-
});
|
|
119
|
-
},
|
|
120
|
-
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
121
|
-
const [hovered, setHovered] = useState(false);
|
|
122
|
-
|
|
123
|
-
return (
|
|
124
|
-
<Button {...args} onMouseEnter={() => setHovered(true)}>
|
|
125
|
-
{hovered ? 'Hovered!' : 'Button text'}
|
|
126
|
-
</Button>
|
|
127
|
-
);
|
|
128
|
-
},
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
export const MouseLeaveInteraction: Story = {
|
|
132
|
-
play: async ({ canvasElement, step }) => {
|
|
133
|
-
const canvas = within(canvasElement);
|
|
134
|
-
const button = canvas.getByRole('button');
|
|
135
|
-
|
|
136
|
-
await step('Hover over the button', async () => {
|
|
137
|
-
await userEvent.hover(button);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
await step('Unhover the button', async () => {
|
|
141
|
-
await userEvent.unhover(button);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
await step('Check if button text changes to "Left!"', async () => {
|
|
145
|
-
await waitFor(async () => expect(button).toHaveTextContent('Left!'));
|
|
146
|
-
});
|
|
147
|
-
},
|
|
148
|
-
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
149
|
-
const [left, setLeft] = useState(false);
|
|
150
|
-
|
|
151
|
-
return (
|
|
152
|
-
<Button {...args} onMouseLeave={() => setLeft(true)}>
|
|
153
|
-
{left ? 'Left!' : 'Button text'}
|
|
154
|
-
</Button>
|
|
155
|
-
);
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
export const KeyDownInteraction: Story = {
|
|
160
|
-
play: async ({ canvasElement, step }) => {
|
|
161
|
-
const canvas = within(canvasElement);
|
|
162
|
-
const button = canvas.getByRole('button');
|
|
163
|
-
|
|
164
|
-
await step('Press Enter key on the button', async () => {
|
|
165
|
-
await userEvent.type(button, '{enter}');
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
await step('Check if button text changes to "Key Pressed!"', async () => {
|
|
169
|
-
await waitFor(async () => expect(button).toHaveTextContent('Key Pressed!'));
|
|
170
|
-
});
|
|
171
|
-
},
|
|
172
|
-
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
173
|
-
const [keyPressed, setKeyPressed] = useState(false);
|
|
174
|
-
|
|
175
|
-
return (
|
|
176
|
-
<Button {...args} onKeyDown={() => setKeyPressed(true)}>
|
|
177
|
-
{keyPressed ? 'Key Pressed!' : 'Button text'}
|
|
178
|
-
</Button>
|
|
179
|
-
);
|
|
180
|
-
},
|
|
181
|
-
};
|
|
182
|
-
export const DisabledClickInteraction: Story = {
|
|
183
|
-
play: async ({ canvasElement, step }) => {
|
|
184
|
-
const canvas = within(canvasElement);
|
|
185
|
-
const button = canvas.getByRole('button');
|
|
186
|
-
|
|
187
|
-
await step('Click the disabled button', async () => {
|
|
188
|
-
await userEvent.click(button);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
await step('Check if button text remains "Button text"', async () => {
|
|
192
|
-
await waitFor(async () => expect(button).toHaveTextContent('Button text'));
|
|
193
|
-
});
|
|
194
|
-
},
|
|
195
|
-
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
196
|
-
return <Button {...args} disabled />;
|
|
197
|
-
},
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
export const DisabledFocusInteraction: Story = {
|
|
201
|
-
play: async ({ canvasElement, step }) => {
|
|
202
|
-
const canvas = within(canvasElement);
|
|
203
|
-
const button = canvas.getByRole('button');
|
|
204
|
-
|
|
205
|
-
await step('Tab to the disabled button', async () => {
|
|
206
|
-
await userEvent.tab();
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
await step('Check if button does not have focus', async () => {
|
|
210
|
-
await waitFor(async () => expect(button).not.toHaveFocus());
|
|
211
|
-
});
|
|
212
|
-
},
|
|
213
|
-
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
214
|
-
return <Button {...args} disabled />;
|
|
215
|
-
},
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
export const DisabledBlurInteraction: Story = {
|
|
219
|
-
play: async ({ canvasElement, step }) => {
|
|
220
|
-
const canvas = within(canvasElement);
|
|
221
|
-
const button = canvas.getByRole('button');
|
|
222
|
-
|
|
223
|
-
await step('Tab to the disabled button', async () => {
|
|
224
|
-
await userEvent.tab();
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
await step('Check if button does not have focus', async () => {
|
|
228
|
-
await waitFor(async () => expect(button).not.toHaveFocus());
|
|
229
|
-
});
|
|
230
|
-
},
|
|
231
|
-
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
232
|
-
return <Button {...args} disabled />;
|
|
233
|
-
},
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
export const DisabledKeyDownInteraction: Story = {
|
|
237
|
-
play: async ({ canvasElement, step }) => {
|
|
238
|
-
const canvas = within(canvasElement);
|
|
239
|
-
const button = canvas.getByRole('button');
|
|
240
|
-
|
|
241
|
-
await step('Press Enter key on the disabled button', async () => {
|
|
242
|
-
await userEvent.type(button, '{enter}');
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
await step('Check if button text remains "Button text"', async () => {
|
|
246
|
-
await waitFor(async () => expect(button).toHaveTextContent('Button text'));
|
|
247
|
-
});
|
|
248
|
-
},
|
|
249
|
-
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
250
|
-
return <Button {...args} disabled />;
|
|
251
|
-
},
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
export const DisabledMouseEnterInteraction: Story = {
|
|
255
|
-
play: async ({ canvasElement, step }) => {
|
|
256
|
-
const canvas = within(canvasElement);
|
|
257
|
-
const button = canvas.getByRole('button');
|
|
258
|
-
|
|
259
|
-
await step('Hover over the disabled button', async () => {
|
|
260
|
-
await userEvent.hover(button);
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
await step('Check if button text remains "Button text"', async () => {
|
|
264
|
-
await waitFor(async () => expect(button).toHaveTextContent('Button text'));
|
|
265
|
-
});
|
|
266
|
-
},
|
|
267
|
-
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
268
|
-
return <Button {...args} disabled />;
|
|
269
|
-
},
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
export const DisabledMouseLeaveInteraction: Story = {
|
|
273
|
-
play: async ({ canvasElement, step }) => {
|
|
274
|
-
const canvas = within(canvasElement);
|
|
275
|
-
const button = canvas.getByRole('button');
|
|
276
|
-
|
|
277
|
-
await step('Unhover the disabled button', async () => {
|
|
278
|
-
await userEvent.unhover(button);
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
await step('Check if button text remains "Button text"', async () => {
|
|
282
|
-
await waitFor(async () => expect(button).toHaveTextContent('Button text'));
|
|
283
|
-
});
|
|
284
|
-
},
|
|
285
|
-
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
286
|
-
return <Button {...args} disabled />;
|
|
287
|
-
},
|
|
288
|
-
};
|
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
import { fireEvent, screen } from '@testing-library/react';
|
|
2
|
-
import { userEvent } from '@testing-library/user-event';
|
|
3
|
-
import Button from '..';
|
|
4
|
-
import messages from '../../../i18n/commonMessages/Button.messages';
|
|
5
|
-
import { render } from '../../../test-utils';
|
|
6
|
-
import { Freeze, ArrowRight } from '@transferwise/icons';
|
|
7
|
-
|
|
8
|
-
beforeAll(() => {
|
|
9
|
-
Object.defineProperty(window, 'matchMedia', {
|
|
10
|
-
writable: true,
|
|
11
|
-
value: jest.fn().mockImplementation((query: string) => ({
|
|
12
|
-
matches: false,
|
|
13
|
-
media: query,
|
|
14
|
-
onchange: null,
|
|
15
|
-
addListener: jest.fn(), // deprecated
|
|
16
|
-
removeListener: jest.fn(), // deprecated
|
|
17
|
-
addEventListener: jest.fn(),
|
|
18
|
-
removeEventListener: jest.fn(),
|
|
19
|
-
dispatchEvent: jest.fn(),
|
|
20
|
-
})),
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe('Button', () => {
|
|
25
|
-
const defaultProps = {
|
|
26
|
-
children: 'Click me',
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const renderButton = (
|
|
30
|
-
props?: Partial<typeof defaultProps>,
|
|
31
|
-
locale = 'en',
|
|
32
|
-
localeMessages = messages,
|
|
33
|
-
) => {
|
|
34
|
-
return render(
|
|
35
|
-
<Button {...defaultProps} {...props} />,
|
|
36
|
-
// @ts-expect-error: props be missing properties from type
|
|
37
|
-
{ locale, messages: localeMessages },
|
|
38
|
-
);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
it('renders a button by default', () => {
|
|
42
|
-
renderButton();
|
|
43
|
-
expect(screen.getByRole('button')).toBeInTheDocument();
|
|
44
|
-
expect(screen.getByRole('button')).toHaveTextContent('Click me');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('applies the correct classes based on props', () => {
|
|
48
|
-
const props = {
|
|
49
|
-
...defaultProps,
|
|
50
|
-
className: 'custom-class',
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
renderButton(props);
|
|
54
|
-
|
|
55
|
-
const button = screen.getByRole('button');
|
|
56
|
-
expect(button).toHaveClass('wds-Button');
|
|
57
|
-
expect(button).toHaveClass('custom-class');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('disables the button when disabled is true', () => {
|
|
61
|
-
const props = {
|
|
62
|
-
...defaultProps,
|
|
63
|
-
disabled: true,
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
renderButton(props);
|
|
67
|
-
|
|
68
|
-
const button = screen.getByRole('button');
|
|
69
|
-
expect(button).toHaveClass('wds-Button--disabled');
|
|
70
|
-
expect(button).toBeDisabled();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('calls onClick when button is clicked', async () => {
|
|
74
|
-
const handleClick = jest.fn();
|
|
75
|
-
const props = {
|
|
76
|
-
...defaultProps,
|
|
77
|
-
onClick: handleClick,
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
renderButton(props);
|
|
81
|
-
|
|
82
|
-
const button = screen.getByRole('button');
|
|
83
|
-
await userEvent.click(button);
|
|
84
|
-
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('calls onFocus when button is focused', () => {
|
|
88
|
-
const handleFocus = jest.fn();
|
|
89
|
-
const props = {
|
|
90
|
-
...defaultProps,
|
|
91
|
-
onFocus: handleFocus,
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
renderButton(props);
|
|
95
|
-
|
|
96
|
-
const button = screen.getByRole('button');
|
|
97
|
-
fireEvent.focus(button);
|
|
98
|
-
expect(handleFocus).toHaveBeenCalledTimes(1);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('calls onKeyDown when a key is pressed', async () => {
|
|
102
|
-
const handleKeyDown = jest.fn();
|
|
103
|
-
const props = {
|
|
104
|
-
...defaultProps,
|
|
105
|
-
onKeyDown: handleKeyDown,
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
renderButton(props);
|
|
109
|
-
|
|
110
|
-
const button = screen.getByRole('button');
|
|
111
|
-
await userEvent.type(button, '{enter}');
|
|
112
|
-
expect(handleKeyDown).toHaveBeenCalledTimes(1);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('calls onBlur when button loses focus', () => {
|
|
116
|
-
const handleBlur = jest.fn();
|
|
117
|
-
const props = {
|
|
118
|
-
...defaultProps,
|
|
119
|
-
onBlur: handleBlur,
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
renderButton(props);
|
|
123
|
-
|
|
124
|
-
const button = screen.getByRole('button');
|
|
125
|
-
fireEvent.blur(button);
|
|
126
|
-
expect(handleBlur).toHaveBeenCalledTimes(1);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('calls onMouseEnter when mouse enters', async () => {
|
|
130
|
-
const handleMouseEnter = jest.fn();
|
|
131
|
-
const props = {
|
|
132
|
-
...defaultProps,
|
|
133
|
-
onMouseEnter: handleMouseEnter,
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
renderButton(props);
|
|
137
|
-
|
|
138
|
-
const button = screen.getByRole('button');
|
|
139
|
-
await userEvent.hover(button);
|
|
140
|
-
expect(handleMouseEnter).toHaveBeenCalledTimes(1);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('calls onMouseLeave when mouse leaves', async () => {
|
|
144
|
-
const handleMouseLeave = jest.fn();
|
|
145
|
-
const props = {
|
|
146
|
-
...defaultProps,
|
|
147
|
-
onMouseLeave: handleMouseLeave,
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
renderButton(props);
|
|
151
|
-
|
|
152
|
-
const button = screen.getByRole('button');
|
|
153
|
-
await userEvent.unhover(button);
|
|
154
|
-
expect(handleMouseLeave).toHaveBeenCalledTimes(1);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('sets data-testid attribute', () => {
|
|
158
|
-
const props = {
|
|
159
|
-
...defaultProps,
|
|
160
|
-
testId: 'custom-id',
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
renderButton(props);
|
|
164
|
-
|
|
165
|
-
const button = screen.getByTestId('custom-id');
|
|
166
|
-
expect(button).toBeInTheDocument();
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('sets the type attribute to submit', () => {
|
|
170
|
-
const props = {
|
|
171
|
-
...defaultProps,
|
|
172
|
-
type: 'submit',
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
renderButton(props);
|
|
176
|
-
|
|
177
|
-
const button = screen.getByRole('button');
|
|
178
|
-
expect(button).toHaveAttribute('type', 'submit');
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('sets the type attribute to reset', () => {
|
|
182
|
-
const props = {
|
|
183
|
-
...defaultProps,
|
|
184
|
-
type: 'reset',
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
renderButton(props);
|
|
188
|
-
|
|
189
|
-
const button = screen.getByRole('button');
|
|
190
|
-
expect(button).toHaveAttribute('type', 'reset');
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('sets the type attribute to button by default', () => {
|
|
194
|
-
renderButton();
|
|
195
|
-
const button = screen.getByRole('button');
|
|
196
|
-
expect(button).toHaveAttribute('type', 'button');
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it('displays the aria-label in Spanish when loading', () => {
|
|
200
|
-
const props = {
|
|
201
|
-
...defaultProps,
|
|
202
|
-
loading: true,
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
const spanishMessages = {
|
|
206
|
-
...messages,
|
|
207
|
-
'neptune.Button.loadingAriaLabel': 'cargando',
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
renderButton(props, 'es', spanishMessages);
|
|
211
|
-
|
|
212
|
-
const button = screen.getByRole('button');
|
|
213
|
-
expect(button).toHaveAttribute('aria-label', 'cargando');
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it('displays with one avatar', () => {
|
|
217
|
-
const props = {
|
|
218
|
-
...defaultProps,
|
|
219
|
-
avatars: [{ asset: <Freeze /> }],
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
renderButton(props);
|
|
223
|
-
|
|
224
|
-
const avatar = screen.getByTestId('freeze-icon');
|
|
225
|
-
expect(avatar).toBeInTheDocument();
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it('displays with one avatar and no left icon', () => {
|
|
229
|
-
const props = {
|
|
230
|
-
...defaultProps,
|
|
231
|
-
avatars: [{ asset: <Freeze /> }],
|
|
232
|
-
iconLeft: ArrowRight,
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
renderButton(props);
|
|
236
|
-
|
|
237
|
-
const avatar = screen.getByTestId('freeze-icon');
|
|
238
|
-
|
|
239
|
-
expect(avatar).toBeInTheDocument();
|
|
240
|
-
expect(screen.queryByTestId('arrow-left-icon')).not.toBeInTheDocument();
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it('displays with two avatars', () => {
|
|
244
|
-
const props = {
|
|
245
|
-
...defaultProps,
|
|
246
|
-
avatars: [{ asset: <Freeze /> }, { asset: <Freeze /> }],
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
renderButton(props);
|
|
250
|
-
|
|
251
|
-
const avatars = screen.getAllByTestId('freeze-icon');
|
|
252
|
-
avatars.forEach((avatar) => {
|
|
253
|
-
expect(avatar).toBeInTheDocument();
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it('displays with avatar and icon', () => {
|
|
258
|
-
const props = {
|
|
259
|
-
...defaultProps,
|
|
260
|
-
avatars: [{ asset: <Freeze /> }],
|
|
261
|
-
iconRight: ArrowRight,
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
renderButton(props);
|
|
265
|
-
|
|
266
|
-
const iconRight = screen.getByTestId('arrow-right-icon');
|
|
267
|
-
const avatar = screen.getByTestId('freeze-icon');
|
|
268
|
-
|
|
269
|
-
expect(avatar).toBeInTheDocument();
|
|
270
|
-
expect(iconRight).toHaveClass('wds-Button-icon');
|
|
271
|
-
expect(iconRight).toHaveClass('wds-Button-icon--right');
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
it('displays with a profile name', () => {
|
|
275
|
-
const props = {
|
|
276
|
-
...defaultProps,
|
|
277
|
-
avatars: [{ profileName: 'John Doe' }],
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
renderButton(props);
|
|
281
|
-
|
|
282
|
-
const avatar = screen.getByText('JD');
|
|
283
|
-
expect(avatar).toBeInTheDocument();
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
it('displays with a profile image', () => {
|
|
287
|
-
const props = {
|
|
288
|
-
...defaultProps,
|
|
289
|
-
avatars: [{ imgSrc: '../avatar-rectangle-fox.webp' }],
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
renderButton(props);
|
|
293
|
-
|
|
294
|
-
const avatar = screen.getByRole('presentation');
|
|
295
|
-
expect(avatar).toHaveAttribute('src', '../avatar-rectangle-fox.webp');
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
it('displays with one icon', () => {
|
|
299
|
-
const props = {
|
|
300
|
-
...defaultProps,
|
|
301
|
-
iconRight: ArrowRight,
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
renderButton(props);
|
|
305
|
-
|
|
306
|
-
const iconRight = screen.getByTestId('arrow-right-icon');
|
|
307
|
-
expect(iconRight).toHaveClass('wds-Button-icon');
|
|
308
|
-
expect(iconRight).toHaveClass('wds-Button-icon--right');
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
it('displays with two icons', () => {
|
|
312
|
-
const props = {
|
|
313
|
-
...defaultProps,
|
|
314
|
-
iconRight: ArrowRight,
|
|
315
|
-
iconLeft: Freeze,
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
renderButton(props);
|
|
319
|
-
|
|
320
|
-
const iconRight = screen.getByTestId('arrow-right-icon');
|
|
321
|
-
const iconLeft = screen.getByTestId('freeze-icon');
|
|
322
|
-
|
|
323
|
-
expect(iconRight).toHaveClass('wds-Button-icon');
|
|
324
|
-
expect(iconRight).toHaveClass('wds-Button-icon--right');
|
|
325
|
-
expect(iconLeft).toHaveClass('wds-Button-icon');
|
|
326
|
-
expect(iconLeft).toHaveClass('wds-Button-icon--left');
|
|
327
|
-
});
|
|
328
|
-
});
|