@transferwise/components 0.0.0-experimental-28eac06 → 0.0.0-experimental-9b6d886

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 (202) hide show
  1. package/build/alert/Alert.js +17 -17
  2. package/build/alert/Alert.js.map +1 -1
  3. package/build/alert/Alert.mjs +14 -14
  4. package/build/alert/Alert.mjs.map +1 -1
  5. package/build/avatarLayout/AvatarLayout.js +2 -9
  6. package/build/avatarLayout/AvatarLayout.js.map +1 -1
  7. package/build/avatarLayout/AvatarLayout.mjs +2 -9
  8. package/build/avatarLayout/AvatarLayout.mjs.map +1 -1
  9. package/build/button/Button.js +79 -86
  10. package/build/button/Button.js.map +1 -1
  11. package/build/button/Button.mjs +80 -87
  12. package/build/button/Button.mjs.map +1 -1
  13. package/build/circularButton/CircularButton.js.map +1 -1
  14. package/build/circularButton/CircularButton.mjs.map +1 -1
  15. package/build/common/action/Action.js +15 -26
  16. package/build/common/action/Action.js.map +1 -1
  17. package/build/common/action/Action.mjs +15 -26
  18. package/build/common/action/Action.mjs.map +1 -1
  19. package/build/common/propsValues/sentiment.js +0 -1
  20. package/build/common/propsValues/sentiment.js.map +1 -1
  21. package/build/common/propsValues/sentiment.mjs +0 -1
  22. package/build/common/propsValues/sentiment.mjs.map +1 -1
  23. package/build/criticalBanner/CriticalCommsBanner.js +73 -10
  24. package/build/criticalBanner/CriticalCommsBanner.js.map +1 -1
  25. package/build/criticalBanner/CriticalCommsBanner.mjs +74 -11
  26. package/build/criticalBanner/CriticalCommsBanner.mjs.map +1 -1
  27. package/build/header/Header.js +2 -2
  28. package/build/header/Header.js.map +1 -1
  29. package/build/header/Header.mjs +1 -1
  30. package/build/i18n/en.json +0 -1
  31. package/build/i18n/en.json.js +0 -1
  32. package/build/i18n/en.json.js.map +1 -1
  33. package/build/i18n/en.json.mjs +0 -1
  34. package/build/i18n/en.json.mjs.map +1 -1
  35. package/build/i18n/ja.json +1 -0
  36. package/build/i18n/ja.json.js +1 -0
  37. package/build/i18n/ja.json.js.map +1 -1
  38. package/build/i18n/ja.json.mjs +1 -0
  39. package/build/i18n/ja.json.mjs.map +1 -1
  40. package/build/i18n/pt.json +1 -0
  41. package/build/i18n/pt.json.js +1 -0
  42. package/build/i18n/pt.json.js.map +1 -1
  43. package/build/i18n/pt.json.mjs +1 -0
  44. package/build/i18n/pt.json.mjs.map +1 -1
  45. package/build/i18n/ru.json +1 -0
  46. package/build/i18n/ru.json.js +1 -0
  47. package/build/i18n/ru.json.js.map +1 -1
  48. package/build/i18n/ru.json.mjs +1 -0
  49. package/build/i18n/ru.json.mjs.map +1 -1
  50. package/build/i18n/zh-HK.json +1 -0
  51. package/build/i18n/zh-HK.json.js +1 -0
  52. package/build/i18n/zh-HK.json.js.map +1 -1
  53. package/build/i18n/zh-HK.json.mjs +1 -0
  54. package/build/i18n/zh-HK.json.mjs.map +1 -1
  55. package/build/index.js +2 -2
  56. package/build/index.mjs +1 -1
  57. package/build/link/Link.js +3 -8
  58. package/build/link/Link.js.map +1 -1
  59. package/build/link/Link.mjs +3 -8
  60. package/build/link/Link.mjs.map +1 -1
  61. package/build/main.css +70 -267
  62. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js +4 -2
  63. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js.map +1 -1
  64. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs +4 -2
  65. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs.map +1 -1
  66. package/build/primitives/PrimitiveButton/src/PrimitiveButton.js +5 -3
  67. package/build/primitives/PrimitiveButton/src/PrimitiveButton.js.map +1 -1
  68. package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs +5 -3
  69. package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs.map +1 -1
  70. package/build/select/Select.js +2 -2
  71. package/build/select/Select.js.map +1 -1
  72. package/build/select/Select.mjs +1 -1
  73. package/build/statusIcon/StatusIcon.js +1 -5
  74. package/build/statusIcon/StatusIcon.js.map +1 -1
  75. package/build/statusIcon/StatusIcon.messages.js +0 -3
  76. package/build/statusIcon/StatusIcon.messages.js.map +1 -1
  77. package/build/statusIcon/StatusIcon.messages.mjs +0 -3
  78. package/build/statusIcon/StatusIcon.messages.mjs.map +1 -1
  79. package/build/statusIcon/StatusIcon.mjs +1 -5
  80. package/build/statusIcon/StatusIcon.mjs.map +1 -1
  81. package/build/styles/avatarLayout/AvatarLayout.css +0 -11
  82. package/build/styles/button/Button.css +15 -230
  83. package/build/styles/criticalBanner/CriticalCommsBanner.css +73 -21
  84. package/build/styles/main.css +70 -267
  85. package/build/types/alert/Alert.d.ts +4 -3
  86. package/build/types/alert/Alert.d.ts.map +1 -1
  87. package/build/types/avatarLayout/AvatarLayout.d.ts.map +1 -1
  88. package/build/types/button/Button.d.ts +23 -2
  89. package/build/types/button/Button.d.ts.map +1 -1
  90. package/build/types/button/index.d.ts +2 -2
  91. package/build/types/button/index.d.ts.map +1 -1
  92. package/build/types/circularButton/CircularButton.d.ts.map +1 -1
  93. package/build/types/common/action/Action.d.ts +2 -5
  94. package/build/types/common/action/Action.d.ts.map +1 -1
  95. package/build/types/common/propsValues/sentiment.d.ts +0 -1
  96. package/build/types/common/propsValues/sentiment.d.ts.map +1 -1
  97. package/build/types/criticalBanner/CriticalCommsBanner.d.ts.map +1 -1
  98. package/build/types/index.d.ts +1 -0
  99. package/build/types/index.d.ts.map +1 -1
  100. package/build/types/link/Link.d.ts +2 -2
  101. package/build/types/link/Link.d.ts.map +1 -1
  102. package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.d.ts.map +1 -1
  103. package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.d.ts +2 -6
  104. package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.d.ts.map +1 -1
  105. package/build/types/primitives/PrimitiveButton/src/PrimitiveButton.d.ts.map +1 -1
  106. package/build/types/statusIcon/StatusIcon.d.ts.map +1 -1
  107. package/build/types/statusIcon/StatusIcon.messages.d.ts +0 -5
  108. package/build/types/statusIcon/StatusIcon.messages.d.ts.map +1 -1
  109. package/build/types/test-utils/index.d.ts +0 -2
  110. package/build/types/test-utils/index.d.ts.map +1 -1
  111. package/build/types/test-utils/story-config.d.ts +1 -1
  112. package/build/types/test-utils/story-config.d.ts.map +1 -1
  113. package/build/upload/steps/completeStep/completeStep.js +2 -2
  114. package/build/upload/steps/completeStep/completeStep.js.map +1 -1
  115. package/build/upload/steps/completeStep/completeStep.mjs +1 -1
  116. package/build/upload/steps/processingStep/processingStep.js +2 -2
  117. package/build/upload/steps/processingStep/processingStep.js.map +1 -1
  118. package/build/upload/steps/processingStep/processingStep.mjs +1 -1
  119. package/build/uploadInput/UploadInput.js +3 -3
  120. package/build/uploadInput/UploadInput.js.map +1 -1
  121. package/build/uploadInput/UploadInput.mjs +1 -1
  122. package/package.json +3 -3
  123. package/src/alert/Alert.spec.tsx +30 -0
  124. package/src/alert/Alert.story.tsx +1 -34
  125. package/src/alert/Alert.tests.story.tsx +1 -1
  126. package/src/alert/Alert.tsx +15 -20
  127. package/src/avatarLayout/AvatarLayout.css +0 -11
  128. package/src/avatarLayout/AvatarLayout.less +1 -18
  129. package/src/avatarLayout/AvatarLayout.tsx +2 -10
  130. package/src/button/Button.css +15 -230
  131. package/src/button/Button.less +14 -242
  132. package/src/button/Button.spec.tsx +226 -215
  133. package/src/button/Button.story.tsx +134 -761
  134. package/src/button/Button.tsx +132 -103
  135. package/src/button/__snapshots__/Button.spec.tsx.snap +309 -0
  136. package/src/button/index.ts +3 -2
  137. package/src/circularButton/CircularButton.tsx +0 -1
  138. package/src/common/action/Action.tsx +22 -40
  139. package/src/common/propsValues/sentiment.ts +0 -1
  140. package/src/criticalBanner/CriticalCommsBanner.css +73 -21
  141. package/src/criticalBanner/CriticalCommsBanner.less +70 -24
  142. package/src/criticalBanner/CriticalCommsBanner.story.tsx +4 -26
  143. package/src/criticalBanner/CriticalCommsBanner.tsx +50 -8
  144. package/src/field/Field.story.tsx +1 -1
  145. package/src/flowNavigation/__snapshots__/FlowNavigation.spec.js.snap +2 -1
  146. package/src/i18n/en.json +0 -1
  147. package/src/i18n/ja.json +1 -0
  148. package/src/i18n/pt.json +1 -0
  149. package/src/i18n/ru.json +1 -0
  150. package/src/i18n/zh-HK.json +1 -0
  151. package/src/index.ts +1 -0
  152. package/src/inputs/SelectInput.story.tsx +1 -1
  153. package/src/label/Label.story.tsx +1 -1
  154. package/src/link/Link.tsx +6 -15
  155. package/src/main.css +70 -267
  156. package/src/main.less +0 -1
  157. package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.tsx +8 -2
  158. package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.ts +2 -7
  159. package/src/primitives/PrimitiveAnchor/test/PrimitiveAnchor.spec.tsx +3 -1
  160. package/src/primitives/PrimitiveButton/src/PrimitiveButton.tsx +12 -4
  161. package/src/primitives/PrimitiveButton/test/PrimitiveButton.spec.tsx +13 -16
  162. package/src/radio/Radio.spec.tsx +73 -0
  163. package/src/radio/Radio.story.tsx +22 -52
  164. package/src/radioGroup/RadioGroup.spec.tsx +91 -0
  165. package/src/radioGroup/RadioGroup.story.tsx +3 -5
  166. package/src/statusIcon/StatusIcon.less +0 -1
  167. package/src/statusIcon/StatusIcon.messages.ts +0 -6
  168. package/src/statusIcon/StatusIcon.tsx +1 -8
  169. package/src/test-utils/Parameters.d.ts +1 -9
  170. package/src/test-utils/story-config.ts +1 -10
  171. package/build/button/Button.resolver.js +0 -74
  172. package/build/button/Button.resolver.js.map +0 -1
  173. package/build/button/Button.resolver.mjs +0 -72
  174. package/build/button/Button.resolver.mjs.map +0 -1
  175. package/build/button/LegacyButton.js +0 -114
  176. package/build/button/LegacyButton.js.map +0 -1
  177. package/build/button/LegacyButton.mjs +0 -112
  178. package/build/button/LegacyButton.mjs.map +0 -1
  179. package/build/styles/button/Button.vars.css +0 -46
  180. package/build/styles/button/LegacyButton.css +0 -23
  181. package/build/types/button/Button.resolver.d.ts +0 -35
  182. package/build/types/button/Button.resolver.d.ts.map +0 -1
  183. package/build/types/button/Button.types.d.ts +0 -70
  184. package/build/types/button/Button.types.d.ts.map +0 -1
  185. package/build/types/button/LegacyButton.d.ts +0 -44
  186. package/build/types/button/LegacyButton.d.ts.map +0 -1
  187. package/src/button/Button.accessibility.docs.mdx +0 -103
  188. package/src/button/Button.resolver.tsx +0 -73
  189. package/src/button/Button.tests.story.tsx +0 -27
  190. package/src/button/Button.types.ts +0 -92
  191. package/src/button/Button.vars.css +0 -46
  192. package/src/button/Button.vars.less +0 -55
  193. package/src/button/LegacyButton.css +0 -23
  194. package/src/button/LegacyButton.less +0 -24
  195. package/src/button/LegacyButton.spec.tsx +0 -147
  196. package/src/button/LegacyButton.story.tsx +0 -228
  197. package/src/button/LegacyButton.tsx +0 -177
  198. package/src/radio/Radio.rtl.spec.tsx +0 -24
  199. package/src/radio/Radio.spec.js +0 -76
  200. package/src/radio/__snapshots__/Radio.rtl.spec.tsx.snap +0 -49
  201. package/src/radioGroup/RadioGroup.rtl.spec.tsx +0 -30
  202. package/src/radioGroup/RadioGroup.spec.js +0 -90
