@transferwise/components 0.0.0-experimental-da6dbbf → 0.0.0-experimental-4c1cb43

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 (96) hide show
  1. package/build/index.js +635 -933
  2. package/build/index.js.map +1 -1
  3. package/build/index.mjs +625 -922
  4. package/build/index.mjs.map +1 -1
  5. package/build/main.css +0 -135
  6. package/build/styles/main.css +0 -135
  7. package/build/types/accordion/AccordionItem/AccordionItem.d.ts.map +1 -1
  8. package/build/types/common/card/Card.d.ts +2 -2
  9. package/build/types/common/card/Card.d.ts.map +1 -1
  10. package/build/types/common/hooks/useMedia.d.ts.map +1 -1
  11. package/build/types/common/panel/Panel.d.ts.map +1 -1
  12. package/build/types/common/responsivePanel/ResponsivePanel.d.ts.map +1 -1
  13. package/build/types/dateLookup/DateLookup.d.ts +6 -5
  14. package/build/types/dateLookup/DateLookup.d.ts.map +1 -1
  15. package/build/types/dimmer/Dimmer.d.ts +1 -11
  16. package/build/types/dimmer/Dimmer.d.ts.map +1 -1
  17. package/build/types/drawer/Drawer.d.ts +4 -4
  18. package/build/types/index.d.ts +3 -4
  19. package/build/types/index.d.ts.map +1 -1
  20. package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts +2 -1
  21. package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts.map +1 -1
  22. package/build/types/inputs/SelectInput.d.ts.map +1 -1
  23. package/build/types/inputs/contexts.d.ts +2 -2
  24. package/build/types/inputs/contexts.d.ts.map +1 -1
  25. package/build/types/modal/Modal.d.ts.map +1 -1
  26. package/build/types/processIndicator/ProcessIndicator.d.ts +36 -19
  27. package/build/types/processIndicator/ProcessIndicator.d.ts.map +1 -1
  28. package/build/types/processIndicator/index.d.ts +2 -2
  29. package/build/types/processIndicator/index.d.ts.map +1 -1
  30. package/build/types/promoCard/PromoCard.d.ts +5 -16
  31. package/build/types/promoCard/PromoCard.d.ts.map +1 -1
  32. package/build/types/select/searchBox/SearchBox.d.ts +1 -1
  33. package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts +2 -1
  34. package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts.map +1 -1
  35. package/build/types/tooltip/Tooltip.d.ts +1 -1
  36. package/build/types/tooltip/Tooltip.d.ts.map +1 -1
  37. package/build/types/uploadInput/uploadItem/UploadItem.d.ts.map +1 -1
  38. package/build/types/withDisplayFormat/WithDisplayFormat.d.ts +14 -14
  39. package/build/types/withDisplayFormat/WithDisplayFormat.d.ts.map +1 -1
  40. package/package.json +9 -13
  41. package/src/accordion/AccordionItem/AccordionItem.tsx +2 -4
  42. package/src/avatarWrapper/AvatarWrapper.story.tsx +1 -3
  43. package/src/button/Button.tsx +1 -1
  44. package/src/common/card/Card.tsx +43 -51
  45. package/src/common/hooks/useConditionalListener/useConditionalListener.spec.js +1 -1
  46. package/src/common/hooks/useHasIntersected/useHasIntersected.spec.js +3 -3
  47. package/src/common/hooks/useMedia.spec.ts +1 -1
  48. package/src/common/hooks/useMedia.ts +1 -2
  49. package/src/common/panel/Panel.tsx +90 -92
  50. package/src/common/responsivePanel/ResponsivePanel.tsx +34 -38
  51. package/src/dateLookup/DateLookup.rtl.spec.tsx +181 -5
  52. package/src/dateLookup/DateLookup.testingLibrary.spec.js +171 -124
  53. package/src/dateLookup/DateLookup.tsx +14 -9
  54. package/src/drawer/Drawer.js +3 -3
  55. package/src/field/Field.tsx +3 -3
  56. package/src/index.ts +3 -4
  57. package/src/inputWithDisplayFormat/InputWithDisplayFormat.tsx +2 -1
  58. package/src/inputs/SelectInput.story.tsx +2 -1
  59. package/src/inputs/SelectInput.tsx +10 -2
  60. package/src/inputs/contexts.tsx +4 -4
  61. package/src/main.css +0 -135
  62. package/src/main.less +0 -1
  63. package/src/modal/Modal.tsx +1 -2
  64. package/src/processIndicator/ProcessIndicator.rtl.spec.tsx +45 -0
  65. package/src/processIndicator/ProcessIndicator.tsx +110 -0
  66. package/src/promoCard/PromoCard.story.tsx +2 -2
  67. package/src/promoCard/PromoCard.tsx +9 -31
  68. package/src/radio/__snapshots__/Radio.rtl.spec.tsx.snap +0 -1
  69. package/src/snackbar/Snackbar.spec.js +4 -1
  70. package/src/snackbar/Snackbar.story.tsx +4 -2
  71. package/src/tabs/Tabs.spec.js +46 -27
  72. package/src/test-utils/index.js +5 -7
  73. package/src/test-utils/jest.setup.js +9 -3
  74. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.tsx +2 -1
  75. package/src/tooltip/Tooltip.tsx +44 -46
  76. package/src/tooltip/__snapshots__/Tooltip.spec.tsx.snap +2 -2
  77. package/src/upload/Upload.spec.js +34 -13
  78. package/src/uploadInput/UploadInput.spec.tsx +21 -23
  79. package/src/uploadInput/uploadItem/UploadItem.tsx +1 -3
  80. package/src/withDisplayFormat/WithDisplayFormat.spec.js +63 -32
  81. package/src/withDisplayFormat/WithDisplayFormat.tsx +28 -28
  82. package/build/styles/carousel/Carousel.css +0 -135
  83. package/build/types/carousel/Carousel.d.ts +0 -26
  84. package/build/types/carousel/Carousel.d.ts.map +0 -1
  85. package/build/types/carousel/index.d.ts +0 -3
  86. package/build/types/carousel/index.d.ts.map +0 -1
  87. package/src/carousel/Carousel.css +0 -135
  88. package/src/carousel/Carousel.less +0 -133
  89. package/src/carousel/Carousel.spec.tsx +0 -221
  90. package/src/carousel/Carousel.story.tsx +0 -63
  91. package/src/carousel/Carousel.tsx +0 -345
  92. package/src/carousel/index.ts +0 -3
  93. package/src/dateLookup/DateLookup.keyboardEvents.spec.js +0 -180
  94. package/src/processIndicator/ProcessIndicator.js +0 -117
  95. package/src/processIndicator/ProcessIndicator.spec.js +0 -101
  96. /package/src/processIndicator/{index.js → index.ts} +0 -0
