@transferwise/components 0.0.0-experimental-4c79cff → 0.0.0-experimental-28a3dd5

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 (183) hide show
  1. package/build/avatarLayout/AvatarLayout.js +10 -4
  2. package/build/avatarLayout/AvatarLayout.js.map +1 -1
  3. package/build/avatarLayout/AvatarLayout.mjs +10 -4
  4. package/build/avatarLayout/AvatarLayout.mjs.map +1 -1
  5. package/build/button/Button.js +86 -79
  6. package/build/button/Button.js.map +1 -1
  7. package/build/button/Button.mjs +87 -80
  8. package/build/button/Button.mjs.map +1 -1
  9. package/build/button/Button.resolver.js +74 -0
  10. package/build/button/Button.resolver.js.map +1 -0
  11. package/build/button/Button.resolver.mjs +72 -0
  12. package/build/button/Button.resolver.mjs.map +1 -0
  13. package/build/button/LegacyButton.js +114 -0
  14. package/build/button/LegacyButton.js.map +1 -0
  15. package/build/button/LegacyButton.mjs +112 -0
  16. package/build/button/LegacyButton.mjs.map +1 -0
  17. package/build/criticalBanner/CriticalCommsBanner.js +2 -2
  18. package/build/criticalBanner/CriticalCommsBanner.js.map +1 -1
  19. package/build/criticalBanner/CriticalCommsBanner.mjs +1 -1
  20. package/build/header/Header.js +2 -2
  21. package/build/header/Header.js.map +1 -1
  22. package/build/header/Header.mjs +1 -1
  23. package/build/i18n/ja.json +0 -1
  24. package/build/i18n/ja.json.js +0 -1
  25. package/build/i18n/ja.json.js.map +1 -1
  26. package/build/i18n/ja.json.mjs +0 -1
  27. package/build/i18n/ja.json.mjs.map +1 -1
  28. package/build/i18n/pt.json +0 -1
  29. package/build/i18n/pt.json.js +0 -1
  30. package/build/i18n/pt.json.js.map +1 -1
  31. package/build/i18n/pt.json.mjs +0 -1
  32. package/build/i18n/pt.json.mjs.map +1 -1
  33. package/build/i18n/ru.json +0 -1
  34. package/build/i18n/ru.json.js +0 -1
  35. package/build/i18n/ru.json.js.map +1 -1
  36. package/build/i18n/ru.json.mjs +0 -1
  37. package/build/i18n/ru.json.mjs.map +1 -1
  38. package/build/i18n/zh-HK.json +0 -1
  39. package/build/i18n/zh-HK.json.js +0 -1
  40. package/build/i18n/zh-HK.json.js.map +1 -1
  41. package/build/i18n/zh-HK.json.mjs +0 -1
  42. package/build/i18n/zh-HK.json.mjs.map +1 -1
  43. package/build/index.js +2 -4
  44. package/build/index.js.map +1 -1
  45. package/build/index.mjs +1 -2
  46. package/build/index.mjs.map +1 -1
  47. package/build/link/Link.js +8 -3
  48. package/build/link/Link.js.map +1 -1
  49. package/build/link/Link.mjs +8 -3
  50. package/build/link/Link.mjs.map +1 -1
  51. package/build/main.css +227 -13
  52. package/build/nudge/Nudge.js.map +1 -1
  53. package/build/nudge/Nudge.mjs.map +1 -1
  54. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js +2 -4
  55. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js.map +1 -1
  56. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs +2 -4
  57. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs.map +1 -1
  58. package/build/primitives/PrimitiveButton/src/PrimitiveButton.js +3 -5
  59. package/build/primitives/PrimitiveButton/src/PrimitiveButton.js.map +1 -1
  60. package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs +3 -5
  61. package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs.map +1 -1
  62. package/build/select/Select.js +2 -2
  63. package/build/select/Select.js.map +1 -1
  64. package/build/select/Select.mjs +1 -1
  65. package/build/styles/avatarLayout/AvatarLayout.css +12 -2
  66. package/build/styles/button/Button.css +207 -15
  67. package/build/styles/button/Button.vars.css +46 -0
  68. package/build/styles/button/LegacyButton.css +23 -0
  69. package/build/styles/main.css +227 -13
  70. package/build/styles/nudge/Nudge.css +0 -11
  71. package/build/types/avatarLayout/AvatarLayout.d.ts.map +1 -1
  72. package/build/types/button/Button.d.ts +2 -23
  73. package/build/types/button/Button.d.ts.map +1 -1
  74. package/build/types/button/Button.resolver.d.ts +33 -0
  75. package/build/types/button/Button.resolver.d.ts.map +1 -0
  76. package/build/types/button/Button.types.d.ts +67 -0
  77. package/build/types/button/Button.types.d.ts.map +1 -0
  78. package/build/types/button/LegacyButton.d.ts +30 -0
  79. package/build/types/button/LegacyButton.d.ts.map +1 -0
  80. package/build/types/button/index.d.ts +2 -2
  81. package/build/types/button/index.d.ts.map +1 -1
  82. package/build/types/index.d.ts +0 -2
  83. package/build/types/index.d.ts.map +1 -1
  84. package/build/types/link/Link.d.ts +2 -2
  85. package/build/types/link/Link.d.ts.map +1 -1
  86. package/build/types/nudge/Nudge.d.ts +1 -1
  87. package/build/types/nudge/Nudge.d.ts.map +1 -1
  88. package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.d.ts.map +1 -1
  89. package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.d.ts +6 -2
  90. package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.d.ts.map +1 -1
  91. package/build/types/primitives/PrimitiveButton/src/PrimitiveButton.d.ts.map +1 -1
  92. package/build/types/test-utils/story-config.d.ts +1 -1
  93. package/build/types/test-utils/story-config.d.ts.map +1 -1
  94. package/build/types/uploadInput/uploadButton/getAllowedFileTypes.d.ts.map +1 -1
  95. package/build/upload/steps/completeStep/completeStep.js +2 -2
  96. package/build/upload/steps/completeStep/completeStep.js.map +1 -1
  97. package/build/upload/steps/completeStep/completeStep.mjs +1 -1
  98. package/build/upload/steps/processingStep/processingStep.js +2 -2
  99. package/build/upload/steps/processingStep/processingStep.js.map +1 -1
  100. package/build/upload/steps/processingStep/processingStep.mjs +1 -1
  101. package/build/uploadInput/UploadInput.js +3 -3
  102. package/build/uploadInput/UploadInput.js.map +1 -1
  103. package/build/uploadInput/UploadInput.mjs +1 -1
  104. package/build/uploadInput/uploadButton/getAllowedFileTypes.js +3 -23
  105. package/build/uploadInput/uploadButton/getAllowedFileTypes.js.map +1 -1
  106. package/build/uploadInput/uploadButton/getAllowedFileTypes.mjs +3 -23
  107. package/build/uploadInput/uploadButton/getAllowedFileTypes.mjs.map +1 -1
  108. package/package.json +3 -3
  109. package/src/alert/Alert.tests.story.tsx +1 -1
  110. package/src/avatarLayout/AvatarLayout.css +12 -2
  111. package/src/avatarLayout/AvatarLayout.less +19 -2
  112. package/src/avatarLayout/AvatarLayout.tsx +10 -3
  113. package/src/button/Button.css +207 -15
  114. package/src/button/Button.less +214 -14
  115. package/src/button/Button.resolver.tsx +73 -0
  116. package/src/button/Button.spec.tsx +188 -224
  117. package/src/button/Button.story.tsx +701 -135
  118. package/src/button/Button.tests.story.tsx +27 -0
  119. package/src/button/Button.tsx +99 -131
  120. package/src/button/Button.types.ts +94 -0
  121. package/src/button/Button.vars.css +46 -0
  122. package/src/button/Button.vars.less +60 -0
  123. package/src/button/LegacyButton.css +23 -0
  124. package/src/button/LegacyButton.less +24 -0
  125. package/src/button/LegacyButton.spec.tsx +147 -0
  126. package/src/button/LegacyButton.story.tsx +220 -0
  127. package/src/button/LegacyButton.tsx +160 -0
  128. package/src/button/index.ts +2 -3
  129. package/src/drawer/Drawer.rtl.spec.tsx +59 -0
  130. package/src/drawer/Drawer.spec.js +101 -0
  131. package/src/drawer/__snapshots__/Drawer.rtl.spec.tsx.snap +55 -0
  132. package/src/field/Field.story.tsx +1 -1
  133. package/src/flowNavigation/__snapshots__/FlowNavigation.spec.js.snap +1 -2
  134. package/src/i18n/ja.json +0 -1
  135. package/src/i18n/pt.json +0 -1
  136. package/src/i18n/ru.json +0 -1
  137. package/src/i18n/zh-HK.json +0 -1
  138. package/src/index.ts +0 -12
  139. package/src/inputs/SelectInput.story.tsx +1 -1
  140. package/src/label/Label.story.tsx +1 -1
  141. package/src/link/Link.tsx +15 -6
  142. package/src/main.css +227 -13
  143. package/src/main.less +1 -0
  144. package/src/nudge/Nudge.css +0 -11
  145. package/src/nudge/Nudge.less +0 -3
  146. package/src/nudge/Nudge.story.tsx +0 -10
  147. package/src/nudge/Nudge.tsx +1 -2
  148. package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.tsx +2 -8
  149. package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.ts +7 -2
  150. package/src/primitives/PrimitiveAnchor/test/PrimitiveAnchor.spec.tsx +1 -3
  151. package/src/primitives/PrimitiveButton/src/PrimitiveButton.tsx +4 -12
  152. package/src/primitives/PrimitiveButton/test/PrimitiveButton.spec.tsx +16 -13
  153. package/src/test-utils/Parameters.d.ts +9 -1
  154. package/src/test-utils/story-config.ts +10 -1
  155. package/src/uploadInput/UploadInput.tests.story.tsx +5 -5
  156. package/src/uploadInput/uploadButton/getAllowedFileTypes.spec.ts +0 -12
  157. package/src/uploadInput/uploadButton/getAllowedFileTypes.ts +7 -33
  158. package/build/table/Table.js +0 -166
  159. package/build/table/Table.js.map +0 -1
  160. package/build/table/Table.messages.js +0 -24
  161. package/build/table/Table.messages.js.map +0 -1
  162. package/build/table/Table.messages.mjs +0 -22
  163. package/build/table/Table.messages.mjs.map +0 -1
  164. package/build/table/Table.mjs +0 -164
  165. package/build/table/Table.mjs.map +0 -1
  166. package/build/table/TableCell.js +0 -86
  167. package/build/table/TableCell.js.map +0 -1
  168. package/build/table/TableCell.mjs +0 -84
  169. package/build/table/TableCell.mjs.map +0 -1
  170. package/build/table/TableHeader.js +0 -57
  171. package/build/table/TableHeader.js.map +0 -1
  172. package/build/table/TableHeader.mjs +0 -55
  173. package/build/table/TableHeader.mjs.map +0 -1
  174. package/build/table/TableRow.js +0 -85
  175. package/build/table/TableRow.js.map +0 -1
  176. package/build/table/TableRow.mjs +0 -83
  177. package/build/table/TableRow.mjs.map +0 -1
  178. package/build/table/TableStatusText.js +0 -54
  179. package/build/table/TableStatusText.js.map +0 -1
  180. package/build/table/TableStatusText.mjs +0 -52
  181. package/build/table/TableStatusText.mjs.map +0 -1
  182. package/src/button/__snapshots__/Button.spec.tsx.snap +0 -309
  183. package/src/drawer/Drawer.spec.tsx +0 -93
