@transferwise/components 46.84.1 → 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 (63) 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 +3 -3
  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/navigationOption/NavigationOption.spec.tsx +113 -0
  52. package/src/radioOption/RadioOption.spec.tsx +73 -0
  53. package/src/stepper/Stepper.spec.tsx +236 -0
  54. package/src/stepper/Stepper.tests.story.tsx +89 -0
  55. package/src/stepper/Stepper.tsx +9 -4
  56. package/src/stepper/{deviceDetection.spec.js → deviceDetection.spec.ts} +6 -3
  57. package/src/uploadInput/uploadButton/UploadButton.messages.ts +7 -0
  58. package/src/uploadInput/uploadButton/UploadButton.tsx +1 -1
  59. package/src/dimmer/Dimmer.spec.js +0 -87
  60. package/src/navigationOption/NavigationOption.spec.js +0 -93
  61. package/src/radioOption/RadioOption.spec.js +0 -67
  62. package/src/stepper/Stepper.spec.js +0 -233
  63. /package/src/alert/{Alert.spec.story.tsx → Alert.tests.story.tsx} +0 -0
@@ -1,233 +0,0 @@
1
- import { shallow } from 'enzyme';
2
-
3
- import { Tooltip } from '..';
4
-
5
- import Stepper from './Stepper';
6
-
7
- jest.mock('./deviceDetection', () => ({
8
- isTouchDevice: jest.fn(() => false),
9
- }));
10
-
11
- describe('Stepper', () => {
12
- let props;
13
- let component;
14
- let fakeDeviceDetection;
15
-
16
- beforeEach(() => {
17
- fakeDeviceDetection = require('./deviceDetection');
18
- props = {
19
- activeStep: 0,
20
- steps: ['one', 'two', 'three'].map((label) => ({ label })),
21
- };
22
- component = shallow(<Stepper {...props} />);
23
- });
24
-
25
- const activeStep = (step) => component.setProps({ activeStep: step });
26
- const steps = (howMany) =>
27
- component.setProps({
28
- steps: new Array(...new Array(howMany)).map((_, index) => ({ label: index.toString() })),
29
- });
30
-
31
- describe('progress bar', () => {
32
- const totalWidth = () => component.find('.progress-bar').prop('style').width;
33
-
34
- describe('when no steps are passed in', () => {
35
- it('renders nothing', () => {
36
- component.setProps({ steps: [] });
37
-
38
- expect(component.isEmptyRender()).toBe(true);
39
- });
40
- });
41
-
42
- it('sets the widths of the progress bar to match where you are in the flow', () => {
43
- expect(totalWidth()).toBe('0px');
44
- activeStep(2);
45
- expect(totalWidth()).toBe(
46
- 'calc(100% + var(--progress-bar-start-shift) + var(--progress-bar-border-width))',
47
- );
48
- steps(5);
49
- expect(totalWidth()).toBe(
50
- 'calc(50% + var(--progress-bar-start-shift) + var(--progress-bar-border-width))',
51
- );
52
- activeStep(10000);
53
- expect(totalWidth()).toBe(
54
- 'calc(100% + var(--progress-bar-start-shift) + var(--progress-bar-border-width))',
55
- );
56
- activeStep(-10);
57
- expect(totalWidth()).toBe('0px');
58
- });
59
- });
60
-
61
- describe('steps', () => {
62
- it('have rendered labels', () => {
63
- steps(5);
64
- [0, 1, 2, 3, 4].forEach((step) => {
65
- expect(component.find('.tw-stepper__step').at(step).find('span').props().children).toBe(
66
- step.toString(),
67
- );
68
- });
69
- });
70
-
71
- it('are active when clickable and completed', () => {
72
- const stepActive = (index) =>
73
- component.find('.tw-stepper__step').at(index).hasClass('tw-stepper__step--clickable');
74
-
75
- component.setProps({
76
- steps: [
77
- { label: '0' },
78
- { label: '1', onClick: () => null },
79
- { label: '2', onClick: () => null },
80
- ],
81
- activeStep: 0,
82
- });
83
-
84
- expect(stepActive(0)).toBe(false);
85
- activeStep(1);
86
- expect(stepActive(0)).toBe(false);
87
- expect(stepActive(1)).toBe(false);
88
- activeStep(2);
89
- expect(stepActive(0)).toBe(false);
90
- expect(stepActive(1)).toBe(true);
91
- expect(stepActive(2)).toBe(false);
92
- });
93
-
94
- it('are not clickable when active', () => {
95
- const clickOnStep = (index) => {
96
- const buttonReference = component.find('.tw-stepper__step').at(index).find('button');
97
- if (buttonReference.exists()) {
98
- buttonReference.simulate('click');
99
- }
100
- };
101
- const buttonDisabled = (index) =>
102
- !component.find('.tw-stepper__step').at(index).find('button').exists();
103
- const clickedOnFirstStep = jest.fn();
104
- const clickedOnSecondStep = jest.fn();
105
- component.setProps({
106
- steps: [
107
- { label: '0', onClick: clickedOnFirstStep },
108
- { label: '1', onClick: clickedOnSecondStep },
109
- ],
110
- activeStep: 0,
111
- });
112
- clickOnStep(0);
113
- expect(buttonDisabled(0)).toBe(true);
114
- expect(clickedOnFirstStep).not.toHaveBeenCalled();
115
- activeStep(1);
116
- expect(buttonDisabled(0)).toBe(false);
117
- clickOnStep(0);
118
- expect(clickedOnFirstStep).toHaveBeenCalledTimes(1);
119
- clickOnStep(1);
120
- expect(clickedOnSecondStep).not.toHaveBeenCalled();
121
- });
122
-
123
- it('are active when they are the currently active step', () => {
124
- const stepActive = (index) =>
125
- component.find('.tw-stepper__step').at(index).hasClass('tw-stepper__step--active');
126
- steps(4);
127
- activeStep(1);
128
- expect(stepActive(0)).toBe(false);
129
- expect(stepActive(1)).toBe(true);
130
- expect(stepActive(2)).toBe(false);
131
- expect(stepActive(3)).toBe(false);
132
- activeStep(2);
133
- expect(stepActive(0)).toBe(false);
134
- expect(stepActive(1)).toBe(false);
135
- expect(stepActive(2)).toBe(true);
136
- expect(stepActive(3)).toBe(false);
137
- });
138
-
139
- it('are marked as visited when active index is less than or equals to current index', () => {
140
- const step = (index) => {
141
- const buttonStates = ['tw-stepper__step--active', 'tw-stepper__step--clickable'];
142
- const stepElement = component.find('.tw-stepper__step').at(index);
143
- return {
144
- active: stepElement.hasClass(buttonStates[0]),
145
- clickable: stepElement.hasClass(buttonStates[1]),
146
- clickableAndActive: buttonStates.every((c) => stepElement.hasClass(c)),
147
- disabled: !stepElement.find('button').exists(),
148
- };
149
- };
150
-
151
- component.setProps({
152
- steps: [
153
- { label: '0', onClick: () => {} },
154
- { label: '1', onClick: () => {} },
155
- { label: '2', onClick: () => {} },
156
- ],
157
- activeStep: 0,
158
- });
159
-
160
- expect(step(0).active).toBe(true);
161
- expect(step(0).disabled).toBe(true);
162
- expect(step(1).clickableAndActive).toBe(false);
163
- expect(step(2).clickableAndActive).toBe(false);
164
-
165
- activeStep(2);
166
- activeStep(0);
167
-
168
- expect(step(1).clickable).toBe(true);
169
- expect(step(2).clickable).toBe(true);
170
- });
171
-
172
- it('are aria-current=step when active', () => {
173
- const stepCurrent = (index) =>
174
- component.find('.tw-stepper__step').at(index).props()['aria-current'];
175
- steps(4);
176
- activeStep(1);
177
- expect(stepCurrent(0)).toBe(false);
178
- expect(stepCurrent(1)).toBe('step');
179
- expect(stepCurrent(2)).toBe(false);
180
- expect(stepCurrent(3)).toBe(false);
181
- activeStep(2);
182
- expect(stepCurrent(0)).toBe(false);
183
- expect(stepCurrent(1)).toBe(false);
184
- expect(stepCurrent(2)).toBe('step');
185
- expect(stepCurrent(3)).toBe(false);
186
- });
187
- });
188
-
189
- describe('hover labels', () => {
190
- const step = (index) => component.find('.tw-stepper__step').at(index);
191
- it('will be rendered when provided', () => {
192
- component.setProps({
193
- steps: [{ hoverLabel: 'hover', label: 'label' }, { label: 'label 2' }],
194
- });
195
- const firstStepHoverLabel = step(0).children();
196
- expect(firstStepHoverLabel.type()).toBe(Tooltip);
197
- expect(firstStepHoverLabel.children().render().text()).toBe('label');
198
- expect(step(1).find('span').props().children).toBe('label 2');
199
- });
200
-
201
- it('renders jsx', () => {
202
- component.setProps({
203
- steps: [
204
- {
205
- hoverLabel: (
206
- <>
207
- hover <p>label</p>
208
- </>
209
- ),
210
- label: '1',
211
- },
212
- ],
213
- });
214
-
215
- expect(step(0).children().prop('label')).toStrictEqual(
216
- <>
217
- hover <p>label</p>
218
- </>,
219
- );
220
- });
221
-
222
- it('will not be rendered if the user is on a touch device', () => {
223
- jest.spyOn(fakeDeviceDetection, 'isTouchDevice').mockImplementation(() => true);
224
- component.setProps({
225
- steps: [{ hoverLabel: 'hover', label: 'label' }, { label: 'label 2' }],
226
- });
227
- const firstStepHoverLabel = step(0).children();
228
- expect(firstStepHoverLabel.type()).toBe('span');
229
- expect(firstStepHoverLabel.props().children).toBe('label');
230
- expect(step(1).children().props().children).toBe('label 2');
231
- });
232
- });
233
- });