@@ -1,235 +1,246 @@
1
- import { render, screen } from '../test-utils';
2
- import Button, { ButtonProps } from './Button.resolver';
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;
3
14
 
4
15
  describe('Button', () => {
5
- const legacyProps: ButtonProps = {
6
- as: 'button',
7
- priority: 'primary',
8
- size: 'md',
9
- type: 'accent',
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',
10
25
  };
11
26
 
12
- const newProps: ButtonProps = {
13
- as: 'button',
14
- v2: true,
15
- priority: 'primary',
16
- size: 'md',
17
- };
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
+ });
18
36
 
19
- const testId = 'new-button';
37
+ beforeEach(jest.clearAllMocks);
20
38
 
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');
39
+ afterAll(() => {
40
+ // eslint-disable-next-line no-console
41
+ console.warn = originalWarn;
26
42
  });
27
43
 
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');
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
+ });
37
70
  });
38
71
 
39
- describe('render as HTML anchor', () => {
40
- const href = 'https://example.com';
41
- const name = 'Button as link';
42
-
43
- describe('v2', () => {
44
- describe('rendered HTMLS element', () => {
45
- it('should render as button by default', () => {
46
- render(<Button v2>{name}</Button>);
47
- expect(screen.getByRole('button', { name })).toBeInTheDocument();
48
- });
49
-
50
- it('should render as link if href is provided', () => {
51
- render(
52
- <Button v2 href={href}>
53
- {name}
54
- </Button>,
55
- );
56
- expect(screen.getByRole('link', { name })).toHaveAttribute('href', href);
57
- });
58
-
59
- it('should render a HTML anchor if `as="a"` is provided', () => {
60
- render(
61
- <Button v2 as="a">
62
- {name}
63
- </Button>,
64
- );
65
- expect(screen.getByText(name).closest('a')).toBeInTheDocument();
66
- });
67
-
68
- it('should render as a button if `href` is set together with `as="button"`', () => {
69
- render(
70
- <Button v2 href={href} as="button">
71
- {name}
72
- </Button>,
73
- );
74
- expect(screen.getByRole('button', { name })).toBeInTheDocument();
75
- });
76
- });
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
77
 
78
- describe('HTML attributes', () => {
79
- it('should not set `type` if rendered as HTML anchor', () => {
80
- render(
81
- <Button v2 type="submit" href="wise.com">
82
- {name}
83
- </Button>,
84
- );
85
- expect(screen.getByRole('link')).not.toHaveAttribute('type');
86
- });
87
-
88
- it('should not set `href` or `target` if rendered as HTML button', () => {
89
- render(
90
- <Button v2 as="button" href="wise.com" target="_blank">
91
- {name}
92
- </Button>,
93
- );
94
- const button = screen.getByRole('button');
95
- expect(button).not.toHaveAttribute('href');
96
- expect(button).not.toHaveAttribute('target');
97
- });
98
- });
78
+ it('passes through custom classes if set', () => {
79
+ render(<Button {...props} className="donkeysarethebest" />);
80
+ expect(screen.getByRole('button')).toHaveClass('donkeysarethebest');
81
+ });
99
82
 
100
- describe('disabled mode', () => {
101
- describe('button', () => {
102
- it('should not be disabled by default', () => {
103
- render(<Button v2>{name}</Button>);
104
- const button = screen.getByRole('button');
105
- expect(button).toBeEnabled();
106
- expect(button).not.toHaveAttribute('aria-disabled');
107
- });
108
-
109
- it('should respect disabled mode and set it only via the `disabled` attribute', () => {
110
- render(
111
- <Button v2 disabled>
112
- {name}
113
- </Button>,
114
- );
115
- const button = screen.getByRole('button');
116
- expect(button).toBeDisabled();
117
- expect(button).not.toHaveAttribute('aria-disabled');
118
- });
119
- });
120
-
121
- describe('anchor', () => {
122
- it('should not be disabled by default', () => {
123
- render(
124
- <Button v2 href="wise.com">
125
- {name}
126
- </Button>,
127
- );
128
- const button = screen.getByRole('link');
129
- expect(button).toBeEnabled();
130
- expect(button).not.toHaveAttribute('aria-disabled');
131
- });
132
-
133
- it('should respect disabled mode', () => {
134
- render(
135
- <Button v2 href="wise.com" disabled>
136
- {name}
137
- </Button>,
138
- );
139
- const button = screen.getByRole('link');
140
- expect(button).toHaveAttribute('aria-disabled');
141
- expect(button).toBeEnabled();
142
- expect(button).not.toHaveAttribute('href');
143
- });
144
- });
145
- });
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
+ });
146
89
 
147
- describe('loading mode', () => {
148
- describe('button', () => {
149
- it('should not be loading by default', () => {
150
- render(<Button v2>{name}</Button>);
151
- const button = screen.getByRole('button');
152
- expect(button).toBeEnabled();
153
- expect(button).not.toHaveAttribute('aria-busy');
154
- });
155
-
156
- it('should respect loading mode', () => {
157
- render(
158
- <Button v2 loading>
159
- {name}
160
- </Button>,
161
- );
162
- const button = screen.getByRole('button');
163
- expect(button).toHaveAttribute('aria-busy');
164
- // the `disabled` attribute is not set to keep the button
165
- // focusable but aria attribute is defined to make it
166
- // announced properly by the assistive tech
167
- expect(button).toBeEnabled();
168
- expect(button).toHaveAttribute('aria-disabled');
169
- });
170
- });
171
-
172
- describe('anchor', () => {
173
- it('should not be loading by default', () => {
174
- render(
175
- <Button v2 href="wise.com">
176
- {name}
177
- </Button>,
178
- );
179
- const button = screen.getByRole('link');
180
- expect(button).toBeEnabled();
181
- expect(button).not.toHaveAttribute('aria-busy');
182
- expect(button).not.toHaveAttribute('aria-disabled');
183
- });
184
-
185
- it('should respect loading mode', () => {
186
- render(
187
- <Button v2 loading href="wise.com">
188
- {name}
189
- </Button>,
190
- );
191
- const button = screen.getByRole('link');
192
- expect(button).toHaveAttribute('aria-busy');
193
- // the `disabled` attribute is not set to keep the button
194
- // focusable but aria attribute is defined to make it
195
- // announced properly by the assistive tech
196
- expect(button).toBeEnabled();
197
- expect(button).toHaveAttribute('aria-disabled');
198
- expect(button).not.toHaveAttribute('href');
199
- });
200
- });
201
- });
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);
202
107
  });