@@ -1,5 +1,4 @@
1
- import { render } from '@testing-library/react';
2
- import { renderHook } from '@testing-library/react-hooks';
1
+ import { render, renderHook } from '@testing-library/react';
3
2
  import userEvent from '@testing-library/user-event';
4
3
 
5
4
  import { Provider } from '..';
@@ -30,9 +29,8 @@ function customRenderHook(callback, { locale = DEFAULT_LOCALE, messages = en } =
30
29
  });
31
30
  }
32
31
 
33
- export * from './window-mock';
34
- export * from './story-config';
35
- export * from './fake-data';
36
32
  export * from '@testing-library/react';
37
- export { userEvent };
38
- export { customRender as render, customRenderHook as renderHook };
33
+ export * from './fake-data';
34
+ export * from './story-config';
35
+ export * from './window-mock';
36
+ export { customRender as render, customRenderHook as renderHook, userEvent };
@@ -1,17 +1,23 @@
1
- const Adapter = require('@wojtekmaj/enzyme-adapter-react-17');
1
+ const { default: Adapter } = require('@cfaester/enzyme-adapter-react-18');
2
2
  const Enzyme = require('enzyme');
3
+ const util = require('node:util');
3
4
 
4
5
  global.fetch = require('jest-fetch-mock');
6
+
5
7
  Enzyme.configure({ adapter: new Adapter() });
6
8
 
7
9
  global.requestAnimationFrame = (callback) => callback();
8
10
 
11
+ Object.defineProperty(global, 'TextEncoder', {
12
+ value: util.TextEncoder,
13
+ });
14
+
9
15
  // https://github.com/esphen/jest-prop-type-error/blob/master/index.js
10
16
  // This mock will make tests fail when props error occurs.
11
17
  const { error, warn } = console;
12
18
  // eslint-disable-next-line no-console
