@transferwise/components 46.84.0 → 46.85.0

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.
Files changed (66) hide show
  1. package/build/dimmer/Dimmer.js.map +1 -1
  2. package/build/dimmer/Dimmer.mjs.map +1 -1
  3. package/build/i18n/en.json +1 -0
  4. package/build/i18n/en.json.js +1 -0
  5. package/build/i18n/en.json.js.map +1 -1
  6. package/build/i18n/en.json.mjs +1 -0
  7. package/build/i18n/en.json.mjs.map +1 -1
  8. package/build/i18n/th.json +5 -0
  9. package/build/i18n/th.json.js +5 -0
  10. package/build/i18n/th.json.js.map +1 -1
  11. package/build/i18n/th.json.mjs +5 -0
  12. package/build/i18n/th.json.mjs.map +1 -1
  13. package/build/i18n/zh-CN.json +10 -0
  14. package/build/i18n/zh-CN.json.js +10 -0
  15. package/build/i18n/zh-CN.json.js.map +1 -1
  16. package/build/i18n/zh-CN.json.mjs +10 -0
  17. package/build/i18n/zh-CN.json.mjs.map +1 -1
  18. package/build/i18n/zh-HK.json +5 -0
  19. package/build/i18n/zh-HK.json.js +5 -0
  20. package/build/i18n/zh-HK.json.js.map +1 -1
  21. package/build/i18n/zh-HK.json.mjs +5 -0
  22. package/build/i18n/zh-HK.json.mjs.map +1 -1
  23. package/build/stepper/Stepper.js +6 -3
  24. package/build/stepper/Stepper.js.map +1 -1
  25. package/build/stepper/Stepper.mjs +6 -3
  26. package/build/stepper/Stepper.mjs.map +1 -1
  27. package/build/types/dimmer/Dimmer.d.ts +1 -1
  28. package/build/types/dimmer/Dimmer.d.ts.map +1 -1
  29. package/build/types/stepper/Stepper.d.ts +2 -1
  30. package/build/types/stepper/Stepper.d.ts.map +1 -1
  31. package/build/types/test-utils/index.d.ts +2 -0
  32. package/build/types/test-utils/index.d.ts.map +1 -1
  33. package/build/types/uploadInput/uploadButton/UploadButton.messages.d.ts +5 -0
  34. package/build/types/uploadInput/uploadButton/UploadButton.messages.d.ts.map +1 -1
  35. package/build/uploadInput/uploadButton/UploadButton.js +3 -1
  36. package/build/uploadInput/uploadButton/UploadButton.js.map +1 -1
  37. package/build/uploadInput/uploadButton/UploadButton.messages.js +3 -0
  38. package/build/uploadInput/uploadButton/UploadButton.messages.js.map +1 -1
  39. package/build/uploadInput/uploadButton/UploadButton.messages.mjs +3 -0
  40. package/build/uploadInput/uploadButton/UploadButton.messages.mjs.map +1 -1
  41. package/build/uploadInput/uploadButton/UploadButton.mjs +3 -1
  42. package/build/uploadInput/uploadButton/UploadButton.mjs.map +1 -1
  43. package/package.json +5 -5
  44. package/src/dimmer/{Dimmer.rtl.spec.tsx → Dimmer.spec.tsx} +33 -29
  45. package/src/dimmer/Dimmer.tsx +4 -4
  46. package/src/flowNavigation/__snapshots__/FlowNavigation.spec.js.snap +3 -1
  47. package/src/i18n/en.json +1 -0
  48. package/src/i18n/th.json +5 -0
  49. package/src/i18n/zh-CN.json +10 -0
  50. package/src/i18n/zh-HK.json +5 -0
  51. package/src/inputs/SelectInput.story.tsx +68 -24
  52. package/src/navigationOption/NavigationOption.spec.tsx +113 -0
  53. package/src/primitives/PrimitiveAnchor/stories/PrimitiveAnchor.tests.story.tsx +81 -32
  54. package/src/primitives/PrimitiveButton/stories/PrimitiveButton.tests.story.tsx +124 -42
  55. package/src/radioOption/RadioOption.spec.tsx +73 -0
  56. package/src/stepper/Stepper.spec.tsx +236 -0
  57. package/src/stepper/Stepper.tests.story.tsx +89 -0
  58. package/src/stepper/Stepper.tsx +9 -4
  59. package/src/stepper/{deviceDetection.spec.js → deviceDetection.spec.ts} +6 -3
  60. package/src/uploadInput/uploadButton/UploadButton.messages.ts +7 -0
  61. package/src/uploadInput/uploadButton/UploadButton.tsx +1 -1
  62. package/src/dimmer/Dimmer.spec.js +0 -87
  63. package/src/navigationOption/NavigationOption.spec.js +0 -93
  64. package/src/radioOption/RadioOption.spec.js +0 -67
  65. package/src/stepper/Stepper.spec.js +0 -233
  66. /package/src/alert/{Alert.spec.story.tsx → Alert.tests.story.tsx} +0 -0