203
108
  });
204
109
 
205
- it('does not set type when type is in LegacyButtonType', () => {
206
- const legacyTypeProps: ButtonProps = {
207
- ...newProps,
208
- // @ts-expect-error here we intentionally set wrong value to test `type` attr in DOM
209
- type: 'accent',
210
- };
211
- render(
212
- <Button data-testid={testId} {...legacyTypeProps}>
213
- Button Type
214
- </Button>,
215
- );
216
- const button = screen.getByTestId('new-button');
217
- expect(button).toBeInTheDocument();
218
- expect(button).not.toHaveAttribute('type');
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
+ });
219
134
  });
220
135
 
221
- it('sets type when type is not in LegacyButtonType', () => {
222
- const buttonTypeProps: ButtonProps = {
223
- ...newProps,
224
- type: 'submit',
225
- };
226
- render(
227
- <Button data-testid={testId} {...buttonTypeProps}>
228
- Submit Button
229
- </Button>,
230
- );
231
- const button = screen.getByTestId('new-button');
232
- expect(button).toBeInTheDocument();
233
- expect(button).toHaveAttribute('type', 'submit');
136
+ describe('sizes', () => {
137
+ it('renders small buttons', () => {
138
+ expect(render(<Button {...props} size={SMALL} />).container).toMatchSnapshot();
139
+ });
140
+
141
+ it('renders medium buttons', () => {
142
+ expect(render(<Button {...props} size={MEDIUM} />).container).toMatchSnapshot();
143
+ });
144
+
145
+ it('renders large buttons', () => {
146
+ expect(render(<Button {...props} size={LARGE} />).container).toMatchSnapshot();
147
+ });
148
+ });
149
+
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
+ });
162
+ });
163
+
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
+ });
180
+
181
+ it('renders tertiary buttons', () => {
182
+ expect(
183
+ render(<Button {...props} priority={TERTIARY} type={ACCENT} />).container,
184
+ ).toMatchSnapshot();
185
+ });
186
+
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
+ });
195
+
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,
201
+ });
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
+
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
+ });
220
+
221
+ it('renders as block if block is true', () => {
222
+ expect(render(<Button {...props} block />).container).toMatchSnapshot();
223
+ });
224
+ });
225
+
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
+ });
241
+
242
+ it('renders link as accent buttons with priority tertiary and logs a warning', () => {
243
+ expect(render(<Button {...props} type={LINK} />).container).toMatchSnapshot();
244
+ });
234
245
  });
235
246
  });