@@ -1,246 +1,210 @@
1
- import { createRef } from 'react';
2
-
3
- import { ControlType, Type, Priority, Size } from '../common';
4
- import { render, screen, userEvent } from '../test-utils';
5
-
6
- import Button from '.';
7
- import messages from '../i18n/commonMessages/Button.messages';
8
- import { ButtonReferenceType } from './Button';
9
-
10
- const { ACCENT, POSITIVE, NEGATIVE } = ControlType;
11
- const { PAY, LINK, DANGER } = Type;
12
- const { PRIMARY, SECONDARY, TERTIARY } = Priority;
13
- const { SMALL, MEDIUM, LARGE } = Size;
1
+ import { render, screen } from '../test-utils';
2
+ import Button, { ButtonProps } from './Button.resolver';
14
3
 
15
4
  describe('Button', () => {
16
- // eslint-disable-next-line no-console
17
- const originalWarn = console.warn;
18
- let mockedWarn: typeof originalWarn;
19
-
20
- const props = {
21
- onClick: jest.fn(),
22
- onFocus: jest.fn(),
23
- onBlur: jest.fn(),
24
- children: 'Send money',
5
+ const legacyProps: ButtonProps = {
6
+ as: 'button',
7
+ priority: 'primary',
8
+ size: 'md',
9
+ type: 'accent',
25
10
  };
26
11
 
27
- beforeAll(() => {
28
- mockedWarn = jest.fn().mockImplementation((args) => {
29
- if (typeof args !== 'string' || !args.startsWith('Button has deprecated the')) {
30
- originalWarn(args);
31
- }
32
- });
33
- // eslint-disable-next-line no-console
34
- console.warn = mockedWarn;
35
- });
36
-
37
- beforeEach(jest.clearAllMocks);
38
-
39
- afterAll(() => {
40
- // eslint-disable-next-line no-console
41
- console.warn = originalWarn;
42
- });
43
-
44
- describe('by default', () => {
45
- it('renders the text', () => {
46
- render(<Button {...props} />);
47
- expect(screen.getByText(props.children)).toBeInTheDocument();
48
- });
49
-
50
- it('set `ref` to be true on Button', () => {
51
- const reference = createRef<ButtonReferenceType>();
52
-
53
- expect(reference.current).toBeFalsy();
54
- render(<Button ref={reference}>Click me!</Button>);
55
- expect(reference.current).toBeTruthy();
56
- });
57
-
58
- it('is not disabled', () => {
59
- render(<Button {...props} />);
60
- expect(screen.getByRole('button')).toBeEnabled();
61
- });
62
-
63
- it('renders a medium button of type accent and priority primary', () => {
64
- expect(render(<Button {...props} />).container).toMatchSnapshot();
65
- });
66
-
67
- it('renders an anchor tag with button styles of type accent and priority primary', () => {
68
- expect(render(<Button {...props} as="a" href="#" />).container).toMatchSnapshot();
69
- });
70
- });
71
-
72
- describe('button attributes', () => {
73
- it('sets the htmlType if set', () => {
74
- render(<Button {...props} htmlType="submit" />);
75
- expect(screen.getByRole('button')).toHaveAttribute('type', 'submit');
76
- });
77
-
78
- it('passes through custom classes if set', () => {
79
- render(<Button {...props} className="donkeysarethebest" />);
80
- expect(screen.getByRole('button')).toHaveClass('donkeysarethebest');
81
- });
82
-
83
- it('passes through aria-label if set', () => {
84
- render(<Button {...props} aria-label="unique label" />);
85
- const loadingButton = screen.getByLabelText('unique label');
86
- expect(loadingButton).toBeInTheDocument();
87
- });
88
- });
89
-
90
- describe('onClick', () => {
91
- it('calls onClick when clicked', async () => {
92
- render(<Button {...props} />);
93
- await userEvent.click(screen.getByRole('button'));
94
- expect(props.onClick).toHaveBeenCalledTimes(1);
95
- });
96
-
97
- it('does not call onClick when clicked if disabled', async () => {
98
- render(<Button {...props} disabled />);
99
- await userEvent.click(screen.getByRole('button'));
100
- expect(props.onClick).toHaveBeenCalledTimes(0);
101
- });
102
-
103
- it('does not call onClick when clicked if loading', async () => {
104
- render(<Button {...props} loading />);
105
- await userEvent.click(screen.getByRole('button'));
106
- expect(props.onClick).toHaveBeenCalledTimes(0);
107
- });
108
- });
109
-
110
- describe('onFocus and onBlur', () => {
111
- it('calls both handlers by default', async () => {
112
- render(<Button {...props} />);
113
- await userEvent.tab();
114
- expect(props.onFocus).toHaveBeenCalledTimes(1);
115
- await userEvent.tab();
116
- expect(props.onFocus).toHaveBeenCalledTimes(1);
117
- });
118
-
119
- it('does not call either handler if disabled', async () => {
120
- render(<Button {...props} disabled />);
121
- await userEvent.tab();
122
- expect(props.onFocus).not.toHaveBeenCalled();
123
- await userEvent.tab();
124
- expect(props.onFocus).not.toHaveBeenCalled();
125
- });
126
-
127
- it('calls both handlers if loading', async () => {
128
- render(<Button {...props} loading />);
129
- await userEvent.tab();
130
- expect(props.onFocus).toHaveBeenCalledTimes(1);
131
- await userEvent.tab();
132
- expect(props.onFocus).toHaveBeenCalledTimes(1);
133
- });
134
- });
135
-
136
- describe('sizes', () => {
137
- it('renders small buttons', () => {
138
- expect(render(<Button {...props} size={SMALL} />).container).toMatchSnapshot();
139
- });
12
+ const newProps: ButtonProps = {
13
+ as: 'button',
14
+ v2: true,
15
+ priority: 'primary',
16
+ size: 'md',
17
+ };
140
18
 
141
- it('renders medium buttons', () => {
142
- expect(render(<Button {...props} size={MEDIUM} />).container).toMatchSnapshot();
143
- });
19
+ const testId = 'new-button';
144
20
 
145
- it('renders large buttons', () => {
146
- expect(render(<Button {...props} size={LARGE} />).container).toMatchSnapshot();
147
- });
21
+ it('renders LegacyButton when v2 is false', () => {
22
+ render(<Button {...legacyProps}>Legacy Button</Button>);
23
+ const button = screen.getByText('Legacy Button');
24
+ expect(button).toBeInTheDocument();
25
+ expect(button).toHaveClass('btn btn-md np-btn np-btn-md btn-accent btn-priority-1');
148
26
  });
149
27
 
150
- describe('types', () => {
151
- it('renders accent buttons', () => {
152
- expect(render(<Button {...props} type={ACCENT} />).container).toMatchSnapshot();
153
- });
154
-
155
- it('renders positive buttons', () => {
156
- expect(render(<Button {...props} type={POSITIVE} />).container).toMatchSnapshot();
157
- });
158
-
159
- it('renders negative buttons', () => {
160
- expect(render(<Button {...props} type={NEGATIVE} />).container).toMatchSnapshot();
161
- });
28
+ it('renders the new Button when v2 is true', () => {
29
+ render(
30
+ <Button data-testid={testId} {...newProps}>
31
+ New Button
32
+ </Button>,
33
+ );
34
+ const button = screen.getByTestId('new-button');
35
+ expect(button).toBeInTheDocument();
36
+ expect(button).toHaveClass('wds-Button wds-Button--medium wds-Button--primary');
162
37
  });
163
38
 
164
- describe('priorities', () => {
165
- it('renders primary buttons', () => {
166
- [ACCENT, POSITIVE, NEGATIVE].forEach((type) =>
167
- expect(
168
- render(<Button {...props} priority={PRIMARY} type={type} />).container,
169
- ).toMatchSnapshot(),
170
- );
171
- });
172
-
173
- it('renders secondary buttons', () => {
174
- [ACCENT, POSITIVE, NEGATIVE].forEach((type) =>
175
- expect(
176
- render(<Button {...props} priority={SECONDARY} type={type} />).container,
177
- ).toMatchSnapshot(),
178
- );
179
- });
39
+ describe('render as HTML anchor', () => {
40
+ const href = 'https://example.com';
41
+ const name = 'Button as link';
180
42
 
181
- it('renders tertiary buttons', () => {
182
- expect(
183
- render(<Button {...props} priority={TERTIARY} type={ACCENT} />).container,
184
- ).toMatchSnapshot();
185
- });
43
+ describe('v2', () => {
44
+ it('should render as button by default', () => {
45
+ render(<Button v2>{name}</Button>);
46
+ expect(screen.getByRole('button', { name })).toBeInTheDocument();
47
+ });
48
+ it('should render as link if href is provided', () => {
49
+ render(
50
+ <Button v2 href={href}>
51
+ {name}
52
+ </Button>,
53
+ );
54
+ expect(screen.getByRole('link', { name })).toHaveAttribute('href', href);
55
+ });
186
56
 
187
- it('defaults tertiary buttons to secondary for positive buttons', () => {
188
- [POSITIVE, NEGATIVE].forEach((type) =>
189
- expect(
190
- render(<Button {...props} priority={TERTIARY} type={type} />).container,
191
- ).toMatchSnapshot(),
192
- );
193
- });
194
- });
57
+ it('should render as link if `as="a"` is provided', () => {
58
+ render(
59
+ <Button v2 as="a">
60
+ {name}
61
+ </Button>,
62
+ );
63
+ expect(screen.getByText(name).closest('a')).toBeInTheDocument();
64
+ });
195
65
 
196
- describe('other states', () => {
197
- it('renders as loading if `loading` is true', () => {
198
- render(<Button {...props} loading />);
199
- const button = screen.queryByRole('button', {
200
- name: messages.loadingAriaLabel.defaultMessage,
66
+ it('should render as link if href is set and `as="button"`', () => {
67
+ render(
68
+ <Button v2 href={href} as="button">
69
+ {name}
70
+ </Button>,
71
+ );
72
+ expect(screen.getByRole('link', { name })).toHaveAttribute('href', href);
201
73
  });
202
- expect(button).toBeInTheDocument();
203
- expect(button).toBeEnabled();
204
- expect(button).toHaveClass('btn-loading');
205
- expect(button).toHaveAttribute('aria-disabled', 'true');
206
- expect(button).toHaveAttribute('aria-busy', 'true');
207
- expect(button).toHaveAttribute('aria-live', 'polite');
208
- expect(screen.getByTestId('ButtonProgressIndicator')).toBeInTheDocument();
209
- });
210
74
 
211
- it('disables the button', () => {
212
- render(<Button {...props} disabled />);
213
- const button = screen.queryByRole('button');
214
- expect(button).toBeDisabled();
215
- expect(button).toHaveClass('disabled');
216
- expect(button).toHaveAttribute('aria-disabled', 'false');
217
- expect(button).toHaveAttribute('aria-busy', 'false');
218
- expect(button).toHaveAttribute('aria-live', 'off');
219
- });
75
+ describe('disabled mode', () => {
76
+ describe('button', () => {
77
+ it('should not be disabled by default', () => {
78
+ render(<Button v2>{name}</Button>);
79
+ const button = screen.getByRole('button');
80
+ expect(button).toBeEnabled();
81
+ expect(button).not.toHaveAttribute('aria-disabled');
82
+ });
83
+
84
+ it('should respect disabled mode and set it only via the `disabled` attribute', () => {
85
+ render(
86
+ <Button v2 disabled>
87
+ {name}
88
+ </Button>,
89
+ );
90
+ const button = screen.getByRole('button');
91
+ expect(button).toBeDisabled();
92
+ expect(button).not.toHaveAttribute('aria-disabled');
93
+ });
94
+ });
95
+
96
+ describe('anchor', () => {
97
+ it('should not be disabled by default', () => {
98
+ render(
99
+ <Button v2 href="wise.com">
100
+ {name}
101
+ </Button>,
102
+ );
103
+ const button = screen.getByRole('link');
104
+ expect(button).toBeEnabled();
105
+ expect(button).not.toHaveAttribute('aria-disabled');
106
+ });
107
+
108
+ it('should respect disabled mode', () => {
109
+ render(
110
+ <Button v2 href="wise.com" disabled>
111
+ {name}
112
+ </Button>,
113
+ );
114
+ const button = screen.getByRole('link');
115
+ expect(button).toHaveAttribute('aria-disabled');
116
+ expect(button).toBeEnabled();
117
+ expect(button).not.toHaveAttribute('href');
118
+ });
119
+ });
120
+ });
220
121
 
221
- it('renders as block if block is true', () => {
222
- expect(render(<Button {...props} block />).container).toMatchSnapshot();
122
+ describe('loading mode', () => {
123
+ describe('button', () => {
124
+ it('should not be loading by default', () => {
125
+ render(<Button v2>{name}</Button>);
126
+ const button = screen.getByRole('button');
127
+ expect(button).toBeEnabled();
128
+ expect(button).not.toHaveAttribute('aria-busy');
129
+ });
130
+
131
+ it('should respect loading mode', () => {
132
+ render(
133
+ <Button v2 loading>
134
+ {name}
135
+ </Button>,
136
+ );
137
+ const button = screen.getByRole('button');
138
+ expect(button).toHaveAttribute('aria-busy');
139
+ // the `disabled` attribute is not set to keep the button
140
+ // focusable but aria attribute is defined to make it
141
+ // announced properly by the assistive tech
142
+ expect(button).toBeEnabled();
143
+ expect(button).toHaveAttribute('aria-disabled');
144
+ });
145
+ });
146
+
147
+ describe('anchor', () => {
148
+ it('should not be loading by default', () => {
149
+ render(
150
+ <Button v2 href="wise.com">
151
+ {name}
152
+ </Button>,
153
+ );
154
+ const button = screen.getByRole('link');
155
+ expect(button).toBeEnabled();
156
+ expect(button).not.toHaveAttribute('aria-busy');
157
+ expect(button).not.toHaveAttribute('aria-disabled');
158
+ });
159
+
160
+ it('should respect loading mode', () => {
161
+ render(
162
+ <Button v2 loading href="wise.com">
163
+ {name}
164
+ </Button>,
165
+ );
166
+ const button = screen.getByRole('link');
167
+ expect(button).toHaveAttribute('aria-busy');
168
+ // the `disabled` attribute is not set to keep the button
169
+ // focusable but aria attribute is defined to make it
170
+ // announced properly by the assistive tech
171
+ expect(button).toBeEnabled();
172
+ expect(button).toHaveAttribute('aria-disabled');
173
+ expect(button).not.toHaveAttribute('href');
174
+ });
175
+ });
176
+ });
223
177
  });
224
178
  });
225
179
 
226
- describe('deprecated types', () => {
227
- it('renders primary as accent buttons and logs a warning', () => {
228
- expect(render(<Button {...props} type={PRIMARY} />).container).toMatchSnapshot();
229
- expect(mockedWarn).toHaveBeenCalledTimes(1);
230
- });
231
-
232
- it('renders pay as positive buttons and logs a warning', () => {
233
- expect(render(<Button {...props} type={PAY} />).container).toMatchSnapshot();
234
- expect(mockedWarn).toHaveBeenCalledTimes(1);
235
- });
236
-
237
- it('renders danger as negative buttons with priority secondary and logs a warning', () => {
238
- expect(render(<Button {...props} type={DANGER} />).container).toMatchSnapshot();
239
- expect(mockedWarn).toHaveBeenCalledTimes(1);
240
- });
180
+ it('does not set type when type is in LegacyButtonType', () => {
181
+ const legacyTypeProps: ButtonProps = {
182
+ ...newProps,
183
+ // @ts-expect-error here we intentionally set wrong value to test `type` attr in DOM
184
+ type: 'accent',
185
+ };
186
+ render(
187
+ <Button data-testid={testId} {...legacyTypeProps}>
188
+ Button Type
189
+ </Button>,
190
+ );
191
+ const button = screen.getByTestId('new-button');
192
+ expect(button).toBeInTheDocument();
193
+ expect(button).not.toHaveAttribute('type');
194
+ });
241
195
 
242
- it('renders link as accent buttons with priority tertiary and logs a warning', () => {
243
- expect(render(<Button {...props} type={LINK} />).container).toMatchSnapshot();
244
- });
196
+ it('sets type when type is not in LegacyButtonType', () => {
197
+ const buttonTypeProps: ButtonProps = {
198
+ ...newProps,
199
+ type: 'submit',
200
+ };
201
+ render(
202
+ <Button data-testid={testId} {...buttonTypeProps}>
203
+ Submit Button
204
+ </Button>,
205
+ );
206
+ const button = screen.getByTestId('new-button');
207
+ expect(button).toBeInTheDocument();
208
+ expect(button).toHaveAttribute('type', 'submit');
245
209
  });
246
210
  });