@@ -0,0 +1,113 @@
1
+ import { render, screen, userEvent } from '../test-utils';
2
+ import type { PropsWithChildren } from 'react';
3
+
4
+ import NavigationOption, { type NavigationOptionProps } from './NavigationOption';
5
+
6
+ describe('Navigation option', () => {
7
+ const initialProps = {
8
+ id: 'componentId',
9
+ name: 'componentName',
10
+ title: 'Component Title',
11
+ content: <img alt="contentImage" />,
12
+ media: <img alt="media" />,
13
+ onClick: jest.fn(),
14
+ complex: true,
15
+ };
16
+ const customRender = (overrides: Partial<NavigationOptionProps> = {}) =>
17
+ render(<NavigationOption {...initialProps} {...overrides} />);
18
+
19
+ afterEach(jest.resetAllMocks);
20
+
21
+ describe('render as', () => {
22
+ it('should render `button` when a `href` and `as` is not passed', () => {
23
+ customRender();
24
+ expect(
25
+ screen.getByRole('button', { name: new RegExp(initialProps.title) }),
26
+ ).toBeInTheDocument();
27
+ });
28
+
29
+ it('should render anchor when a `href` is passed', () => {
30
+ const href = 'https://wise.com';
31
+ customRender({ href });
32
+ expect(screen.getByRole('link', { name: new RegExp(initialProps.title) })).toHaveAttribute(
33
+ 'href',
34
+ href,
35
+ );
36
+ });
37
+
38
+ it('should respect `as` prop', () => {
39
+ const View = (props: PropsWithChildren) => <div {...props} data-testid="wrapper" />;
40
+ customRender({ as: View });
41
+
42
+ expect(screen.getByTestId('wrapper')).toBeInTheDocument();
43
+ });
44
+ });
45
+
46
+ it('should render `media`', () => {
47
+ customRender();
48
+ expect(screen.getByRole('img', { name: 'media' })).toBeInTheDocument();
49
+ });
50
+
51
+ it('passes `id`', () => {
52
+ customRender();
53
+ expect(screen.getByRole('button')).toHaveAttribute('id', initialProps.id);
54
+ });
55
+
56
+ it('passes `name`', () => {
57
+ customRender();
58
+ expect(screen.getByRole('button')).toHaveAttribute('name', initialProps.name);
59
+ });
60
+
61
+ describe('disabled', () => {
62
+ it('should be `false` by default', () => {
63
+ customRender();
64
+ expect(screen.getByRole('button')).toBeEnabled();
65
+ });
66
+
67
+ it('should respect the prop', () => {
68
+ customRender({ disabled: true });
69
+ expect(screen.getByRole('button')).toBeDisabled();
70
+ });
71
+
72
+ it('calls click handler on option click when not disabled', async () => {
73
+ customRender();
74
+ await userEvent.click(screen.getByRole('button'));
75
+ expect(initialProps.onClick).toHaveBeenCalledTimes(1);
76
+ });
77
+
78
+ it('does not call click handler when disabled', async () => {
79
+ customRender({ disabled: true });
80
+ await userEvent.click(screen.getByRole('button'));
81
+ expect(initialProps.onClick).not.toHaveBeenCalled();
82
+ });
83
+ });
84
+
85
+ describe('rendering circle', () => {
86
+ it('should render it by default', () => {
87
+ customRender();
88
+ expect(screen.getByRole('img', { name: 'media' }).parentNode).toHaveClass('circle');
89
+ });
90
+
91
+ it('should respect `showMediaCircle` prop', () => {
92
+ customRender({ showMediaCircle: false });
93
+ expect(screen.getByRole('img', { name: 'media' }).parentNode).not.toHaveClass('circle');
94
+ });
95
+ });
96
+
97
+ it('should pass correct class names to Option', () => {
98
+ customRender({ className: 'test-class-name' });
99
+ expect(screen.getByRole('button')).toHaveClass('test-class-name');
100
+ });
101
+
102
+ describe('isContainerAligned', () => {
103
+ it('should not be aligned by default', () => {
104
+ const { container } = customRender();
105
+ expect(container.querySelector('.np-option')).not.toHaveClass('np-option__container-aligned');
106
+ });
107
+
108
+ it('renders aligned with container content', () => {
109
+ const { container } = customRender({ isContainerAligned: true });
110
+ expect(container.querySelector('.np-option')).toHaveClass('np-option__container-aligned');
111
+ });
112
+ });
113
+ });
@@ -1,7 +1,7 @@
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
- import PrimitiveAnchor from '..';
4
+ import PrimitiveAnchor from '../src';
5
5
 
