@transferwise/components 0.0.0-experimental-92b8379 → 0.0.0-experimental-da032bc
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transferwise/components",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-da032bc",
|
|
4
4
|
"description": "Neptune React components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -92,12 +92,12 @@
|
|
|
92
92
|
"rollup-preserve-directives": "^1.1.1",
|
|
93
93
|
"storybook": "^8.2.2",
|
|
94
94
|
"@transferwise/less-config": "3.1.0",
|
|
95
|
-
"@transferwise/neptune-css": "0.0.0-experimental-
|
|
95
|
+
"@transferwise/neptune-css": "0.0.0-experimental-da032bc",
|
|
96
96
|
"@wise/components-theming": "1.6.1"
|
|
97
97
|
},
|
|
98
98
|
"peerDependencies": {
|
|
99
99
|
"@transferwise/icons": "^3.13.1",
|
|
100
|
-
"@transferwise/neptune-css": "0.0.0-experimental-
|
|
100
|
+
"@transferwise/neptune-css": "0.0.0-experimental-da032bc",
|
|
101
101
|
"@wise/art": "^2.16",
|
|
102
102
|
"@wise/components-theming": "^1.0.0",
|
|
103
103
|
"react": ">=18",
|
|
@@ -23,11 +23,17 @@ const wait = async (duration = 500) =>
|
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
export const ClickInteraction: Story = {
|
|
26
|
-
play: async ({ canvasElement
|
|
26
|
+
play: async ({ canvasElement, step }) => {
|
|
27
27
|
const canvas = within(canvasElement);
|
|
28
28
|
const button = canvas.getByRole('button');
|
|
29
|
-
|
|
30
|
-
await
|
|
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
|
+
});
|
|
31
37
|
},
|
|
32
38
|
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
33
39
|
const [clicked, setClicked] = useState(false);
|
|
@@ -41,12 +47,18 @@ export const ClickInteraction: Story = {
|
|
|
41
47
|
};
|
|
42
48
|
|
|
43
49
|
export const FocusInteraction: Story = {
|
|
44
|
-
play: async ({ canvasElement
|
|
50
|
+
play: async ({ canvasElement, step }) => {
|
|
45
51
|
const canvas = within(canvasElement);
|
|
46
52
|
const button = canvas.getByRole('button');
|
|
47
|
-
|
|
48
|
-
await
|
|
49
|
-
|
|
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
|
+
});
|
|
50
62
|
},
|
|
51
63
|
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
52
64
|
const [focused, setFocused] = useState(false);
|
|
@@ -60,14 +72,26 @@ export const FocusInteraction: Story = {
|
|
|
60
72
|
};
|
|
61
73
|
|
|
62
74
|
export const BlurInteraction: Story = {
|
|
63
|
-
play: async ({ canvasElement
|
|
75
|
+
play: async ({ canvasElement, step }) => {
|
|
64
76
|
const canvas = within(canvasElement);
|
|
65
77
|
const button = canvas.getByRole('button');
|
|
66
|
-
|
|
67
|
-
await
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
+
});
|
|
71
95
|
},
|
|
72
96
|
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
73
97
|
const [blurred, setBlurred] = useState(false);
|
|
@@ -81,11 +105,17 @@ export const BlurInteraction: Story = {
|
|
|
81
105
|
};
|
|
82
106
|
|
|
83
107
|
export const MouseEnterInteraction: Story = {
|
|
84
|
-
play: async ({ canvasElement
|
|
108
|
+
play: async ({ canvasElement, step }) => {
|
|
85
109
|
const canvas = within(canvasElement);
|
|
86
110
|
const button = canvas.getByRole('button');
|
|
87
|
-
|
|
88
|
-
await
|
|
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
|
+
});
|
|
89
119
|
},
|
|
90
120
|
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
91
121
|
const [hovered, setHovered] = useState(false);
|
|
@@ -99,15 +129,21 @@ export const MouseEnterInteraction: Story = {
|
|
|
99
129
|
};
|
|
100
130
|
|
|
101
131
|
export const MouseLeaveInteraction: Story = {
|
|
102
|
-
play: async ({ canvasElement
|
|
132
|
+
play: async ({ canvasElement, step }) => {
|
|
103
133
|
const canvas = within(canvasElement);
|
|
104
134
|
const button = canvas.getByRole('button');
|
|
105
135
|
|
|
106
|
-
await
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
await
|
|
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
|
+
});
|
|
111
147
|
},
|
|
112
148
|
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
113
149
|
const [left, setLeft] = useState(false);
|
|
@@ -121,11 +157,17 @@ export const MouseLeaveInteraction: Story = {
|
|
|
121
157
|
};
|
|
122
158
|
|
|
123
159
|
export const KeyDownInteraction: Story = {
|
|
124
|
-
play: async ({ canvasElement
|
|
160
|
+
play: async ({ canvasElement, step }) => {
|
|
125
161
|
const canvas = within(canvasElement);
|
|
126
162
|
const button = canvas.getByRole('button');
|
|
127
|
-
|
|
128
|
-
await
|
|
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
|
+
});
|
|
129
171
|
},
|
|
130
172
|
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
131
173
|
const [keyPressed, setKeyPressed] = useState(false);
|
|
@@ -137,13 +179,18 @@ export const KeyDownInteraction: Story = {
|
|
|
137
179
|
);
|
|
138
180
|
},
|
|
139
181
|
};
|
|
140
|
-
|
|
141
182
|
export const DisabledClickInteraction: Story = {
|
|
142
|
-
play: async ({ canvasElement
|
|
183
|
+
play: async ({ canvasElement, step }) => {
|
|
143
184
|
const canvas = within(canvasElement);
|
|
144
185
|
const button = canvas.getByRole('button');
|
|
145
|
-
|
|
146
|
-
await
|
|
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
|
+
});
|
|
147
194
|
},
|
|
148
195
|
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
149
196
|
return <Button {...args} disabled />;
|
|
@@ -151,11 +198,17 @@ export const DisabledClickInteraction: Story = {
|
|
|
151
198
|
};
|
|
152
199
|
|
|
153
200
|
export const DisabledFocusInteraction: Story = {
|
|
154
|
-
play: async ({ canvasElement
|
|
201
|
+
play: async ({ canvasElement, step }) => {
|
|
155
202
|
const canvas = within(canvasElement);
|
|
156
203
|
const button = canvas.getByRole('button');
|
|
157
|
-
|
|
158
|
-
await
|
|
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
|
+
});
|
|
159
212
|
},
|
|
160
213
|
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
161
214
|
return <Button {...args} disabled />;
|
|
@@ -163,11 +216,17 @@ export const DisabledFocusInteraction: Story = {
|
|
|
163
216
|
};
|
|
164
217
|
|
|
165
218
|
export const DisabledBlurInteraction: Story = {
|
|
166
|
-
play: async ({ canvasElement
|
|
219
|
+
play: async ({ canvasElement, step }) => {
|
|
167
220
|
const canvas = within(canvasElement);
|
|
168
221
|
const button = canvas.getByRole('button');
|
|
169
|
-
|
|
170
|
-
await
|
|
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
|
+
});
|
|
171
230
|
},
|
|
172
231
|
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
173
232
|
return <Button {...args} disabled />;
|
|
@@ -175,11 +234,17 @@ export const DisabledBlurInteraction: Story = {
|
|
|
175
234
|
};
|
|
176
235
|
|
|
177
236
|
export const DisabledKeyDownInteraction: Story = {
|
|
178
|
-
play: async ({ canvasElement
|
|
237
|
+
play: async ({ canvasElement, step }) => {
|
|
179
238
|
const canvas = within(canvasElement);
|
|
180
239
|
const button = canvas.getByRole('button');
|
|
181
|
-
|
|
182
|
-
await
|
|
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
|
+
});
|
|
183
248
|
},
|
|
184
249
|
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
185
250
|
return <Button {...args} disabled />;
|
|
@@ -187,11 +252,17 @@ export const DisabledKeyDownInteraction: Story = {
|
|
|
187
252
|
};
|
|
188
253
|
|
|
189
254
|
export const DisabledMouseEnterInteraction: Story = {
|
|
190
|
-
play: async ({ canvasElement
|
|
255
|
+
play: async ({ canvasElement, step }) => {
|
|
191
256
|
const canvas = within(canvasElement);
|
|
192
257
|
const button = canvas.getByRole('button');
|
|
193
|
-
|
|
194
|
-
await
|
|
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
|
+
});
|
|
195
266
|
},
|
|
196
267
|
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
197
268
|
return <Button {...args} disabled />;
|
|
@@ -199,11 +270,17 @@ export const DisabledMouseEnterInteraction: Story = {
|
|
|
199
270
|
};
|
|
200
271
|
|
|
201
272
|
export const DisabledMouseLeaveInteraction: Story = {
|
|
202
|
-
play: async ({ canvasElement
|
|
273
|
+
play: async ({ canvasElement, step }) => {
|
|
203
274
|
const canvas = within(canvasElement);
|
|
204
275
|
const button = canvas.getByRole('button');
|
|
205
|
-
|
|
206
|
-
await
|
|
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
|
+
});
|
|
207
284
|
},
|
|
208
285
|
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
209
286
|
return <Button {...args} disabled />;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
|
-
import { userEvent, within, expect } from '@storybook/test';
|
|
2
|
+
import { userEvent, within, expect, waitFor } from '@storybook/test';
|
|
3
3
|
import { Meta, StoryObj } from '@storybook/react';
|
|
4
4
|
import PrimitiveAnchor from '../src';
|
|
5
5
|
|
|
@@ -22,11 +22,17 @@ const wait = async (duration = 500) =>
|
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
export const ClickInteraction: Story = {
|
|
25
|
-
play: async ({ canvasElement }) => {
|
|
25
|
+
play: async ({ canvasElement, step }) => {
|
|
26
26
|
const canvas = within(canvasElement);
|
|
27
27
|
const link = canvas.getByRole('link');
|
|
28
|
-
|
|
29
|
-
await
|
|
28
|
+
|
|
29
|
+
await step('Click the link', async () => {
|
|
30
|
+
await userEvent.click(link);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
await step('Check if link text changes to "Clicked!"', async () => {
|
|
34
|
+
await waitFor(async () => expect(link).toHaveTextContent('Clicked!'));
|
|
35
|
+
});
|
|
30
36
|
},
|
|
31
37
|
render: function Render(args) {
|
|
32
38
|
const [clicked, setClicked] = useState(false);
|
|
@@ -46,12 +52,18 @@ export const ClickInteraction: Story = {
|
|
|
46
52
|
};
|
|
47
53
|
|
|
48
54
|
export const FocusInteraction: Story = {
|
|
49
|
-
play: async ({ canvasElement }) => {
|
|
55
|
+
play: async ({ canvasElement, step }) => {
|
|
50
56
|
const canvas = within(canvasElement);
|
|
51
57
|
const link = canvas.getByRole('link');
|
|
52
|
-
|
|
53
|
-
await
|
|
54
|
-
|
|
58
|
+
|
|
59
|
+
await step('Tab to the link', async () => {
|
|
60
|
+
await userEvent.tab();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
await step('Check if link has focus and text changes to "Focused!"', async () => {
|
|
64
|
+
await waitFor(async () => expect(link).toHaveFocus());
|
|
65
|
+
await waitFor(async () => expect(link).toHaveTextContent('Focused!'));
|
|
66
|
+
});
|
|
55
67
|
},
|
|
56
68
|
render: function Render(args) {
|
|
57
69
|
const [focused, setFocused] = useState(false);
|
|
@@ -65,14 +77,26 @@ export const FocusInteraction: Story = {
|
|
|
65
77
|
};
|
|
66
78
|
|
|
67
79
|
export const BlurInteraction: Story = {
|
|
68
|
-
play: async ({ canvasElement }) => {
|
|
80
|
+
play: async ({ canvasElement, step }) => {
|
|
69
81
|
const canvas = within(canvasElement);
|
|
70
82
|
const link = canvas.getByRole('link');
|
|
71
|
-
|
|
72
|
-
await
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
83
|
+
|
|
84
|
+
await step('Tab to the link', async () => {
|
|
85
|
+
await userEvent.tab();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
await step('Check if link has focus', async () => {
|
|
89
|
+
await waitFor(async () => expect(link).toHaveFocus());
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
await step('Tab away from the link', async () => {
|
|
93
|
+
await userEvent.tab();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
await step('Check if link loses focus and text changes to "Blurred!"', async () => {
|
|
97
|
+
await waitFor(async () => expect(link).not.toHaveFocus());
|
|
98
|
+
await waitFor(async () => expect(link).toHaveTextContent('Blurred!'));
|
|
99
|
+
});
|
|
76
100
|
},
|
|
77
101
|
render: function Render(args) {
|
|
78
102
|
const [blurred, setBlurred] = useState(false);
|
|
@@ -86,12 +110,17 @@ export const BlurInteraction: Story = {
|
|
|
86
110
|
};
|
|
87
111
|
|
|
88
112
|
export const MouseEnterInteraction: Story = {
|
|
89
|
-
play: async ({ canvasElement }) => {
|
|
113
|
+
play: async ({ canvasElement, step }) => {
|
|
90
114
|
const canvas = within(canvasElement);
|
|
91
115
|
const link = canvas.getByRole('link');
|
|
92
|
-
|
|
93
|
-
await
|
|
94
|
-
|
|
116
|
+
|
|
117
|
+
await step('Hover over the link', async () => {
|
|
118
|
+
await userEvent.hover(link);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
await step('Check if link text changes to "Hovered!"', async () => {
|
|
122
|
+
await waitFor(async () => expect(link).toHaveTextContent('Hovered!'));
|
|
123
|
+
});
|
|
95
124
|
},
|
|
96
125
|
render: function Render(args) {
|
|
97
126
|
const [hovered, setHovered] = useState(false);
|
|
@@ -105,12 +134,21 @@ export const MouseEnterInteraction: Story = {
|
|
|
105
134
|
};
|
|
106
135
|
|
|
107
136
|
export const MouseLeaveInteraction: Story = {
|
|
108
|
-
play: async ({ canvasElement }) => {
|
|
137
|
+
play: async ({ canvasElement, step }) => {
|
|
109
138
|
const canvas = within(canvasElement);
|
|
110
139
|
const link = canvas.getByRole('link');
|
|
111
|
-
|
|
112
|
-
await
|
|
113
|
-
|
|
140
|
+
|
|
141
|
+
await step('Hover over the link', async () => {
|
|
142
|
+
await userEvent.hover(link);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
await step('Unhover the link', async () => {
|
|
146
|
+
await userEvent.unhover(link);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
await step('Check if link text changes to "Left!"', async () => {
|
|
150
|
+
await waitFor(async () => expect(link).toHaveTextContent('Left!'));
|
|
151
|
+
});
|
|
114
152
|
},
|
|
115
153
|
render: function Render(args) {
|
|
116
154
|
const [left, setLeft] = useState(false);
|
|
@@ -124,14 +162,19 @@ export const MouseLeaveInteraction: Story = {
|
|
|
124
162
|
};
|
|
125
163
|
|
|
126
164
|
export const KeyDownInteraction: Story = {
|
|
127
|
-
play: async ({ canvasElement }) => {
|
|
165
|
+
play: async ({ canvasElement, step }) => {
|
|
128
166
|
const canvas = within(canvasElement);
|
|
129
167
|
const link = canvas.getByRole('link');
|
|
130
|
-
|
|
131
|
-
await
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
168
|
+
|
|
169
|
+
await step('Press ArrowDown key on the link', async () => {
|
|
170
|
+
await userEvent.tab();
|
|
171
|
+
await wait();
|
|
172
|
+
await userEvent.keyboard('{ArrowDown}');
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
await step('Check if link text changes to "Key Pressed!"', async () => {
|
|
176
|
+
await waitFor(async () => expect(link).toHaveTextContent('Key Pressed!'));
|
|
177
|
+
});
|
|
135
178
|
},
|
|
136
179
|
render: function Render(args) {
|
|
137
180
|
const [keyPressed, setKeyPressed] = useState(false);
|
|
@@ -153,11 +196,17 @@ export const KeyDownInteraction: Story = {
|
|
|
153
196
|
};
|
|
154
197
|
|
|
155
198
|
export const TabIndexBehavior: Story = {
|
|
156
|
-
play: async ({ canvasElement }) => {
|
|
199
|
+
play: async ({ canvasElement, step }) => {
|
|
157
200
|
const canvas = within(canvasElement);
|
|
158
201
|
const link = canvas.getByRole('link');
|
|
159
|
-
|
|
160
|
-
await
|
|
202
|
+
|
|
203
|
+
await step('Tab to the link', async () => {
|
|
204
|
+
await userEvent.tab();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
await step('Check if link does not have focus', async () => {
|
|
208
|
+
await waitFor(async () => expect(link).not.toHaveFocus());
|
|
209
|
+
});
|
|
161
210
|
},
|
|
162
211
|
render: function Render(args) {
|
|
163
212
|
return (
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
|
-
import { userEvent, within, expect } from '@storybook/test';
|
|
2
|
+
import { userEvent, within, expect, waitFor } from '@storybook/test';
|
|
3
3
|
import { Meta, StoryObj } from '@storybook/react';
|
|
4
4
|
import PrimitiveButton from '../src';
|
|
5
5
|
|
|
@@ -22,11 +22,17 @@ const wait = async (duration = 500) =>
|
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
export const ClickInteraction: Story = {
|
|
25
|
-
play: async ({ canvasElement }) => {
|
|
25
|
+
play: async ({ canvasElement, step }) => {
|
|
26
26
|
const canvas = within(canvasElement);
|
|
27
27
|
const button = canvas.getByRole('button');
|
|
28
|
-
|
|
29
|
-
await
|
|
28
|
+
|
|
29
|
+
await step('Click the button', async () => {
|
|
30
|
+
await userEvent.click(button);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
await step('Check if button text changes to "Clicked!"', async () => {
|
|
34
|
+
await waitFor(async () => expect(button).toHaveTextContent('Clicked!'));
|
|
35
|
+
});
|
|
30
36
|
},
|
|
31
37
|
render: function Render(args) {
|
|
32
38
|
const [clicked, setClicked] = useState(false);
|
|
@@ -40,12 +46,18 @@ export const ClickInteraction: Story = {
|
|
|
40
46
|
};
|
|
41
47
|
|
|
42
48
|
export const FocusInteraction: Story = {
|
|
43
|
-
play: async ({ canvasElement }) => {
|
|
49
|
+
play: async ({ canvasElement, step }) => {
|
|
44
50
|
const canvas = within(canvasElement);
|
|
45
51
|
const button = canvas.getByRole('button');
|
|
46
|
-
|
|
47
|
-
await
|
|
48
|
-
|
|
52
|
+
|
|
53
|
+
await step('Tab to the button', async () => {
|
|
54
|
+
await userEvent.tab();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
await step('Check if button has focus and text changes to "Focused!"', async () => {
|
|
58
|
+
await waitFor(async () => expect(button).toHaveFocus());
|
|
59
|
+
await waitFor(async () => expect(button).toHaveTextContent('Focused!'));
|
|
60
|
+
});
|
|
49
61
|
},
|
|
50
62
|
render: function Render(args) {
|
|
51
63
|
const [focused, setFocused] = useState(false);
|
|
@@ -59,14 +71,26 @@ export const FocusInteraction: Story = {
|
|
|
59
71
|
};
|
|
60
72
|
|
|
61
73
|
export const BlurInteraction: Story = {
|
|
62
|
-
play: async ({ canvasElement }) => {
|
|
74
|
+
play: async ({ canvasElement, step }) => {
|
|
63
75
|
const canvas = within(canvasElement);
|
|
64
76
|
const button = canvas.getByRole('button');
|
|
65
|
-
|
|
66
|
-
await
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
77
|
+
|
|
78
|
+
await step('Tab to the button', async () => {
|
|
79
|
+
await userEvent.tab();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
await step('Check if button has focus', async () => {
|
|
83
|
+
await waitFor(async () => expect(button).toHaveFocus());
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
await step('Tab away from the button', async () => {
|
|
87
|
+
await userEvent.tab();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
await step('Check if button loses focus and text changes to "Blurred!"', async () => {
|
|
91
|
+
await waitFor(async () => expect(button).not.toHaveFocus());
|
|
92
|
+
await waitFor(async () => expect(button).toHaveTextContent('Blurred!'));
|
|
93
|
+
});
|
|
70
94
|
},
|
|
71
95
|
render: function Render(args) {
|
|
72
96
|
const [blurred, setBlurred] = useState(false);
|
|
@@ -80,11 +104,17 @@ export const BlurInteraction: Story = {
|
|
|
80
104
|
};
|
|
81
105
|
|
|
82
106
|
export const MouseEnterInteraction: Story = {
|
|
83
|
-
play: async ({ canvasElement }) => {
|
|
107
|
+
play: async ({ canvasElement, step }) => {
|
|
84
108
|
const canvas = within(canvasElement);
|
|
85
109
|
const button = canvas.getByRole('button');
|
|
86
|
-
|
|
87
|
-
await
|
|
110
|
+
|
|
111
|
+
await step('Hover over the button', async () => {
|
|
112
|
+
await userEvent.hover(button);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
await step('Check if button text changes to "Hovered!"', async () => {
|
|
116
|
+
await waitFor(async () => expect(button).toHaveTextContent('Hovered!'));
|
|
117
|
+
});
|
|
88
118
|
},
|
|
89
119
|
render: function Render(args) {
|
|
90
120
|
const [hovered, setHovered] = useState(false);
|
|
@@ -98,11 +128,21 @@ export const MouseEnterInteraction: Story = {
|
|
|
98
128
|
};
|
|
99
129
|
|
|
100
130
|
export const MouseLeaveInteraction: Story = {
|
|
101
|
-
play: async ({ canvasElement }) => {
|
|
131
|
+
play: async ({ canvasElement, step }) => {
|
|
102
132
|
const canvas = within(canvasElement);
|
|
103
133
|
const button = canvas.getByRole('button');
|
|
104
|
-
|
|
105
|
-
await
|
|
134
|
+
|
|
135
|
+
await step('Hover over the button', async () => {
|
|
136
|
+
await userEvent.hover(button);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
await step('Unhover the button', async () => {
|
|
140
|
+
await userEvent.unhover(button);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
await step('Check if button text changes to "Left!"', async () => {
|
|
144
|
+
await waitFor(async () => expect(button).toHaveTextContent('Left!'));
|
|
145
|
+
});
|
|
106
146
|
},
|
|
107
147
|
render: function Render(args) {
|
|
108
148
|
const [left, setLeft] = useState(false);
|
|
@@ -116,11 +156,17 @@ export const MouseLeaveInteraction: Story = {
|
|
|
116
156
|
};
|
|
117
157
|
|
|
118
158
|
export const KeyDownInteraction: Story = {
|
|
119
|
-
play: async ({ canvasElement }) => {
|
|
159
|
+
play: async ({ canvasElement, step }) => {
|
|
120
160
|
const canvas = within(canvasElement);
|
|
121
161
|
const button = canvas.getByRole('button');
|
|
122
|
-
|
|
123
|
-
await
|
|
162
|
+
|
|
163
|
+
await step('Press Enter key on the button', async () => {
|
|
164
|
+
await userEvent.type(button, '{enter}');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
await step('Check if button text changes to "Key Pressed!"', async () => {
|
|
168
|
+
await waitFor(async () => expect(button).toHaveTextContent('Key Pressed!'));
|
|
169
|
+
});
|
|
124
170
|
},
|
|
125
171
|
render: function Render(args) {
|
|
126
172
|
const [keyPressed, setKeyPressed] = useState(false);
|
|
@@ -134,11 +180,17 @@ export const KeyDownInteraction: Story = {
|
|
|
134
180
|
};
|
|
135
181
|
|
|
136
182
|
export const DisabledClickInteraction: Story = {
|
|
137
|
-
play: async ({ canvasElement }) => {
|
|
183
|
+
play: async ({ canvasElement, step }) => {
|
|
138
184
|
const canvas = within(canvasElement);
|
|
139
185
|
const button = canvas.getByRole('button');
|
|
140
|
-
|
|
141
|
-
await
|
|
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
|
+
});
|
|
142
194
|
},
|
|
143
195
|
render: function Render(args) {
|
|
144
196
|
return (
|
|
@@ -150,11 +202,17 @@ export const DisabledClickInteraction: Story = {
|
|
|
150
202
|
};
|
|
151
203
|
|
|
152
204
|
export const DisabledFocusInteraction: Story = {
|
|
153
|
-
play: async ({ canvasElement }) => {
|
|
205
|
+
play: async ({ canvasElement, step }) => {
|
|
154
206
|
const canvas = within(canvasElement);
|
|
155
207
|
const button = canvas.getByRole('button');
|
|
156
|
-
|
|
157
|
-
await
|
|
208
|
+
|
|
209
|
+
await step('Tab to the disabled button', async () => {
|
|
210
|
+
await userEvent.tab();
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
await step('Check if button does not have focus', async () => {
|
|
214
|
+
await waitFor(async () => expect(button).not.toHaveFocus());
|
|
215
|
+
});
|
|
158
216
|
},
|
|
159
217
|
render: function Render(args) {
|
|
160
218
|
return (
|
|
@@ -166,11 +224,17 @@ export const DisabledFocusInteraction: Story = {
|
|
|
166
224
|
};
|
|
167
225
|
|
|
168
226
|
export const DisabledBlurInteraction: Story = {
|
|
169
|
-
play: async ({ canvasElement }) => {
|
|
227
|
+
play: async ({ canvasElement, step }) => {
|
|
170
228
|
const canvas = within(canvasElement);
|
|
171
229
|
const button = canvas.getByRole('button');
|
|
172
|
-
|
|
173
|
-
await
|
|
230
|
+
|
|
231
|
+
await step('Tab to the disabled button', async () => {
|
|
232
|
+
await userEvent.tab();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
await step('Check if button does not have focus', async () => {
|
|
236
|
+
await waitFor(async () => expect(button).not.toHaveFocus());
|
|
237
|
+
});
|
|
174
238
|
},
|
|
175
239
|
render: function Render(args) {
|
|
176
240
|
return (
|
|
@@ -182,11 +246,17 @@ export const DisabledBlurInteraction: Story = {
|
|
|
182
246
|
};
|
|
183
247
|
|
|
184
248
|
export const DisabledKeyDownInteraction: Story = {
|
|
185
|
-
play: async ({ canvasElement }) => {
|
|
249
|
+
play: async ({ canvasElement, step }) => {
|
|
186
250
|
const canvas = within(canvasElement);
|
|
187
251
|
const button = canvas.getByRole('button');
|
|
188
|
-
|
|
189
|
-
await
|
|
252
|
+
|
|
253
|
+
await step('Press Enter key on the disabled button', async () => {
|
|
254
|
+
await userEvent.type(button, '{enter}');
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
await step('Check if button text remains "Button text"', async () => {
|
|
258
|
+
await waitFor(async () => expect(button).toHaveTextContent('Button text'));
|
|
259
|
+
});
|
|
190
260
|
},
|
|
191
261
|
render: function Render(args) {
|
|
192
262
|
return (
|
|
@@ -198,11 +268,17 @@ export const DisabledKeyDownInteraction: Story = {
|
|
|
198
268
|
};
|
|
199
269
|
|
|
200
270
|
export const DisabledMouseEnterInteraction: Story = {
|
|
201
|
-
play: async ({ canvasElement }) => {
|
|
271
|
+
play: async ({ canvasElement, step }) => {
|
|
202
272
|
const canvas = within(canvasElement);
|
|
203
273
|
const button = canvas.getByRole('button');
|
|
204
|
-
|
|
205
|
-
await
|
|
274
|
+
|
|
275
|
+
await step('Hover over the disabled button', async () => {
|
|
276
|
+
await userEvent.hover(button);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
await step('Check if button text remains "Button text"', async () => {
|
|
280
|
+
await waitFor(async () => expect(button).toHaveTextContent('Button text'));
|
|
281
|
+
});
|
|
206
282
|
},
|
|
207
283
|
render: function Render(args) {
|
|
208
284
|
return (
|
|
@@ -214,11 +290,17 @@ export const DisabledMouseEnterInteraction: Story = {
|
|
|
214
290
|
};
|
|
215
291
|
|
|
216
292
|
export const DisabledMouseLeaveInteraction: Story = {
|
|
217
|
-
play: async ({ canvasElement }) => {
|
|
293
|
+
play: async ({ canvasElement, step }) => {
|
|
218
294
|
const canvas = within(canvasElement);
|
|
219
295
|
const button = canvas.getByRole('button');
|
|
220
|
-
|
|
221
|
-
await
|
|
296
|
+
|
|
297
|
+
await step('Unhover the disabled button', async () => {
|
|
298
|
+
await userEvent.unhover(button);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
await step('Check if button text remains "Button text"', async () => {
|
|
302
|
+
await waitFor(async () => expect(button).toHaveTextContent('Button text'));
|
|
303
|
+
});
|
|
222
304
|
},
|
|
223
305
|
render: function Render(args) {
|
|
224
306
|
return (
|