13
19
  console.error = (message, ...args) => {
14
- if (/(Invalid prop|Failed prop type)/gi.test(message)) {
20
+ if (/(Invalid prop|Failed prop type)/i.test(message)) {
15
21
  throw new Error(message);
16
22
  }
17
23
 
@@ -20,7 +26,7 @@ console.error = (message, ...args) => {
20
26
 
21
27
  // eslint-disable-next-line no-console
22
28
  console.warn = (message, ...args) => {
23
- if (/(Call to useTheme outside a ThemeProvider)/gi.test(message)) {
29
+ if (/(Call to useTheme outside a ThemeProvider)/i.test(message)) {
24
30
  return;
25
31
  }
26
32
 
@@ -1,7 +1,8 @@
1
1
  import { TextArea, type TextAreaProps } from '../inputs/TextArea';
2
2
  import WithDisplayFormat, { type WithDisplayFormatProps } from '../withDisplayFormat';
3
3
 
4
- export interface TextareaWithDisplayFormatProps extends Omit<WithDisplayFormatProps, 'render'> {}
4
+ export interface TextareaWithDisplayFormatProps
5
+ extends Omit<WithDisplayFormatProps<TextAreaProps>, 'render'> {}
5
6
 
6
7
  const TextareaWithDisplayFormat = (props: TextareaWithDisplayFormatProps) => (
7
8
  <WithDisplayFormat<TextAreaProps>
@@ -1,14 +1,14 @@
1
1
  /* eslint-disable @typescript-eslint/ban-ts-comment */
2
- import { useId } from '@radix-ui/react-id';
3
2
  import classNames from 'classnames';
4
3
  import {
4
+ PropsWithChildren,
5
+ ReactElement,
6
+ ReactNode,
5
7
  cloneElement,
8
+ useEffect,
9
+ useId,
6
10
  useRef,
7
11
  useState,
8
- useEffect,
9
- ReactNode,
10
- ReactElement,
11
- PropsWithChildren,
12
12
  } from 'react';
13
13
  import { usePopper } from 'react-popper';
14
14
 
@@ -75,49 +75,47 @@ const Tooltip = ({
75
75
  }, [open]);
76
76
 
77
77
  return (
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)}
78
+ <span
79
+ ref={anchorReference}
80
+ className="tw-tooltip-container"
81
+ onMouseOver={() => setOpen(true)}
82
+ onFocus={() => setOpen(true)}
83
+ onMouseOut={() => setOpen(false)}
84
+ onBlur={() => setOpen(false)}
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`}
86
106
  >
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>
107
+ <div className="np-panel__content tooltip-inner">
108
+ {label}
109
+ <div
110
+ // @ts-expect-error
111
+ ref={setArrowElement}
112
+ className={classNames('np-panel__arrow')}
113
+ // eslint-disable-next-line react/forbid-dom-props
114
+ style={styles.arrow}
115
+ />
118
116
  </div>
119
- </span>
120
- </>
117
+ </div>
118
+ </span>
121
119
  );
122
120
  };
123
121
 
@@ -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="radix-0-tooltip"
9
+ aria-describedby=":r0:-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="radix-0-tooltip"
16
+ id=":r0:-tooltip"
17
17
  role="tooltip"
18
18
  style="position: absolute; left: 0px; top: 0px;"
19
19
  >
@@ -1,4 +1,5 @@
1
1
  import { shallow, mount } from 'enzyme';
2
+ import { act } from 'react';
2
3
 
3
4
  import { ANIMATION_DURATION_IN_MS } from '../processIndicator';
4
5
 
@@ -6,7 +7,6 @@ import { CompleteStep, UploadImageStep, MediaUploadStep, ProcessingStep } from '
6
7
 
7
8
  import Upload from '.';
8
9
 
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) => `${id}`;
18
+ const formatMessage = (id) => String(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) => `${id}` }} />
23
+ <Component {...props} intl={{ locale: defaultLocale, formatMessage: (id) => String(id) }} />
24
24
  );
25
25
  },
26
26
  useIntl: () => ({ formatMessage }),
@@ -87,11 +87,14 @@ const COMPLETED_STEP_PROPS = {
87
87
  describe('Upload', () => {
88
88
  let component;
89
89
  beforeEach(() => {
90
+ jest.useFakeTimers();
90
91
  component = shallow(<Upload {...props} />).dive();
91
92
  asyncFileRead.mockImplementation(async () => 'a value');
92
93
  });
93
94
 
94
- afterEach(() => {
95
+ afterEach(async () => {
96
+ await jest.runOnlyPendingTimersAsync();
97
+ jest.useRealTimers();
95
98
  jest.clearAllMocks();
96
99
  jest.clearAllTimers();
97
100
  });
@@ -213,6 +216,14 @@ describe('Upload', () => {
213
216
  });
214
217
 
215
218
  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
+
216
227
  it('step changes from UploadImageStep to CompleteStep', async () => {
217
228
  component = mount(<Upload {...props} />);
218
229
  const upload = component.children();
@@ -220,8 +231,10 @@ describe('Upload', () => {
220
231
  expect(upload.find(ProcessingStep)).toHaveLength(0);
221
232
  expect(upload.find(CompleteStep)).toHaveLength(0);
222
233
 
223
- await upload.instance().fileDropped(TEST_FILE);
224
- jest.advanceTimersByTime(props.animationDelay + ANIMATION_DELAY);
234
+ await act(async () => {
235
+ await upload.instance().fileDropped(TEST_FILE);
236
+ });
237
+ await waitForUpload();
225
238
  component.update();
226
239
 
227
240
  expect(component.find(UploadImageStep)).toHaveLength(0);
@@ -236,8 +249,10 @@ describe('Upload', () => {
236
249
  throw 'An error';
237
250
  });
238
251
 
239
- await upload.instance().fileDropped(TEST_FILE);
240
- jest.advanceTimersByTime(props.animationDelay + ANIMATION_DELAY);
252
+ await act(async () => {
253
+ await upload.instance().fileDropped(TEST_FILE);
254
+ });
255
+ await waitForUpload();
241
256
  component.update();
242
257
 
243
258
  expect(component.find(CompleteStep).props()).toStrictEqual({
@@ -252,8 +267,10 @@ describe('Upload', () => {
252
267
  it('onSuccess is called with response when httpOptions are provided', async () => {
253
268
  component = mount(<Upload {...props} httpOptions={{ url: 'a-url' }} />).children();
254
269
 
255
- await component.instance().fileDropped(TEST_FILE);
256
- jest.advanceTimersByTime(props.animationDelay + ANIMATION_DELAY);
270
+ await act(async () => {
271
+ await component.instance().fileDropped(TEST_FILE);
272
+ });
273
+ await waitForUpload();
257
274
 
258
275
  expect(props.onSuccess).toHaveBeenCalledWith('ServerResponse', TEST_FILE.name);
259
276
  });
@@ -261,11 +278,15 @@ describe('Upload', () => {
261
278
  it('wont process new file while current process is in progress', async () => {
262
279
  component = mount(<Upload {...props} httpOptions={{ url: 'a-url' }} />).children();
263
280
 
264
- await component.instance().fileDropped(TEST_FILE);
265
- const result = await component.instance().fileDropped(TEST_FILE);
266
- jest.advanceTimersByTime(props.animationDelay + ANIMATION_DELAY);
281
+ await act(async () => {
282
+ await component.instance().fileDropped(TEST_FILE);
283
+ });
284
+ const result = await act(async () => component.instance().fileDropped(TEST_FILE));
267
285
 
268
286
  expect(result).toBe(false);
287
+
288
+ await waitForUpload();
289
+
269
290
  expect(props.onSuccess).toHaveBeenCalledTimes(1);
270
291
  });
271
292
  });
@@ -7,8 +7,7 @@ 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
-
11
- const spiedDateObject = jest.spyOn(global, 'Date');
10
+ import { act } from 'react';
12
11
 
13
12
  mockMatchMedia();
14
13
 
@@ -42,43 +41,35 @@ describe('UploadInput', () => {
42
41
  render(<UploadInput {...customProps} />);
43
42
 
44
43
  beforeEach(() => {
45
- (spiedDateObject as jest.Mock).mockImplementation(() => ({
46
- getTime: jest.fn().mockReturnValue(Math.random()),
47
- }));
44
+ jest.useFakeTimers();
48
45
  });
49
46
 
50
- afterAll(() => {
51
- (spiedDateObject as jest.Mock).mockRestore();
47
+ afterEach(async () => {
48
+ await jest.runOnlyPendingTimersAsync();
49
+ jest.useRealTimers();
52
50
  });
53
51
 
54
52
  describe('single file upload', () => {
55
53
  it('should trigger onUploadFiles & onFilesChange with a single FormData entry containing `file` field', async () => {
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
- }));
54
+ const date = Date.now();
55
+ jest.setSystemTime(date);
64
56
 
65
57
  const onFilesChange = jest.fn();
66
58
  renderComponent({ ...props, onFilesChange });
67
59
 
68
60
  const input = screen.getByTestId(UPLOAD_BUTTON_TEST_IDS.uploadInput);
69
61
  userEvent.upload(input, [pngFile, jpgFile]);
70
-
71
- await waitFor(() => {
72
- expect(props.onUploadFile).toHaveBeenCalledTimes(1);
62
+ await act(async () => {
63
+ await jest.runOnlyPendingTimersAsync();
73
64
  });
74
65
 
66
+ expect(props.onUploadFile).toHaveBeenCalledTimes(1);
75
67
  expect(onFilesChange).toHaveBeenCalledTimes(2);
76
68
  expect(onFilesChange).toHaveBeenNthCalledWith(1, [
77
69
  {
78
70
  filename: 'foo.png',
79
- id: `foo.png_3_${mockTimeStampValue1}`,
71
+ id: `foo.png_3_${date}`,
80
72
  status: 'pending',
81
- url: undefined,
82
73
  },
83
74
  ]);
84
75
 
@@ -150,6 +141,10 @@ describe('UploadInput', () => {
150
141
 
151
142
  const fileToDelete = screen.getAllByTestId(UPLOAD_ITEM_TEST_IDS.uploadItem)[0];
152
143
  within(fileToDelete).getByLabelText('Remove file', { exact: false }).click();
144
+ await act(async () => {
145
+ await jest.runOnlyPendingTimersAsync();
146
+ });
147
+
153
148
  screen.getByText('Remove').click();
154
149
 
155
150
  await waitForElementToBeRemoved(fileToDelete);
@@ -179,7 +174,7 @@ describe('UploadInput', () => {
179
174
  ]);
180
175
  });
181
176
 
182
- it('should delete file with failed state without modal confirmation', () => {
177
+ it('should delete file with failed state without modal confirmation', async () => {
183
178
  const files = [
184
179
  {
185
180
  id: 1,
@@ -197,6 +192,9 @@ describe('UploadInput', () => {
197
192
 
198
193
  const fileToDelete = screen.getAllByTestId(UPLOAD_ITEM_TEST_IDS.uploadItem)[0];
199
194
  within(fileToDelete).getByLabelText('Remove file', { exact: false }).click();
195
+ await act(async () => {
196
+ await jest.runOnlyPendingTimersAsync();
197
+ });
200
198
 
201
199
  expect(fileToDelete).not.toBeInTheDocument();
202
200
 
@@ -240,7 +238,7 @@ describe('UploadInput', () => {
240
238
  onUploadFile: mockOnUploadFileFn,
241
239
  });
242
240
 
243
- mockOnUploadFileFn.mockImplementation((formData: FormData) => {
241
+ mockOnUploadFileFn.mockImplementation(async (formData: FormData) => {
244
242
  const file = formData.get('file');
245
243
  return Promise.resolve({ file, id: Math.random() });
246
244
  });
@@ -268,7 +266,7 @@ describe('UploadInput', () => {
268
266
  onUploadFile: mockOnUploadFileFn,
269
267
  });
270
268
 
271
- mockOnUploadFileFn.mockImplementation((formData: FormData) => {
269
+ mockOnUploadFileFn.mockImplementation(async (formData: FormData) => {
272
270
  const file = formData.get('file');
273
271
  return Promise.resolve({ file, id: Math.random() });
274
272
  });
@@ -83,9 +83,7 @@ const UploadItem = ({
83
83
  };
84
84
 
85
85
  const getErrorMessage = () =>
86
- (typeof error === 'object' && error.message) ||
87
- error ||
88
- formatMessage(MESSAGES.uploadingFailed);
86
+ typeof error === 'object' ? error.message : error || formatMessage(MESSAGES.uploadingFailed);
89
87
 
90
88
  const getDescription = () => {
91
89
  if (error || status === Status.FAILED) {
@@ -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.clearAllTimers();
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
- component.setState({
70
- historyNavigator: new HistoryNavigator(['@', '@@', '@@@']),
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
- component.setState({ selectionStart: 3, selectionEnd: 3 });
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
- component.setState({ selectionStart: 4, selectionEnd: 4 });
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
- jest.runAllTimers();
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
- component.setState({ selectionStart: 2, selectionEnd: 2 });
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
- jest.runAllTimers();
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
- component.setState({
171
- triggerEvent: { ...triggerEventA, key: 'Backspace' },
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
- jest.runAllTimers();
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
- component.setState({
192
- triggerType: 'Paste',
193
- pastedLength: 2,
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
- component.setState({ selectionStart: 2, selectionEnd: 2 });
217
+ await act(async () => {
218
+ component.setState({ selectionStart: 2, selectionEnd: 2 });
219
+ });
197
220
  componentInput().simulate('change', { target: { value: '13-@@' } });
198
- jest.runAllTimers();
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
- component.setState({
204
- triggerType: 'Paste',
205
- pastedLength: 2,
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
- jest.runAllTimers();
238
+ await act(async () => {
239
+ await jest.runOnlyPendingTimersAsync();
240
+ });
210
241
  expect(component.state().selectionStart).toBe(4);
211
242
  });
212
243