@transferwise/components 46.34.0 → 46.35.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.
- package/build/index.js +170 -192
- package/build/index.js.map +1 -1
- package/build/index.mjs +164 -186
- package/build/index.mjs.map +1 -1
- package/build/types/accordion/AccordionItem/AccordionItem.d.ts.map +1 -1
- package/build/types/common/hooks/useMedia.d.ts.map +1 -1
- package/build/types/common/panel/Panel.d.ts.map +1 -1
- package/build/types/common/responsivePanel/ResponsivePanel.d.ts.map +1 -1
- package/build/types/dimmer/Dimmer.d.ts +1 -11
- package/build/types/dimmer/Dimmer.d.ts.map +1 -1
- package/build/types/drawer/Drawer.d.ts +4 -4
- package/build/types/index.d.ts +3 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/inputs/SelectInput.d.ts.map +1 -1
- package/build/types/modal/Modal.d.ts.map +1 -1
- package/build/types/processIndicator/ProcessIndicator.d.ts +36 -19
- package/build/types/processIndicator/ProcessIndicator.d.ts.map +1 -1
- package/build/types/processIndicator/index.d.ts +2 -2
- package/build/types/processIndicator/index.d.ts.map +1 -1
- package/build/types/promoCard/PromoCard.d.ts.map +1 -1
- package/build/types/select/searchBox/SearchBox.d.ts +1 -1
- package/build/types/snackbar/Snackbar.d.ts +0 -1
- package/build/types/snackbar/Snackbar.d.ts.map +1 -1
- package/build/types/test-utils/wait.d.ts +2 -0
- package/build/types/test-utils/wait.d.ts.map +1 -0
- package/build/types/tooltip/Tooltip.d.ts +1 -1
- package/build/types/tooltip/Tooltip.d.ts.map +1 -1
- package/build/types/uploadInput/uploadItem/UploadItem.d.ts.map +1 -1
- package/build/types/withDisplayFormat/WithDisplayFormat.d.ts.map +1 -1
- package/package.json +11 -15
- package/src/accordion/AccordionItem/AccordionItem.tsx +2 -4
- package/src/avatarWrapper/AvatarWrapper.story.tsx +1 -3
- package/src/button/Button.tsx +1 -1
- package/src/common/hooks/useConditionalListener/useConditionalListener.spec.js +1 -1
- package/src/common/hooks/useHasIntersected/useHasIntersected.spec.js +3 -3
- package/src/common/hooks/useMedia.spec.ts +1 -1
- package/src/common/hooks/useMedia.ts +1 -2
- package/src/common/panel/Panel.tsx +90 -92
- package/src/common/responsivePanel/ResponsivePanel.tsx +34 -38
- package/src/dateLookup/DateLookup.rtl.spec.tsx +181 -5
- package/src/dateLookup/DateLookup.testingLibrary.spec.js +171 -124
- package/src/drawer/Drawer.js +3 -3
- package/src/field/Field.tsx +3 -3
- package/src/index.ts +3 -2
- package/src/inputs/SelectInput.story.tsx +3 -2
- package/src/inputs/SelectInput.tsx +10 -2
- package/src/modal/Modal.tsx +1 -2
- package/src/processIndicator/ProcessIndicator.rtl.spec.tsx +45 -0
- package/src/processIndicator/ProcessIndicator.tsx +110 -0
- package/src/promoCard/PromoCard.tsx +1 -2
- package/src/radio/__snapshots__/Radio.rtl.spec.tsx.snap +0 -1
- package/src/snackbar/Snackbar.spec.js +8 -2
- package/src/snackbar/Snackbar.story.tsx +3 -1
- package/src/snackbar/Snackbar.tsx +1 -1
- package/src/tabs/Tabs.spec.js +46 -27
- package/src/test-utils/index.js +5 -7
- package/src/test-utils/jest.setup.js +9 -3
- package/src/test-utils/wait.ts +7 -0
- package/src/tooltip/Tooltip.tsx +44 -46
- package/src/tooltip/__snapshots__/Tooltip.spec.tsx.snap +2 -2
- package/src/upload/Upload.spec.js +34 -13
- package/src/uploadInput/UploadInput.spec.tsx +21 -23
- package/src/uploadInput/uploadItem/UploadItem.tsx +1 -3
- package/src/withDisplayFormat/WithDisplayFormat.spec.js +63 -32
- package/src/withDisplayFormat/WithDisplayFormat.tsx +4 -6
- package/src/dateLookup/DateLookup.keyboardEvents.spec.js +0 -180
- package/src/processIndicator/ProcessIndicator.js +0 -117
- package/src/processIndicator/ProcessIndicator.spec.js +0 -101
- /package/src/processIndicator/{index.js → index.ts} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { mount } from 'enzyme/build';
|
|
2
|
+
import { act } from 'react';
|
|
2
3
|
|
|
3
4
|
import { HistoryNavigator } from '../common';
|
|
4
5
|
import { fakeKeyDownEventForKey } from '../common/fakeEvents';
|
|
@@ -6,8 +7,6 @@ import { Input } from '../inputs/Input';
|
|
|
6
7
|
|
|
7
8
|
import WithDisplayFormat from '.';
|
|
8
9
|
|
|
9
|
-
jest.useFakeTimers();
|
|
10
|
-
|
|
11
10
|
const REDO_EVENT = { ctrlKey: true, charCode: 'z', shiftKey: true, which: 90 };
|
|
12
11
|
const UNDO_EVENT = { ctrlKey: true, charCode: 'z', which: 90 };
|
|
13
12
|
|
|
@@ -36,11 +35,13 @@ describe('InputWithTextFormat', () => {
|
|
|
36
35
|
};
|
|
37
36
|
|
|
38
37
|
beforeEach(() => {
|
|
38
|
+
jest.useFakeTimers();
|
|
39
39
|
component = mountComponent(props);
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
afterEach(() => {
|
|
43
|
-
jest.
|
|
42
|
+
afterEach(async () => {
|
|
43
|
+
await jest.runOnlyPendingTimersAsync();
|
|
44
|
+
jest.useRealTimers();
|
|
44
45
|
});
|
|
45
46
|
|
|
46
47
|
TESTS.forEach((test) => {
|
|
@@ -64,10 +65,12 @@ describe('InputWithTextFormat', () => {
|
|
|
64
65
|
});
|
|
65
66
|
|
|
66
67
|
describe('when Undo/Redo is preformed', () => {
|
|
67
|
-
it(`goes back/forward in input value's history`, () => {
|
|
68
|
+
it(`goes back/forward in input value's history`, async () => {
|
|
68
69
|
component.setProps({ displayPattern: '***' });
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
await act(async () => {
|
|
71
|
+
component.setState({
|
|
72
|
+
historyNavigator: new HistoryNavigator(['@', '@@', '@@@']),
|
|
73
|
+
});
|
|
71
74
|
});
|
|
72
75
|
|
|
73
76
|
componentInput().simulate('keyDown', UNDO_EVENT);
|
|
@@ -136,8 +139,10 @@ describe('InputWithTextFormat', () => {
|
|
|
136
139
|
expect(componentInput().props().value).toBe('12-3');
|
|
137
140
|
});
|
|
138
141
|
|
|
139
|
-
it(`performs an extra delete if next char is a separator`, () => {
|
|
140
|
-
|
|
142
|
+
it(`performs an extra delete if next char is a separator`, async () => {
|
|
143
|
+
await act(async () => {
|
|
144
|
+
component.setState({ selectionStart: 3, selectionEnd: 3 });
|
|
145
|
+
});
|
|
141
146
|
|
|
142
147
|
componentInput().simulate('change', { target: { value: '123' } });
|
|
143
148
|
expect(componentInput().props().value).toBe('13');
|
|
@@ -152,27 +157,41 @@ describe('InputWithTextFormat', () => {
|
|
|
152
157
|
});
|
|
153
158
|
});
|
|
154
159
|
|
|
155
|
-
it(`when entered a char`, () => {
|
|
156
|
-
|
|
160
|
+
it(`when entered a char`, async () => {
|
|
161
|
+
await act(async () => {
|
|
162
|
+
component.setState({ selectionStart: 4, selectionEnd: 4 });
|
|
163
|
+
});
|
|
157
164
|
componentInput().simulate('change', { target: { value: '13-4@' } });
|
|
158
|
-
|
|
165
|
+
await act(async () => {
|
|
166
|
+
await jest.runOnlyPendingTimersAsync();
|
|
167
|
+
});
|
|
159
168
|
expect(component.state().selectionStart).toBe(5);
|
|
160
169
|
});
|
|
161
170
|
|
|
162
|
-
it(`when entered a char before a symbol`, () => {
|
|
163
|
-
|
|
171
|
+
it(`when entered a char before a symbol`, async () => {
|
|
172
|
+
await act(async () => {
|
|
173
|
+
component.setState({ selectionStart: 2, selectionEnd: 2 });
|
|
174
|
+
});
|
|
164
175
|
componentInput().simulate('change', { target: { value: '13-@' } });
|
|
165
|
-
|
|
176
|
+
await act(async () => {
|
|
177
|
+
await jest.runOnlyPendingTimersAsync();
|
|
178
|
+
});
|
|
166
179
|
expect(component.state().selectionStart).toBe(4);
|
|
167
180
|
});
|
|
168
181
|
//
|
|
169
|
-
it(`when deleted a char before the symbol`, () => {
|
|
170
|
-
|
|
171
|
-
|
|
182
|
+
it(`when deleted a char before the symbol`, async () => {
|
|
183
|
+
await act(async () => {
|
|
184
|
+
component.setState({
|
|
185
|
+
triggerEvent: { ...triggerEventA, key: 'Backspace' },
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
await act(async () => {
|
|
189
|
+
component.setState({ selectionStart: 3, selectionEnd: 3 });
|
|
172
190
|
});
|
|
173
|
-
component.setState({ selectionStart: 3, selectionEnd: 3 });
|
|
174
191
|
componentInput().simulate('change', { target: { value: '13-45-6' } });
|
|
175
|
-
|
|
192
|
+
await act(async () => {
|
|
193
|
+
await jest.runOnlyPendingTimersAsync();
|
|
194
|
+
});
|
|
176
195
|
expect(component.state().selectionStart).toBe(1);
|
|
177
196
|
});
|
|
178
197
|
|
|
@@ -187,26 +206,38 @@ describe('InputWithTextFormat', () => {
|
|
|
187
206
|
expect(component.state().selectionStart).toBe(2);
|
|
188
207
|
});
|
|
189
208
|
|
|
190
|
-
it(`when pasted selection is entered after a symbol`, () => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
209
|
+
it(`when pasted selection is entered after a symbol`, async () => {
|
|
210
|
+
await act(async () => {
|
|
211
|
+
component.setState({
|
|
212
|
+
triggerType: 'Paste',
|
|
213
|
+
pastedLength: 2,
|
|
214
|
+
});
|
|
194
215
|
});
|
|
195
216
|
|
|
196
|
-
|
|
217
|
+
await act(async () => {
|
|
218
|
+
component.setState({ selectionStart: 2, selectionEnd: 2 });
|
|
219
|
+
});
|
|
197
220
|
componentInput().simulate('change', { target: { value: '13-@@' } });
|
|
198
|
-
|
|
221
|
+
await act(async () => {
|
|
222
|
+
await jest.runOnlyPendingTimersAsync();
|
|
223
|
+
});
|
|
199
224
|
expect(component.state().selectionStart).toBe(5);
|
|
200
225
|
});
|
|
201
226
|
|
|
202
|
-
it(`when pasted selection is entered before a symbol`, () => {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
227
|
+
it(`when pasted selection is entered before a symbol`, async () => {
|
|
228
|
+
await act(async () => {
|
|
229
|
+
component.setState({
|
|
230
|
+
triggerType: 'Paste',
|
|
231
|
+
pastedLength: 2,
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
await act(async () => {
|
|
235
|
+
component.setState({ selectionStart: 1, selectionEnd: 1 });
|
|
206
236
|
});
|
|
207
|
-
component.setState({ selectionStart: 1, selectionEnd: 1 });
|
|
208
237
|
componentInput().simulate('change', { target: { value: '1@-@' } });
|
|
209
|
-
|
|
238
|
+
await act(async () => {
|
|
239
|
+
await jest.runOnlyPendingTimersAsync();
|
|
240
|
+
});
|
|
210
241
|
expect(component.state().selectionStart).toBe(4);
|
|
211
242
|
});
|
|
212
243
|
|
|
@@ -137,10 +137,9 @@ class WithDisplayFormat<T extends TextElementProps> extends Component<
|
|
|
137
137
|
return 'Backspace';
|
|
138
138
|
}
|
|
139
139
|
return triggerEvent.key;
|
|
140
|
-
} else {
|
|
141
|
-
// triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
|
|
142
|
-
return 'Paste';
|
|
143
140
|
}
|
|
141
|
+
// triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
|
|
142
|
+
return 'Paste';
|
|
144
143
|
};
|
|
145
144
|
|
|
146
145
|
resetEvent = () => {
|
|
@@ -273,6 +272,7 @@ class WithDisplayFormat<T extends TextElementProps> extends Component<
|
|
|
273
272
|
handleCursorPositioning = (action: string) => {
|
|
274
273
|
const { displayPattern } = this.props;
|
|
275
274
|
const { triggerEvent, selectionStart, selectionEnd, pastedLength } = this.state;
|
|
275
|
+
const target = triggerEvent?.currentTarget;
|
|
276
276
|
|
|
277
277
|
const cursorPosition = getCursorPositionAfterKeystroke(
|
|
278
278
|
action,
|
|
@@ -283,9 +283,7 @@ class WithDisplayFormat<T extends TextElementProps> extends Component<
|
|
|
283
283
|
);
|
|
284
284
|
|
|
285
285
|
setTimeout(() => {
|
|
286
|
-
|
|
287
|
-
(triggerEvent.target as HTMLTextElement).setSelectionRange(cursorPosition, cursorPosition);
|
|
288
|
-
}
|
|
286
|
+
target?.setSelectionRange(cursorPosition, cursorPosition);
|
|
289
287
|
this.setState({ selectionStart: cursorPosition, selectionEnd: cursorPosition });
|
|
290
288
|
}, 0);
|
|
291
289
|
};
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
/* eslint-disable jest/expect-expect */
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
|
|
4
|
-
import { fakeKeyDownEventForKey } from '../common/fakeEvents';
|
|
5
|
-
import { mockMatchMedia } from '../test-utils';
|
|
6
|
-
|
|
7
|
-
import { DateLookupWithoutInputAttributes as DateLookup } from './DateLookup';
|
|
8
|
-
|
|
9
|
-
mockMatchMedia();
|
|
10
|
-
|
|
11
|
-
const defaultLocale = 'en-GB';
|
|
12
|
-
const formatMessage = (id) => String(id);
|
|
13
|
-
jest.mock('react-intl', () => ({
|
|
14
|
-
injectIntl: (Component) =>
|
|
15
|
-
function (props) {
|
|
16
|
-
return <Component {...props} intl={{ locale: defaultLocale, formatMessage }} />;
|
|
17
|
-
},
|
|
18
|
-
useIntl: () => ({ locale: defaultLocale, formatMessage }),
|
|
19
|
-
defineMessages: (translations) => translations,
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
describe('DateLookup (keyboard events)', () => {
|
|
23
|
-
const date = new Date(2018, 11, 27);
|
|
24
|
-
let component;
|
|
25
|
-
let props;
|
|
26
|
-
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
props = { value: date, onChange: jest.fn() };
|
|
29
|
-
component = mount(<DateLookup {...props} />);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('can be opened by LEFT arrow', () => {
|
|
33
|
-
pressKey('ArrowLeft');
|
|
34
|
-
expect(component.instance().state.open).toBe(true);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('can be opened by UP arrow', () => {
|
|
38
|
-
pressKey('ArrowUp');
|
|
39
|
-
expect(component.instance().state.open).toBe(true);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('can be opened by RIGHT arrow', () => {
|
|
43
|
-
pressKey('ArrowRight');
|
|
44
|
-
expect(component.instance().state.open).toBe(true);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('can be opened by DOWN arrow', () => {
|
|
48
|
-
pressKey('ArrowDown');
|
|
49
|
-
expect(component.instance().state.open).toBe(true);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('can be closed by pressing ESCAPE', () => {
|
|
53
|
-
component.setState({ open: true });
|
|
54
|
-
pressKey('Escape');
|
|
55
|
-
expect(component.instance().state.open).toBe(false);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('when open and in day mode', () => {
|
|
59
|
-
beforeEach(() => {
|
|
60
|
-
component.setState({ open: true, mode: 'day' });
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('moves 1 day back by pressing LEFT', () => {
|
|
64
|
-
pressKey('ArrowLeft');
|
|
65
|
-
onChangeCalledWith(new Date(2018, 11, 26));
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('moves 7 days back by pressing UP', () => {
|
|
69
|
-
pressKey('ArrowUp');
|
|
70
|
-
onChangeCalledWith(new Date(2018, 11, 20));
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('moves 1 day forward by pressing RIGHT', () => {
|
|
74
|
-
pressKey('ArrowRight');
|
|
75
|
-
onChangeCalledWith(new Date(2018, 11, 28));
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('moves 7 day forward by pressing DOWN', () => {
|
|
79
|
-
pressKey('ArrowDown');
|
|
80
|
-
onChangeCalledWith(new Date(2019, 0, 3));
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('resets to original date when escape key is pressed', () => {
|
|
84
|
-
pressKey('ArrowLeft');
|
|
85
|
-
pressKey('Escape');
|
|
86
|
-
onChangeCalledWith(date);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('resets to original date when clicking outside modal', () => {
|
|
90
|
-
pressKey('ArrowLeft');
|
|
91
|
-
component.find('.dimmer').simulate('click');
|
|
92
|
-
onChangeCalledWith(date);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe('when open and in month mode', () => {
|
|
97
|
-
beforeEach(() => {
|
|
98
|
-
component.setState({ open: true, mode: 'month' });
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('moves 1 month back by pressing LEFT', () => {
|
|
102
|
-
pressKey('ArrowLeft');
|
|
103
|
-
onChangeCalledWith(new Date(2018, 10, 27));
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('moves 4 months back by pressing UP', () => {
|
|
107
|
-
pressKey('ArrowUp');
|
|
108
|
-
onChangeCalledWith(new Date(2018, 7, 27));
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('moves 1 month forward by pressing RIGHT', () => {
|
|
112
|
-
pressKey('ArrowRight');
|
|
113
|
-
onChangeCalledWith(new Date(2019, 0, 27));
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('moves 4 months forward by pressing DOWN', () => {
|
|
117
|
-
pressKey('ArrowDown');
|
|
118
|
-
onChangeCalledWith(new Date(2019, 3, 27));
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
describe('when open and in year mode', () => {
|
|
123
|
-
beforeEach(() => {
|
|
124
|
-
component.setState({ open: true, mode: 'year' });
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('moves 1 year back by pressing LEFT', () => {
|
|
128
|
-
pressKey('ArrowLeft');
|
|
129
|
-
onChangeCalledWith(new Date(2017, 11, 27));
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('moves 4 years back by pressing UP', () => {
|
|
133
|
-
pressKey('ArrowUp');
|
|
134
|
-
onChangeCalledWith(new Date(2014, 11, 27));
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('moves 1 year forward by pressing RIGHT', () => {
|
|
138
|
-
pressKey('ArrowRight');
|
|
139
|
-
onChangeCalledWith(new Date(2019, 11, 27));
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('moves 4 year forward by pressing DOWN', () => {
|
|
143
|
-
pressKey('ArrowDown');
|
|
144
|
-
onChangeCalledWith(new Date(2022, 11, 27));
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
describe('when min and max provided', () => {
|
|
149
|
-
beforeEach(() => {
|
|
150
|
-
component.setState({
|
|
151
|
-
open: true,
|
|
152
|
-
mode: 'day',
|
|
153
|
-
min: new Date(2018, 11, 26),
|
|
154
|
-
max: new Date(2018, 11, 28),
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('makes sure that date is >= min', () => {
|
|
159
|
-
pressKey('ArrowLeft');
|
|
160
|
-
onChangeCalledWith(new Date(2018, 11, 26));
|
|
161
|
-
pressKey('ArrowLeft');
|
|
162
|
-
onChangeCalledWith(new Date(2018, 11, 26));
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('makes sure that date is <= max', () => {
|
|
166
|
-
pressKey('ArrowRight');
|
|
167
|
-
onChangeCalledWith(new Date(2018, 11, 28));
|
|
168
|
-
pressKey('ArrowRight');
|
|
169
|
-
onChangeCalledWith(new Date(2018, 11, 28));
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
const pressKey = (key) => {
|
|
174
|
-
component.simulate('keyDown', fakeKeyDownEventForKey(key));
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
const onChangeCalledWith = (d) => {
|
|
178
|
-
expect(props.onChange).toHaveBeenLastCalledWith(d);
|
|
179
|
-
};
|
|
180
|
-
});
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import classNames from 'classnames';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { Component } from 'react';
|
|
4
|
-
|
|
5
|
-
import { Status, Size } from '../common';
|
|
6
|
-
|
|
7
|
-
const radius = { xxs: 6, xs: 11, sm: 22, xl: 61 };
|
|
8
|
-
export const ANIMATION_DURATION_IN_MS = 1500;
|
|
9
|
-
|
|
10
|
-
class ProcessIndicator extends Component {
|
|
11
|
-
constructor(props) {
|
|
12
|
-
super(props);
|
|
13
|
-
this.state = {
|
|
14
|
-
status: props.status,
|
|
15
|
-
size: props.size,
|
|
16
|
-
};
|
|
17
|
-
this.interval = null;
|
|
18
|
-
this.timeout = null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Create interval for animation duration (1500ms)
|
|
23
|
-
* Update state only at the end of every interval
|
|
24
|
-
* (end of animation loop) if props changed before end of animation
|
|
25
|
-
*/
|
|
26
|
-
componentDidMount() {
|
|
27
|
-
this.interval = setInterval(() => {
|
|
28
|
-
const statusFromState = this.state.status;
|
|
29
|
-
const sizeFromState = this.state.size;
|
|
30
|
-
|
|
31
|
-
const statusFromProps = this.props.status;
|
|
32
|
-
const sizeFromProps = this.props.size;
|
|
33
|
-
|
|
34
|
-
if (statusFromState !== statusFromProps) {
|
|
35
|
-
this.setState({ status: statusFromProps }, this.runCallBack(statusFromProps));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (sizeFromState !== sizeFromProps) {
|
|
39
|
-
this.setState({ size: sizeFromProps });
|
|
40
|
-
}
|
|
41
|
-
}, ANIMATION_DURATION_IN_MS);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Only trigger render if comopnent's state got
|
|
46
|
-
* updated from interval callback
|
|
47
|
-
*
|
|
48
|
-
* @param nextProps
|
|
49
|
-
* @param nextState
|
|
50
|
-
*/
|
|
51
|
-
shouldComponentUpdate(nextProps, nextState) {
|
|
52
|
-
const isSameStatus = nextProps.status === nextState.status;
|
|
53
|
-
const isSameSize = nextProps.size === nextState.size;
|
|
54
|
-
|
|
55
|
-
return isSameStatus && isSameSize;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Clear interval before destroying component
|
|
59
|
-
componentWillUnmount() {
|
|
60
|
-
clearInterval(this.interval);
|
|
61
|
-
clearTimeout(this.timeout);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
runCallBack = (statusFromProps) => {
|
|
65
|
-
const { onAnimationCompleted } = this.props;
|
|
66
|
-
if (onAnimationCompleted) {
|
|
67
|
-
this.timeouts = setTimeout(() => {
|
|
68
|
-
onAnimationCompleted(statusFromProps);
|
|
69
|
-
}, ANIMATION_DURATION_IN_MS);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
render() {
|
|
74
|
-
const { className, 'data-testid': dataTestId } = this.props;
|
|
75
|
-
const { size, status } = this.state;
|
|
76
|
-
const classes = classNames(`process process-${size}`, className, {
|
|
77
|
-
[`process-danger`]: status === Status.FAILED,
|
|
78
|
-
[`process-stopped`]: status === Status.HIDDEN,
|
|
79
|
-
[`process-success`]: status === Status.SUCCEEDED,
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
return (
|
|
83
|
-
<span className={classes} data-testid={dataTestId}>
|
|
84
|
-
<span className="process-icon-container">
|
|
85
|
-
<span className="process-icon-horizontal" />
|
|
86
|
-
<span className="process-icon-vertical" />
|
|
87
|
-
</span>
|
|
88
|
-
<svg xmlns="http://www.w3.org/2000/svg">
|
|
89
|
-
<circle
|
|
90
|
-
className="process-circle"
|
|
91
|
-
cx="50%"
|
|
92
|
-
cy="50%"
|
|
93
|
-
r={radius[this.state.size]}
|
|
94
|
-
fillOpacity="0.0"
|
|
95
|
-
/>
|
|
96
|
-
</svg>
|
|
97
|
-
</span>
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
ProcessIndicator.propTypes = {
|
|
102
|
-
status: PropTypes.oneOf(['processing', 'failed', 'succeeded', 'hidden']),
|
|
103
|
-
size: PropTypes.oneOf(['xxs', 'xs', 'sm', 'xl']),
|
|
104
|
-
onAnimationCompleted: PropTypes.func,
|
|
105
|
-
className: PropTypes.string,
|
|
106
|
-
'data-testid': PropTypes.string,
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
ProcessIndicator.defaultProps = {
|
|
110
|
-
status: Status.PROCESSING,
|
|
111
|
-
size: Size.SMALL,
|
|
112
|
-
onAnimationCompleted: null,
|
|
113
|
-
className: undefined,
|
|
114
|
-
'data-testid': null,
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export default ProcessIndicator;
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { mount } from 'enzyme';
|
|
2
|
-
|
|
3
|
-
import { Status, Size } from '../common';
|
|
4
|
-
|
|
5
|
-
import ProcessIndicator from '.';
|
|
6
|
-
|
|
7
|
-
describe('processIndicator', () => {
|
|
8
|
-
let wrapper;
|
|
9
|
-
const ANIMATION_DURATION = 1500;
|
|
10
|
-
const props = {
|
|
11
|
-
status: Status.PROCESSING,
|
|
12
|
-
size: Size.Small,
|
|
13
|
-
onAnimationCompleted: jest.fn(),
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
jest.useFakeTimers();
|
|
18
|
-
|
|
19
|
-
wrapper = mount(<ProcessIndicator {...props} />);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
afterEach(() => {
|
|
23
|
-
jest.useRealTimers();
|
|
24
|
-
jest.clearAllMocks();
|
|
25
|
-
jest.clearAllTimers();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('has right classes when rendered with provided props', () => {
|
|
29
|
-
expect(wrapper.find('.process')).toHaveLength(1);
|
|
30
|
-
expect(wrapper.find('.process-sm')).toHaveLength(1);
|
|
31
|
-
|
|
32
|
-
expect(wrapper.find('.process-lg')).toHaveLength(0);
|
|
33
|
-
expect(wrapper.find('.process-xs')).toHaveLength(0);
|
|
34
|
-
expect(wrapper.find('.process-danger')).toHaveLength(0);
|
|
35
|
-
expect(wrapper.find('.process-stopped')).toHaveLength(0);
|
|
36
|
-
expect(wrapper.find('.process-success')).toHaveLength(0);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('updates component state with delay on props change to create smooth transition between CSS animations', () => {
|
|
40
|
-
expect(wrapper.state().status).toBe('processing');
|
|
41
|
-
|
|
42
|
-
wrapper.setProps({ status: 'succeeded' });
|
|
43
|
-
expect(wrapper.props().status).toBe('succeeded');
|
|
44
|
-
expect(wrapper.state().status).toBe('processing');
|
|
45
|
-
|
|
46
|
-
jest.advanceTimersByTime(ANIMATION_DURATION);
|
|
47
|
-
wrapper.update();
|
|
48
|
-
|
|
49
|
-
expect(wrapper.state().status).toBe('succeeded');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('updates size classes with delay', () => {
|
|
53
|
-
expect(wrapper.find('.process-sm')).toHaveLength(1);
|
|
54
|
-
wrapper.setProps({ size: 'xl' });
|
|
55
|
-
expect(wrapper.find('.process-xl')).toHaveLength(0);
|
|
56
|
-
|
|
57
|
-
jest.advanceTimersByTime(ANIMATION_DURATION);
|
|
58
|
-
wrapper.update();
|
|
59
|
-
|
|
60
|
-
expect(wrapper.find('.process-xs')).toHaveLength(0);
|
|
61
|
-
expect(wrapper.find('.process-sm')).toHaveLength(0);
|
|
62
|
-
expect(wrapper.find('.process-xl')).toHaveLength(1);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('properly updates status classes with delay', () => {
|
|
66
|
-
wrapper.setProps({ status: 'succeeded' });
|
|
67
|
-
expect(wrapper.find('.process-success')).toHaveLength(0);
|
|
68
|
-
jest.advanceTimersByTime(ANIMATION_DURATION);
|
|
69
|
-
wrapper.update();
|
|
70
|
-
expect(wrapper.find('.process-success')).toHaveLength(1);
|
|
71
|
-
expect(wrapper.find('.process-danger')).toHaveLength(0);
|
|
72
|
-
expect(wrapper.find('.process-stopped')).toHaveLength(0);
|
|
73
|
-
|
|
74
|
-
wrapper.setProps({ status: 'failed' });
|
|
75
|
-
expect(wrapper.find('.process-danger')).toHaveLength(0);
|
|
76
|
-
jest.advanceTimersByTime(ANIMATION_DURATION);
|
|
77
|
-
wrapper.update();
|
|
78
|
-
expect(wrapper.find('.process-success')).toHaveLength(0);
|
|
79
|
-
expect(wrapper.find('.process-danger')).toHaveLength(1);
|
|
80
|
-
expect(wrapper.find('.process-stopped')).toHaveLength(0);
|
|
81
|
-
|
|
82
|
-
wrapper.setProps({ status: 'hidden' });
|
|
83
|
-
expect(wrapper.find('.process-stopped')).toHaveLength(0);
|
|
84
|
-
jest.advanceTimersByTime(ANIMATION_DURATION);
|
|
85
|
-
wrapper.update();
|
|
86
|
-
expect(wrapper.find('.process-success')).toHaveLength(0);
|
|
87
|
-
expect(wrapper.find('.process-danger')).toHaveLength(0);
|
|
88
|
-
expect(wrapper.find('.process-stopped')).toHaveLength(1);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('calls onAnimationCompleted with Delay', () => {
|
|
92
|
-
expect(props.onAnimationCompleted).not.toHaveBeenCalled();
|
|
93
|
-
wrapper.setProps({ status: Status.FAILED });
|
|
94
|
-
expect(props.onAnimationCompleted).not.toHaveBeenCalled();
|
|
95
|
-
jest.advanceTimersByTime(ANIMATION_DURATION * 2);
|
|
96
|
-
expect(props.onAnimationCompleted).toHaveBeenCalledWith(Status.FAILED);
|
|
97
|
-
wrapper.setProps({ status: Status.SUCCEEDED });
|
|
98
|
-
jest.advanceTimersByTime(ANIMATION_DURATION * 2);
|
|
99
|
-
expect(props.onAnimationCompleted).toHaveBeenCalledWith(Status.SUCCEEDED);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
File without changes
|