@transferwise/components 0.0.0-experimental-47ae02a → 0.0.0-experimental-da6dbbf
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 +940 -642
- package/build/index.js.map +1 -1
- package/build/index.mjs +930 -633
- package/build/index.mjs.map +1 -1
- package/build/main.css +135 -0
- package/build/styles/carousel/Carousel.css +135 -0
- package/build/styles/main.css +135 -0
- package/build/types/accordion/AccordionItem/AccordionItem.d.ts.map +1 -1
- package/build/types/carousel/Carousel.d.ts +26 -0
- package/build/types/carousel/Carousel.d.ts.map +1 -0
- package/build/types/carousel/index.d.ts +3 -0
- package/build/types/carousel/index.d.ts.map +1 -0
- package/build/types/common/card/Card.d.ts +2 -2
- package/build/types/common/card/Card.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 +11 -1
- 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 +4 -3
- package/build/types/index.d.ts.map +1 -1
- package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts +1 -2
- package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.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 +19 -36
- 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 +16 -5
- package/build/types/promoCard/PromoCard.d.ts.map +1 -1
- package/build/types/select/searchBox/SearchBox.d.ts +1 -1
- package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts +1 -2
- package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts.map +1 -1
- 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 +14 -14
- package/build/types/withDisplayFormat/WithDisplayFormat.d.ts.map +1 -1
- package/package.json +11 -7
- package/src/accordion/AccordionItem/AccordionItem.tsx +4 -2
- package/src/avatarWrapper/AvatarWrapper.story.tsx +3 -1
- package/src/button/Button.tsx +1 -1
- package/src/carousel/Carousel.css +135 -0
- package/src/carousel/Carousel.less +133 -0
- package/src/carousel/Carousel.spec.tsx +221 -0
- package/src/carousel/Carousel.story.tsx +63 -0
- package/src/carousel/Carousel.tsx +345 -0
- package/src/carousel/index.ts +3 -0
- package/src/common/card/Card.tsx +51 -43
- 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 +2 -1
- package/src/common/panel/Panel.tsx +92 -90
- package/src/common/responsivePanel/ResponsivePanel.tsx +38 -34
- package/src/dateLookup/DateLookup.keyboardEvents.spec.js +180 -0
- package/src/dateLookup/DateLookup.rtl.spec.tsx +5 -181
- package/src/dateLookup/DateLookup.testingLibrary.spec.js +124 -171
- package/src/drawer/Drawer.js +3 -3
- package/src/field/Field.tsx +3 -3
- package/src/index.ts +4 -3
- package/src/inputWithDisplayFormat/InputWithDisplayFormat.tsx +1 -2
- package/src/inputs/SelectInput.story.tsx +0 -1
- package/src/inputs/SelectInput.tsx +2 -10
- package/src/main.css +135 -0
- package/src/main.less +1 -0
- package/src/modal/Modal.tsx +2 -1
- package/src/processIndicator/ProcessIndicator.js +117 -0
- package/src/processIndicator/ProcessIndicator.spec.js +101 -0
- package/src/promoCard/PromoCard.story.tsx +2 -2
- package/src/promoCard/PromoCard.tsx +31 -9
- package/src/radio/__snapshots__/Radio.rtl.spec.tsx.snap +1 -0
- package/src/snackbar/Snackbar.spec.js +1 -4
- package/src/tabs/Tabs.spec.js +27 -46
- package/src/test-utils/index.js +7 -5
- package/src/test-utils/jest.setup.js +3 -9
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.tsx +1 -2
- package/src/tooltip/Tooltip.tsx +46 -44
- package/src/tooltip/__snapshots__/Tooltip.spec.tsx.snap +2 -2
- package/src/upload/Upload.spec.js +13 -34
- package/src/uploadInput/UploadInput.spec.tsx +23 -21
- package/src/uploadInput/uploadItem/UploadItem.tsx +3 -1
- package/src/withDisplayFormat/WithDisplayFormat.spec.js +32 -63
- package/src/withDisplayFormat/WithDisplayFormat.tsx +28 -28
- package/src/processIndicator/ProcessIndicator.rtl.spec.tsx +0 -45
- package/src/processIndicator/ProcessIndicator.tsx +0 -110
- /package/src/processIndicator/{index.ts → index.js} +0 -0
package/src/tooltip/Tooltip.tsx
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
import { useId } from '@radix-ui/react-id';
|
|
2
3
|
import classNames from 'classnames';
|
|
3
4
|
import {
|
|
4
|
-
PropsWithChildren,
|
|
5
|
-
ReactElement,
|
|
6
|
-
ReactNode,
|
|
7
5
|
cloneElement,
|
|
8
|
-
useEffect,
|
|
9
|
-
useId,
|
|
10
6
|
useRef,
|
|
11
7
|
useState,
|
|
8
|
+
useEffect,
|
|
9
|
+
ReactNode,
|
|
10
|
+
ReactElement,
|
|
11
|
+
PropsWithChildren,
|
|
12
12
|
} from 'react';
|
|
13
13
|
import { usePopper } from 'react-popper';
|
|
14
14
|
|
|
@@ -75,47 +75,49 @@ const Tooltip = ({
|
|
|
75
75
|
}, [open]);
|
|
76
76
|
|
|
77
77
|
return (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
{children
|
|
87
|
-
? cloneElement(children as ReactElement, {
|
|
88
|
-
'aria-describedby': `${tooltipId}-tooltip`,
|
|
89
|
-
})
|
|
90
|
-
: null}
|
|
91
|
-
<div
|
|
92
|
-
// @ts-expect-error
|
|
93
|
-
ref={setPopperElement}
|
|
94
|
-
className={classNames(
|
|
95
|
-
'np-tooltip',
|
|
96
|
-
'np-panel',
|
|
97
|
-
open ? `np-panel--open np-tooltip--open` : null,
|
|
98
|
-
className,
|
|
99
|
-
)}
|
|
100
|
-
// eslint-disable-next-line react/forbid-dom-props
|
|
101
|
-
style={{ ...styles.popper }}
|
|
102
|
-
{...attributes.popper}
|
|
103
|
-
aria-hidden={!open}
|
|
104
|
-
role="tooltip"
|
|
105
|
-
id={`${tooltipId}-tooltip`}
|
|
78
|
+
<>
|
|
79
|
+
<span
|
|
80
|
+
ref={anchorReference}
|
|
81
|
+
className="tw-tooltip-container"
|
|
82
|
+
onMouseOver={() => setOpen(true)}
|
|
83
|
+
onFocus={() => setOpen(true)}
|
|
84
|
+
onMouseOut={() => setOpen(false)}
|
|
85
|
+
onBlur={() => setOpen(false)}
|
|
106
86
|
>
|
|
107
|
-
|
|
108
|
-
{
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
87
|
+
{children
|
|
88
|
+
? cloneElement(children as ReactElement, {
|
|
89
|
+
'aria-describedby': `${tooltipId}-tooltip`,
|
|
90
|
+
})
|
|
91
|
+
: null}
|
|
92
|
+
<div
|
|
93
|
+
// @ts-expect-error
|
|
94
|
+
ref={setPopperElement}
|
|
95
|
+
className={classNames(
|
|
96
|
+
'np-tooltip',
|
|
97
|
+
'np-panel',
|
|
98
|
+
open ? `np-panel--open np-tooltip--open` : null,
|
|
99
|
+
className,
|
|
100
|
+
)}
|
|
101
|
+
// eslint-disable-next-line react/forbid-dom-props
|
|
102
|
+
style={{ ...styles.popper }}
|
|
103
|
+
{...attributes.popper}
|
|
104
|
+
aria-hidden={!open}
|
|
105
|
+
role="tooltip"
|
|
106
|
+
id={`${tooltipId}-tooltip`}
|
|
107
|
+
>
|
|
108
|
+
<div className="np-panel__content tooltip-inner">
|
|
109
|
+
{label}
|
|
110
|
+
<div
|
|
111
|
+
// @ts-expect-error
|
|
112
|
+
ref={setArrowElement}
|
|
113
|
+
className={classNames('np-panel__arrow')}
|
|
114
|
+
// eslint-disable-next-line react/forbid-dom-props
|
|
115
|
+
style={styles.arrow}
|
|
116
|
+
/>
|
|
117
|
+
</div>
|
|
116
118
|
</div>
|
|
117
|
-
</
|
|
118
|
-
|
|
119
|
+
</span>
|
|
120
|
+
</>
|
|
119
121
|
);
|
|
120
122
|
};
|
|
121
123
|
|
|
@@ -6,14 +6,14 @@ exports[`Tooltip Component renders an empty list when no items are passed 1`] =
|
|
|
6
6
|
class="tw-tooltip-container"
|
|
7
7
|
>
|
|
8
8
|
<span
|
|
9
|
-
aria-describedby="
|
|
9
|
+
aria-describedby="radix-0-tooltip"
|
|
10
10
|
>
|
|
11
11
|
Hover me
|
|
12
12
|
</span>
|
|
13
13
|
<div
|
|
14
14
|
aria-hidden="true"
|
|
15
15
|
class="np-tooltip np-panel"
|
|
16
|
-
id="
|
|
16
|
+
id="radix-0-tooltip"
|
|
17
17
|
role="tooltip"
|
|
18
18
|
style="position: absolute; left: 0px; top: 0px;"
|
|
19
19
|
>
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { shallow, mount } from 'enzyme';
|
|
2
|
-
import { act } from 'react';
|
|
3
2
|
|
|
4
3
|
import { ANIMATION_DURATION_IN_MS } from '../processIndicator';
|
|
5
4
|
|
|
@@ -7,6 +6,7 @@ import { CompleteStep, UploadImageStep, MediaUploadStep, ProcessingStep } from '
|
|
|
7
6
|
|
|
8
7
|
import Upload from '.';
|
|
9
8
|
|
|
9
|
+
jest.useFakeTimers();
|
|
10
10
|
jest.mock('./utils/postData', () => ({
|
|
11
11
|
postData: async () => 'ServerResponse',
|
|
12
12
|
}));
|
|
@@ -15,12 +15,12 @@ jest.mock('./utils/asyncFileRead');
|
|
|
15
15
|
const { asyncFileRead } = require('./utils/asyncFileRead');
|
|
16
16
|
|
|
17
17
|
const defaultLocale = 'en-GB';
|
|
18
|
-
const formatMessage = (id) =>
|
|
18
|
+
const formatMessage = (id) => `${id}`;
|
|
19
19
|
jest.mock('react-intl', () => ({
|
|
20
20
|
injectIntl: (Component) =>
|
|
21
21
|
function (props) {
|
|
22
22
|
return (
|
|
23
|
-
<Component {...props} intl={{ locale: defaultLocale, formatMessage: (id) =>
|
|
23
|
+
<Component {...props} intl={{ locale: defaultLocale, formatMessage: (id) => `${id}` }} />
|
|
24
24
|
);
|
|
25
25
|
},
|
|
26
26
|
useIntl: () => ({ formatMessage }),
|
|
@@ -87,14 +87,11 @@ const COMPLETED_STEP_PROPS = {
|
|
|
87
87
|
describe('Upload', () => {
|
|
88
88
|
let component;
|
|
89
89
|
beforeEach(() => {
|
|
90
|
-
jest.useFakeTimers();
|
|
91
90
|
component = shallow(<Upload {...props} />).dive();
|
|
92
91
|
asyncFileRead.mockImplementation(async () => 'a value');
|
|
93
92
|
});
|
|
94
93
|
|
|
95
|
-
afterEach(
|
|
96
|
-
await jest.runOnlyPendingTimersAsync();
|
|
97
|
-
jest.useRealTimers();
|
|
94
|
+
afterEach(() => {
|
|
98
95
|
jest.clearAllMocks();
|
|
99
96
|
jest.clearAllTimers();
|
|
100
97
|
});
|
|
@@ -216,14 +213,6 @@ describe('Upload', () => {
|
|
|
216
213
|
});
|
|
217
214
|
|
|
218
215
|
describe('when file is processed', () => {
|
|
219
|
-
const waitForUpload = async () => {
|
|
220
|
-
for (let i = 0; i < 4; i += 1) {
|
|
221
|
-
await act(async () => {
|
|
222
|
-
await jest.runOnlyPendingTimersAsync();
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
|
|
227
216
|
it('step changes from UploadImageStep to CompleteStep', async () => {
|
|
228
217
|
component = mount(<Upload {...props} />);
|
|
229
218
|
const upload = component.children();
|
|
@@ -231,10 +220,8 @@ describe('Upload', () => {
|
|
|
231
220
|
expect(upload.find(ProcessingStep)).toHaveLength(0);
|
|
232
221
|
expect(upload.find(CompleteStep)).toHaveLength(0);
|
|
233
222
|
|
|
234
|
-
await
|
|
235
|
-
|
|
236
|
-
});
|
|
237
|
-
await waitForUpload();
|
|
223
|
+
await upload.instance().fileDropped(TEST_FILE);
|
|
224
|
+
jest.advanceTimersByTime(props.animationDelay + ANIMATION_DELAY);
|
|
238
225
|
component.update();
|
|
239
226
|
|
|
240
227
|
expect(component.find(UploadImageStep)).toHaveLength(0);
|
|
@@ -249,10 +236,8 @@ describe('Upload', () => {
|
|
|
249
236
|
throw 'An error';
|
|
250
237
|
});
|
|
251
238
|
|
|
252
|
-
await
|
|
253
|
-
|
|
254
|
-
});
|
|
255
|
-
await waitForUpload();
|
|
239
|
+
await upload.instance().fileDropped(TEST_FILE);
|
|
240
|
+
jest.advanceTimersByTime(props.animationDelay + ANIMATION_DELAY);
|
|
256
241
|
component.update();
|
|
257
242
|
|
|
258
243
|
expect(component.find(CompleteStep).props()).toStrictEqual({
|
|
@@ -267,10 +252,8 @@ describe('Upload', () => {
|
|
|
267
252
|
it('onSuccess is called with response when httpOptions are provided', async () => {
|
|
268
253
|
component = mount(<Upload {...props} httpOptions={{ url: 'a-url' }} />).children();
|
|
269
254
|
|
|
270
|
-
await
|
|
271
|
-
|
|
272
|
-
});
|
|
273
|
-
await waitForUpload();
|
|
255
|
+
await component.instance().fileDropped(TEST_FILE);
|
|
256
|
+
jest.advanceTimersByTime(props.animationDelay + ANIMATION_DELAY);
|
|
274
257
|
|
|
275
258
|
expect(props.onSuccess).toHaveBeenCalledWith('ServerResponse', TEST_FILE.name);
|
|
276
259
|
});
|
|
@@ -278,15 +261,11 @@ describe('Upload', () => {
|
|
|
278
261
|
it('wont process new file while current process is in progress', async () => {
|
|
279
262
|
component = mount(<Upload {...props} httpOptions={{ url: 'a-url' }} />).children();
|
|
280
263
|
|
|
281
|
-
await
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const result = await act(async () => component.instance().fileDropped(TEST_FILE));
|
|
264
|
+
await component.instance().fileDropped(TEST_FILE);
|
|
265
|
+
const result = await component.instance().fileDropped(TEST_FILE);
|
|
266
|
+
jest.advanceTimersByTime(props.animationDelay + ANIMATION_DELAY);
|
|
285
267
|
|
|
286
268
|
expect(result).toBe(false);
|
|
287
|
-
|
|
288
|
-
await waitForUpload();
|
|
289
|
-
|
|
290
269
|
expect(props.onSuccess).toHaveBeenCalledTimes(1);
|
|
291
270
|
});
|
|
292
271
|
});
|
|
@@ -7,7 +7,8 @@ import { mockMatchMedia, render, screen, waitFor, waitForElementToBeRemoved } fr
|
|
|
7
7
|
import UploadInput, { UploadInputProps } from './UploadInput';
|
|
8
8
|
import { TEST_IDS as UPLOAD_BUTTON_TEST_IDS } from './uploadButton/UploadButton';
|
|
9
9
|
import { TEST_IDS as UPLOAD_ITEM_TEST_IDS } from './uploadItem/UploadItem';
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
const spiedDateObject = jest.spyOn(global, 'Date');
|
|
11
12
|
|
|
12
13
|
mockMatchMedia();
|
|
13
14
|
|
|
@@ -41,35 +42,43 @@ describe('UploadInput', () => {
|
|
|
41
42
|
render(<UploadInput {...customProps} />);
|
|
42
43
|
|
|
43
44
|
beforeEach(() => {
|
|
44
|
-
jest.
|
|
45
|
+
(spiedDateObject as jest.Mock).mockImplementation(() => ({
|
|
46
|
+
getTime: jest.fn().mockReturnValue(Math.random()),
|
|
47
|
+
}));
|
|
45
48
|
});
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
jest.useRealTimers();
|
|
50
|
+
afterAll(() => {
|
|
51
|
+
(spiedDateObject as jest.Mock).mockRestore();
|
|
50
52
|
});
|
|
51
53
|
|
|
52
54
|
describe('single file upload', () => {
|
|
53
55
|
it('should trigger onUploadFiles & onFilesChange with a single FormData entry containing `file` field', async () => {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
+
const mockTimeStampValue1 = '11111111';
|
|
57
|
+
const mockTimeStampValue2 = '22222222';
|
|
58
|
+
(spiedDateObject as jest.Mock).mockImplementation(() => ({
|
|
59
|
+
getTime: jest
|
|
60
|
+
.fn()
|
|
61
|
+
.mockReturnValueOnce(mockTimeStampValue1)
|
|
62
|
+
.mockReturnValueOnce(mockTimeStampValue2),
|
|
63
|
+
}));
|
|
56
64
|
|
|
57
65
|
const onFilesChange = jest.fn();
|
|
58
66
|
renderComponent({ ...props, onFilesChange });
|
|
59
67
|
|
|
60
68
|
const input = screen.getByTestId(UPLOAD_BUTTON_TEST_IDS.uploadInput);
|
|
61
69
|
userEvent.upload(input, [pngFile, jpgFile]);
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
|
|
71
|
+
await waitFor(() => {
|
|
72
|
+
expect(props.onUploadFile).toHaveBeenCalledTimes(1);
|
|
64
73
|
});
|
|
65
74
|
|
|
66
|
-
expect(props.onUploadFile).toHaveBeenCalledTimes(1);
|
|
67
75
|
expect(onFilesChange).toHaveBeenCalledTimes(2);
|
|
68
76
|
expect(onFilesChange).toHaveBeenNthCalledWith(1, [
|
|
69
77
|
{
|
|
70
78
|
filename: 'foo.png',
|
|
71
|
-
id: `foo.png_3_${
|
|
79
|
+
id: `foo.png_3_${mockTimeStampValue1}`,
|
|
72
80
|
status: 'pending',
|
|
81
|
+
url: undefined,
|
|
73
82
|
},
|
|
74
83
|
]);
|
|
75
84
|
|
|
@@ -141,10 +150,6 @@ describe('UploadInput', () => {
|
|
|
141
150
|
|
|
142
151
|
const fileToDelete = screen.getAllByTestId(UPLOAD_ITEM_TEST_IDS.uploadItem)[0];
|
|
143
152
|
within(fileToDelete).getByLabelText('Remove file', { exact: false }).click();
|
|
144
|
-
await act(async () => {
|
|
145
|
-
await jest.runOnlyPendingTimersAsync();
|
|
146
|
-
});
|
|
147
|
-
|
|
148
153
|
screen.getByText('Remove').click();
|
|
149
154
|
|
|
150
155
|
await waitForElementToBeRemoved(fileToDelete);
|
|
@@ -174,7 +179,7 @@ describe('UploadInput', () => {
|
|
|
174
179
|
]);
|
|
175
180
|
});
|
|
176
181
|
|
|
177
|
-
it('should delete file with failed state without modal confirmation',
|
|
182
|
+
it('should delete file with failed state without modal confirmation', () => {
|
|
178
183
|
const files = [
|
|
179
184
|
{
|
|
180
185
|
id: 1,
|
|
@@ -192,9 +197,6 @@ describe('UploadInput', () => {
|
|
|
192
197
|
|
|
193
198
|
const fileToDelete = screen.getAllByTestId(UPLOAD_ITEM_TEST_IDS.uploadItem)[0];
|
|
194
199
|
within(fileToDelete).getByLabelText('Remove file', { exact: false }).click();
|
|
195
|
-
await act(async () => {
|
|
196
|
-
await jest.runOnlyPendingTimersAsync();
|
|
197
|
-
});
|
|
198
200
|
|
|
199
201
|
expect(fileToDelete).not.toBeInTheDocument();
|
|
200
202
|
|
|
@@ -238,7 +240,7 @@ describe('UploadInput', () => {
|
|
|
238
240
|
onUploadFile: mockOnUploadFileFn,
|
|
239
241
|
});
|
|
240
242
|
|
|
241
|
-
mockOnUploadFileFn.mockImplementation(
|
|
243
|
+
mockOnUploadFileFn.mockImplementation((formData: FormData) => {
|
|
242
244
|
const file = formData.get('file');
|
|
243
245
|
return Promise.resolve({ file, id: Math.random() });
|
|
244
246
|
});
|
|
@@ -266,7 +268,7 @@ describe('UploadInput', () => {
|
|
|
266
268
|
onUploadFile: mockOnUploadFileFn,
|
|
267
269
|
});
|
|
268
270
|
|
|
269
|
-
mockOnUploadFileFn.mockImplementation(
|
|
271
|
+
mockOnUploadFileFn.mockImplementation((formData: FormData) => {
|
|
270
272
|
const file = formData.get('file');
|
|
271
273
|
return Promise.resolve({ file, id: Math.random() });
|
|
272
274
|
});
|
|
@@ -83,7 +83,9 @@ const UploadItem = ({
|
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
const getErrorMessage = () =>
|
|
86
|
-
typeof error === 'object'
|
|
86
|
+
(typeof error === 'object' && error.message) ||
|
|
87
|
+
error ||
|
|
88
|
+
formatMessage(MESSAGES.uploadingFailed);
|
|
87
89
|
|
|
88
90
|
const getDescription = () => {
|
|
89
91
|
if (error || status === Status.FAILED) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { mount } from 'enzyme/build';
|
|
2
|
-
import { act } from 'react';
|
|
3
2
|
|
|
4
3
|
import { HistoryNavigator } from '../common';
|
|
5
4
|
import { fakeKeyDownEventForKey } from '../common/fakeEvents';
|
|
@@ -7,6 +6,8 @@ import { Input } from '../inputs/Input';
|
|
|
7
6
|
|
|
8
7
|
import WithDisplayFormat from '.';
|
|
9
8
|
|
|
9
|
+
jest.useFakeTimers();
|
|
10
|
+
|
|
10
11
|
const REDO_EVENT = { ctrlKey: true, charCode: 'z', shiftKey: true, which: 90 };
|
|
11
12
|
const UNDO_EVENT = { ctrlKey: true, charCode: 'z', which: 90 };
|
|
12
13
|
|
|
@@ -35,13 +36,11 @@ describe('InputWithTextFormat', () => {
|
|
|
35
36
|
};
|
|
36
37
|
|
|
37
38
|
beforeEach(() => {
|
|
38
|
-
jest.useFakeTimers();
|
|
39
39
|
component = mountComponent(props);
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
afterEach(
|
|
43
|
-
|
|
44
|
-
jest.useRealTimers();
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
jest.clearAllTimers();
|
|
45
44
|
});
|
|
46
45
|
|
|
47
46
|
TESTS.forEach((test) => {
|
|
@@ -65,12 +64,10 @@ describe('InputWithTextFormat', () => {
|
|
|
65
64
|
});
|
|
66
65
|
|
|
67
66
|
describe('when Undo/Redo is preformed', () => {
|
|
68
|
-
it(`goes back/forward in input value's history`,
|
|
67
|
+
it(`goes back/forward in input value's history`, () => {
|
|
69
68
|
component.setProps({ displayPattern: '***' });
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
historyNavigator: new HistoryNavigator(['@', '@@', '@@@']),
|
|
73
|
-
});
|
|
69
|
+
component.setState({
|
|
70
|
+
historyNavigator: new HistoryNavigator(['@', '@@', '@@@']),
|
|
74
71
|
});
|
|
75
72
|
|
|
76
73
|
componentInput().simulate('keyDown', UNDO_EVENT);
|
|
@@ -139,10 +136,8 @@ describe('InputWithTextFormat', () => {
|
|
|
139
136
|
expect(componentInput().props().value).toBe('12-3');
|
|
140
137
|
});
|
|
141
138
|
|
|
142
|
-
it(`performs an extra delete if next char is a separator`,
|
|
143
|
-
|
|
144
|
-
component.setState({ selectionStart: 3, selectionEnd: 3 });
|
|
145
|
-
});
|
|
139
|
+
it(`performs an extra delete if next char is a separator`, () => {
|
|
140
|
+
component.setState({ selectionStart: 3, selectionEnd: 3 });
|
|
146
141
|
|
|
147
142
|
componentInput().simulate('change', { target: { value: '123' } });
|
|
148
143
|
expect(componentInput().props().value).toBe('13');
|
|
@@ -157,41 +152,27 @@ describe('InputWithTextFormat', () => {
|
|
|
157
152
|
});
|
|
158
153
|
});
|
|
159
154
|
|
|
160
|
-
it(`when entered a char`,
|
|
161
|
-
|
|
162
|
-
component.setState({ selectionStart: 4, selectionEnd: 4 });
|
|
163
|
-
});
|
|
155
|
+
it(`when entered a char`, () => {
|
|
156
|
+
component.setState({ selectionStart: 4, selectionEnd: 4 });
|
|
164
157
|
componentInput().simulate('change', { target: { value: '13-4@' } });
|
|
165
|
-
|
|
166
|
-
await jest.runOnlyPendingTimersAsync();
|
|
167
|
-
});
|
|
158
|
+
jest.runAllTimers();
|
|
168
159
|
expect(component.state().selectionStart).toBe(5);
|
|
169
160
|
});
|
|
170
161
|
|
|
171
|
-
it(`when entered a char before a symbol`,
|
|
172
|
-
|
|
173
|
-
component.setState({ selectionStart: 2, selectionEnd: 2 });
|
|
174
|
-
});
|
|
162
|
+
it(`when entered a char before a symbol`, () => {
|
|
163
|
+
component.setState({ selectionStart: 2, selectionEnd: 2 });
|
|
175
164
|
componentInput().simulate('change', { target: { value: '13-@' } });
|
|
176
|
-
|
|
177
|
-
await jest.runOnlyPendingTimersAsync();
|
|
178
|
-
});
|
|
165
|
+
jest.runAllTimers();
|
|
179
166
|
expect(component.state().selectionStart).toBe(4);
|
|
180
167
|
});
|
|
181
168
|
//
|
|
182
|
-
it(`when deleted a char before the symbol`,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
triggerEvent: { ...triggerEventA, key: 'Backspace' },
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
await act(async () => {
|
|
189
|
-
component.setState({ selectionStart: 3, selectionEnd: 3 });
|
|
169
|
+
it(`when deleted a char before the symbol`, () => {
|
|
170
|
+
component.setState({
|
|
171
|
+
triggerEvent: { ...triggerEventA, key: 'Backspace' },
|
|
190
172
|
});
|
|
173
|
+
component.setState({ selectionStart: 3, selectionEnd: 3 });
|
|
191
174
|
componentInput().simulate('change', { target: { value: '13-45-6' } });
|
|
192
|
-
|
|
193
|
-
await jest.runOnlyPendingTimersAsync();
|
|
194
|
-
});
|
|
175
|
+
jest.runAllTimers();
|
|
195
176
|
expect(component.state().selectionStart).toBe(1);
|
|
196
177
|
});
|
|
197
178
|
|
|
@@ -206,38 +187,26 @@ describe('InputWithTextFormat', () => {
|
|
|
206
187
|
expect(component.state().selectionStart).toBe(2);
|
|
207
188
|
});
|
|
208
189
|
|
|
209
|
-
it(`when pasted selection is entered after a symbol`,
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
pastedLength: 2,
|
|
214
|
-
});
|
|
190
|
+
it(`when pasted selection is entered after a symbol`, () => {
|
|
191
|
+
component.setState({
|
|
192
|
+
triggerType: 'Paste',
|
|
193
|
+
pastedLength: 2,
|
|
215
194
|
});
|
|
216
195
|
|
|
217
|
-
|
|
218
|
-
component.setState({ selectionStart: 2, selectionEnd: 2 });
|
|
219
|
-
});
|
|
196
|
+
component.setState({ selectionStart: 2, selectionEnd: 2 });
|
|
220
197
|
componentInput().simulate('change', { target: { value: '13-@@' } });
|
|
221
|
-
|
|
222
|
-
await jest.runOnlyPendingTimersAsync();
|
|
223
|
-
});
|
|
198
|
+
jest.runAllTimers();
|
|
224
199
|
expect(component.state().selectionStart).toBe(5);
|
|
225
200
|
});
|
|
226
201
|
|
|
227
|
-
it(`when pasted selection is entered before a symbol`,
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
pastedLength: 2,
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
await act(async () => {
|
|
235
|
-
component.setState({ selectionStart: 1, selectionEnd: 1 });
|
|
202
|
+
it(`when pasted selection is entered before a symbol`, () => {
|
|
203
|
+
component.setState({
|
|
204
|
+
triggerType: 'Paste',
|
|
205
|
+
pastedLength: 2,
|
|
236
206
|
});
|
|
207
|
+
component.setState({ selectionStart: 1, selectionEnd: 1 });
|
|
237
208
|
componentInput().simulate('change', { target: { value: '1@-@' } });
|
|
238
|
-
|
|
239
|
-
await jest.runOnlyPendingTimersAsync();
|
|
240
|
-
});
|
|
209
|
+
jest.runAllTimers();
|
|
241
210
|
expect(component.state().selectionStart).toBe(4);
|
|
242
211
|
});
|
|
243
212
|
|