6
6
  const meta = {
7
7
  title: 'Primitives/Anchor/Tests',
@@ -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
- await userEvent.click(link);
29
- await expect(link).toHaveTextContent('Clicked!');
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
- await userEvent.tab();
53
- await expect(link).toHaveFocus();
54
- await expect(link).toHaveTextContent('Focused!');
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
- await userEvent.tab();
72
- await expect(link).toHaveFocus();
73
- await userEvent.tab();
74
- await expect(link).not.toHaveFocus();
75
- await expect(link).toHaveTextContent('Blurred!');
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
- await expect(link).toHaveTextContent('Click me');
93
- await userEvent.hover(link);
94
- await expect(link).toHaveTextContent('Hovered!');
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
- await expect(link).toHaveTextContent('Click me');
112
- await userEvent.unhover(link);
113
- await expect(link).toHaveTextContent('Left!');
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
- await expect(link).toHaveTextContent('Click me');
131
- await userEvent.tab();
132
- await wait();
133
- await userEvent.keyboard('{ArrowDown}');
134
- await expect(link).toHaveTextContent('Key Pressed!');
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
- await userEvent.tab();
160
- await expect(link).not.toHaveFocus();
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,7 +1,7 @@
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
- import PrimitiveButton from '..';
4
+ import PrimitiveButton from '../src';
5
5
 
6
6
  const meta = {
7
7
  title: 'Primitives/Button/Tests',
@@ -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
- await userEvent.click(button);
29
- await expect(button).toHaveTextContent('Clicked!');
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
- await userEvent.tab();
47
- await expect(button).toHaveFocus();
48
- await expect(button).toHaveTextContent('Focused!');
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
- await userEvent.tab();
66
- await expect(button).toHaveFocus();
67
- await userEvent.tab();
68
- await expect(button).not.toHaveFocus();
69
- await expect(button).toHaveTextContent('Blurred!');
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
- await userEvent.hover(button);
87
- await expect(button).toHaveTextContent('Hovered!');
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
- await userEvent.unhover(button);
105
- await expect(button).toHaveTextContent('Left!');
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
- await userEvent.type(button, '{enter}');
123
- await expect(button).toHaveTextContent('Key Pressed!');
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
- await userEvent.click(button);
141
- await expect(button).toHaveTextContent('Button text');
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
- await userEvent.tab();
157
- await expect(button).not.toHaveFocus();
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
- await userEvent.tab();
173
- await expect(button).not.toHaveFocus();
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
- await userEvent.type(button, '{enter}');
189
- await expect(button).toHaveTextContent('Button text');
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
- await userEvent.hover(button);
205
- await expect(button).toHaveTextContent('Button text');
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
- await userEvent.unhover(button);
221
- await expect(button).toHaveTextContent('Button text');
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 (
@@ -0,0 +1,73 @@
1
+ import { render, screen, userEvent } from '../test-utils';
2
+ import RadioOption, { type RadioOptionProps } from '.';
3
+
4
+ describe('Radio option', () => {
5
+ const initialProps = {
6
+ id: 'componentId',
7
+ name: 'componentName',
8
+ title: 'Component Title',
9
+ content: <img alt="contentImage" />,
10
+ onChange: jest.fn(),
11
+ };
12
+
13
+ const customRender = (overrides: Partial<RadioOptionProps> = {}) =>
14
+ render(<RadioOption {...initialProps} {...overrides} />);
15
+
16
+ it('should render `media`', () => {
17
+ const Icon = <img alt="media" />;
18
+ customRender({ media: Icon });
19
+ expect(screen.getByRole('img', { name: 'media' })).toBeInTheDocument();
20
+ });
21
+
22
+ it('passes props to radio button', () => {
23
+ customRender();
24
+ expect(screen.getByRole('radio')).toHaveAttribute('id', initialProps.id);
25
+ });
26
+
27
+ it('passes name to radio button', () => {
28
+ customRender();
29
+ expect(screen.getByRole('radio')).toHaveAttribute('name', initialProps.name);
30
+ });
31
+
32
+ describe('checked', () => {
33
+ it('should be `false` by default', () => {
34
+ customRender();
35
+ expect(screen.getByRole('radio')).not.toBeChecked();
36
+ });
37
+
38
+ it('should respect the prop', () => {
39
+ customRender({ checked: true });
40
+ expect(screen.getByRole('radio')).toBeChecked();
41
+ });
42
+ });
43
+
44
+ it('passes change handler to radio button', async () => {
45
+ customRender();
46
+ await userEvent.click(screen.getByRole('radio'));
47
+ expect(initialProps.onChange).toHaveBeenCalledTimes(1);
48
+ });
49
+
50
+ describe('disabled', () => {
51
+ it('should be `false` by default', () => {
52
+ customRender();
53
+ expect(screen.getByRole('radio')).toBeEnabled();
54
+ });
55
+
56
+ it('should respect the prop', () => {
57
+ customRender({ disabled: true });
58
+ expect(screen.getByRole('radio')).toBeDisabled();
59
+ });
60
+ });
61
+
62
+ describe('isContainerAligned', () => {
63
+ it('should not be aligned by default', () => {
64
+ const { container } = customRender();
65
+ expect(container.querySelector('.np-option')).not.toHaveClass('np-option__container-aligned');
66
+ });
67
+
68
+ it('renders aligned with container content', () => {
69
+ const { container } = customRender({ isContainerAligned: true });
70
+ expect(container.querySelector('.np-option')).toHaveClass('np-option__container-aligned');
71
+ });
72
+ });
73
+ });