@transferwise/components 46.79.0 → 46.80.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 (57) hide show
  1. package/build/button/Button.js.map +1 -1
  2. package/build/button/Button.mjs.map +1 -1
  3. package/build/button/legacyUtils/legacyUtils.js.map +1 -1
  4. package/build/button/legacyUtils/legacyUtils.mjs.map +1 -1
  5. package/build/common/dateUtils/getDateView/getDateView.js +10 -0
  6. package/build/common/dateUtils/getDateView/getDateView.js.map +1 -0
  7. package/build/common/dateUtils/getDateView/getDateView.mjs +8 -0
  8. package/build/common/dateUtils/getDateView/getDateView.mjs.map +1 -0
  9. package/build/dateLookup/DateLookup.js +6 -6
  10. package/build/dateLookup/DateLookup.js.map +1 -1
  11. package/build/dateLookup/DateLookup.mjs +6 -6
  12. package/build/dateLookup/DateLookup.mjs.map +1 -1
  13. package/build/dateLookup/dayCalendar/table/DayCalendarTable.js +4 -1
  14. package/build/dateLookup/dayCalendar/table/DayCalendarTable.js.map +1 -1
  15. package/build/dateLookup/dayCalendar/table/DayCalendarTable.mjs +4 -1
  16. package/build/dateLookup/dayCalendar/table/DayCalendarTable.mjs.map +1 -1
  17. package/build/i18n/th.json +5 -0
  18. package/build/i18n/th.json.js +5 -0
  19. package/build/i18n/th.json.js.map +1 -1
  20. package/build/i18n/th.json.mjs +5 -0
  21. package/build/i18n/th.json.mjs.map +1 -1
  22. package/build/types/button/Button.d.ts +1 -1
  23. package/build/types/button/Button.d.ts.map +1 -1
  24. package/build/types/button/legacyUtils/legacyUtils.d.ts +2 -2
  25. package/build/types/button/legacyUtils/legacyUtils.d.ts.map +1 -1
  26. package/build/types/common/dateUtils/getDateView/getDateView.d.ts +2 -0
  27. package/build/types/common/dateUtils/getDateView/getDateView.d.ts.map +1 -0
  28. package/build/types/common/dateUtils/index.d.ts +1 -0
  29. package/build/types/common/dateUtils/index.d.ts.map +1 -1
  30. package/build/types/dateLookup/DateLookup.d.ts +1 -1
  31. package/build/types/dateLookup/DateLookup.d.ts.map +1 -1
  32. package/build/types/dateLookup/dayCalendar/table/DayCalendarTable.d.ts +1 -1
  33. package/build/types/dateLookup/dayCalendar/table/DayCalendarTable.d.ts.map +1 -1
  34. package/build/types/test-utils/index.d.ts +158 -0
  35. package/build/types/test-utils/index.d.ts.map +1 -0
  36. package/build/types/test-utils/jest.setup.d.ts +2 -0
  37. package/build/types/test-utils/jest.setup.d.ts.map +1 -0
  38. package/package.json +3 -2
  39. package/src/button/{Button.spec.js → Button.spec.tsx} +3 -2
  40. package/src/button/Button.tsx +1 -1
  41. package/src/button/legacyUtils/{legacyUtils.spec.js → legacyUtils.spec.tsx} +1 -1
  42. package/src/button/legacyUtils/legacyUtils.ts +2 -2
  43. package/src/common/dateUtils/getDateView/getDateView.ts +5 -0
  44. package/src/common/dateUtils/index.ts +1 -0
  45. package/src/dateLookup/DateLookup.tests.story.tsx +40 -5
  46. package/src/dateLookup/DateLookup.tsx +9 -11
  47. package/src/dateLookup/dayCalendar/table/DayCalendarTable.tsx +5 -2
  48. package/src/i18n/th.json +5 -0
  49. package/src/modal/{Modal.rtl.spec.js → Modal.rtl.spec.tsx} +8 -7
  50. package/src/slidingPanel/SlidingPanel.spec.js +1 -1
  51. package/src/ssr.spec.tsx +264 -0
  52. package/src/test-utils/{index.js → index.tsx} +11 -6
  53. package/src/test-utils/{jest.setup.js → jest.setup.ts} +13 -8
  54. package/src/ssr.spec.js +0 -256
  55. /package/src/button/__snapshots__/{Button.spec.js.snap → Button.spec.tsx.snap} +0 -0
  56. /package/src/dimmer/{Dimmer.rtl.spec.js → Dimmer.rtl.spec.tsx} +0 -0
  57. /package/src/info/{Info.spec.js → Info.spec.jsx} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { formatDate } from '@transferwise/formatting';
2
2
  import { PureComponent } from 'react';
3
- import { injectIntl, WrappedComponentProps } from 'react-intl';
3
+ import { injectIntl, type WrappedComponentProps } from 'react-intl';
4
4
 
5
5
  import { getDayNames, isWithinRange } from '../../../common/dateUtils';
6
6
  import { getFocusableTime } from '../../getFocusableTime/getFocusableTime';
@@ -64,6 +64,9 @@ class DayCalendarTable extends PureComponent<DayCalendarTableProps> {
64
64
  };
65
65
 
66
66
  isDisabled = (day: number) => {
67
+ if (day < 0) {
68
+ return true;
69
+ }
67
70
  const { min, max, viewMonth, viewYear } = this.props;
68
71
  const date = new Date(viewYear, viewMonth, day);
69
72
 
@@ -72,7 +75,7 @@ class DayCalendarTable extends PureComponent<DayCalendarTableProps> {
72
75
 
73
76
  isActive = (day: number) => {
74
77
  const { selectedDate, viewMonth, viewYear } = this.props;
75
- return !!(selectedDate && +new Date(viewYear, viewMonth, day) === +selectedDate);
78
+ return !!(selectedDate && Number(new Date(viewYear, viewMonth, day)) === Number(selectedDate));
76
79
  };
77
80
 
78
81
  isToday = (day: number) => {
package/src/i18n/th.json CHANGED
@@ -27,6 +27,11 @@
27
27
  "neptune.SelectInput.noResultsFound": "ไม่พบผลลัพธ์",
28
28
  "neptune.SelectOption.action.label": "เลือก",
29
29
  "neptune.SelectOption.selected.action.label": "เปลี่ยนตัวเลือกที่เลือกไว้",
30
+ "neptune.StatusIcon.iconLabel.error": "ข้อผิดพลาด:",
31
+ "neptune.StatusIcon.iconLabel.information": "ข้อมูล:",
32
+ "neptune.StatusIcon.iconLabel.pending": "รอดำเนินการ:",
33
+ "neptune.StatusIcon.iconLabel.success": "สำเร็จ:",
34
+ "neptune.StatusIcon.iconLabel.warning": "คำเตือน:",
30
35
  "neptune.Summary.statusDone": "รายการที่ทำแล้ว",
31
36
  "neptune.Summary.statusNotDone": "รายการที่ต้องทำ",
32
37
  "neptune.Summary.statusPending": "รายการที่รอดำเนินการ",
@@ -1,15 +1,16 @@
1
1
  import { Position } from '../common';
2
2
  import { render, fireEvent, screen, mockMatchMedia } from '../test-utils';
3
3
 
4
- import Modal from './Modal';
4
+ import Modal, { ModalProps } from './Modal';
5
5
 
6
6
  mockMatchMedia();
7
7
 
8
8
  describe('Modal', () => {
9
- const props = {
9
+ const props: ModalProps = {
10
10
  onClose: jest.fn(),
11
11
  body: 'Some body',
12
12
  position: Position.TOP,
13
+ open: true,
13
14
  };
14
15
 
15
16
  beforeEach(() => {
@@ -17,14 +18,14 @@ describe('Modal', () => {
17
18
  });
18
19
 
19
20
  it(`doesn't calls onClose when click is inside modal`, () => {
20
- render(<Modal {...props} open />);
21
+ render(<Modal {...props} />);
21
22
 
22
23
  fireEvent.click(getDialog());
23
24
  expect(props.onClose).not.toHaveBeenCalled();
24
25
  });
25
26
 
26
27
  it('calls onClose if click outside the content', () => {
27
- render(<Modal {...props} open />);
28
+ render(<Modal {...props} />);
28
29
  expect(props.onClose).not.toHaveBeenCalled();
29
30
 
30
31
  fireEvent.click(screen.getByRole('presentation'));
@@ -32,7 +33,7 @@ describe('Modal', () => {
32
33
  });
33
34
 
34
35
  it("doesn't call onClose if click outside the content and closing on dimmer is disabled", () => {
35
- render(<Modal {...props} open disableDimmerClickToClose />);
36
+ render(<Modal {...props} disableDimmerClickToClose />);
36
37
 
37
38
  fireEvent.click(screen.getByRole('presentation'));
38
39
 
@@ -40,7 +41,7 @@ describe('Modal', () => {
40
41
  });
41
42
 
42
43
  it('calls onClose when Escape is pressed on Modal', () => {
43
- render(<Modal {...props} open />);
44
+ render(<Modal {...props} />);
44
45
  expect(props.onClose).not.toHaveBeenCalled();
45
46
 
46
47
  fireEvent.keyDown(getDialog(), { key: 'Escape' });
@@ -48,7 +49,7 @@ describe('Modal', () => {
48
49
  });
49
50
 
50
51
  it('calls onClose when Escape is pressed on document', () => {
51
- render(<Modal {...props} open />);
52
+ render(<Modal {...props} />);
52
53
  expect(props.onClose).not.toHaveBeenCalled();
53
54
 
54
55
  fireEvent.keyDown(document, { key: 'Escape' });
@@ -1,6 +1,6 @@
1
1
  import { shallow, mount } from 'enzyme';
2
2
 
3
- import SlidingPanel, { EXIT_ANIMATION } from './SlidingPanel';
3
+ import SlidingPanel from './SlidingPanel';
4
4
 
5
5
  describe('SlidingPanel', () => {
6
6
  let component;
@@ -0,0 +1,264 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+ import { renderToString } from 'react-dom/server';
5
+
6
+ import en from './i18n/en.json';
7
+
8
+ import * as exposedLibraryItems from '.';
9
+
10
+ type ExposedLibraryItemsType = typeof exposedLibraryItems;
11
+ type ExposedLibraryKeysType = keyof ExposedLibraryItemsType;
12
+
13
+ const excluded = new Set<ExposedLibraryKeysType | string>([
14
+ // hooks
15
+ 'useSnackbar',
16
+ 'useDirection',
17
+ 'useLayout',
18
+ 'useScreenSize',
19
+
20
+ // specific components
21
+ 'Provider',
22
+ 'BottomSheet',
23
+ 'DropFade',
24
+ 'SelectInputTriggerButton',
25
+ 'Panel',
26
+ 'ResponsivePanel',
27
+
28
+ // enums
29
+ 'Size',
30
+ 'Width',
31
+ 'Sentiment',
32
+ 'Variant',
33
+ 'Priority',
34
+ 'ControlType',
35
+ 'Type',
36
+ 'Theme',
37
+ 'DateMode',
38
+ 'MonthFormat',
39
+ 'Position',
40
+ 'Scroll',
41
+ 'ProfileType',
42
+ 'Breakpoint',
43
+ 'Layout',
44
+ 'Status',
45
+ 'MarkdownNodeType',
46
+ 'AvatarType',
47
+ 'InfoPresentation',
48
+ 'UploadStep',
49
+ 'DecisionPresentation',
50
+ 'DecisionType',
51
+ 'AlertArrowPosition',
52
+ 'LogoType',
53
+ 'FileType',
54
+ 'Direction',
55
+ 'Typography',
56
+
57
+ // types
58
+ 'SearchInputProps',
59
+ 'SelectInputItem',
60
+ 'SelectInputOptionContentProps',
61
+ 'SelectInputProps',
62
+ 'UploadedFile',
63
+ 'UploadError',
64
+ 'UploadResponse',
65
+ 'LayoutDirection',
66
+
67
+ // utils
68
+ 'SUPPORTED_LANGUAGES',
69
+ 'RTL_LANGUAGES',
70
+ 'DEFAULT_LANG',
71
+ 'DEFAULT_LOCALE',
72
+ 'adjustLocale',
73
+ 'getLangFromLocale',
74
+ 'getCountryFromLocale',
75
+ 'getDirectionFromLocale',
76
+ 'isServerSide',
77
+ 'isBrowser',
78
+
79
+ // other
80
+ 'translations',
81
+ ]);
82
+
83
+ function isNotExcluded(item: ExposedLibraryKeysType) {
84
+ return !excluded.has(item);
85
+ }
86
+
87
+ describe('Server side rendering', () => {
88
+ const componentNames = (
89
+ Object.keys(exposedLibraryItems) as (keyof ExposedLibraryItemsType)[]
90
+ ).filter((moduleName) => isNotExcluded(moduleName));
91
+
92
+ // stick all possible properties we might need to render all components in here
93
+ const allProps: Record<string, unknown> = {
94
+ currencies: [],
95
+ steps: [],
96
+ stepper: {
97
+ steps: [],
98
+ },
99
+ items: [],
100
+ children: 'yo',
101
+ id: '1',
102
+ text: 'test',
103
+ timeout: 0,
104
+ timestamp: 1,
105
+ title: 'trolo',
106
+ name: 'lolo',
107
+ label: 'hello',
108
+ content: 'world',
109
+ currency: 'XYZ',
110
+ amount: 0,
111
+ options: [],
112
+ model: {},
113
+ fields: {},
114
+ media: <h1>Hello</h1>,
115
+ onClick: jest.fn(),
116
+ onChange: jest.fn(),
117
+ status: 'processing',
118
+ size: 'sm',
119
+ body: 'body',
120
+ onClose: jest.fn(),
121
+ onDismiss: jest.fn(),
122
+ onRemove: jest.fn(),
123
+ radios: [
124
+ {
125
+ id: 'id-test-0',
126
+ label: 'Radio1',
127
+ },
128
+ {
129
+ id: 'id-test-0',
130
+ label: 'Radio1',
131
+ },
132
+ ],
133
+ position: 'left',
134
+ open: true,
135
+ tabs: [],
136
+ direction: {
137
+ xs: 'column',
138
+ sm: 'row',
139
+ md: 'column',
140
+ lg: 'row',
141
+ },
142
+ alt: '',
143
+ src: '',
144
+ details: 'yo',
145
+ icon: <svg />,
146
+ badge: <svg />,
147
+ link: 'link',
148
+ href: '#',
149
+ description: 'description',
150
+ 'aria-label': 'a label',
151
+ logo: <svg />,
152
+ chips: [
153
+ {
154
+ value: 1,
155
+ label: 'One',
156
+ },
157
+ {
158
+ value: 2,
159
+ label: 'Two',
160
+ },
161
+ ],
162
+ segments: [
163
+ {
164
+ id: '1',
165
+ value: 'accounting',
166
+ label: 'Accounting',
167
+ },
168
+ {
169
+ id: '2',
170
+ value: 'payroll',
171
+ label: 'Payroll',
172
+ },
173
+ {
174
+ id: '3',
175
+ value: 'reporting',
176
+ label: 'Reporting',
177
+ },
178
+ ],
179
+ };
180
+
181
+ // Override props in case of name collision.
182
+ const overrideProps: Partial<Record<keyof ExposedLibraryItemsType, Record<string, unknown>>> = {
183
+ Alert: { children: undefined, message: 'Fluffy kittens', size: undefined },
184
+ Card: { isExpanded: true },
185
+ CheckboxButton: { children: undefined, onChange: jest.fn() },
186
+ Typeahead: { size: 'md' },
187
+ InputWithDisplayFormat: { displayPattern: '**-**' },
188
+ TextareaWithDisplayFormat: { displayPattern: '**-**' },
189
+ Sticky: { position: 'top' },
190
+ MoneyInput: { selectedCurrency: { currency: 'EUR' } },
191
+ Tabs: { selected: 1, onTabSelect: jest.fn() },
192
+ Markdown: { children: '# Markdown string' },
193
+ SnackbarConsumer: {
194
+ children: jest.fn(),
195
+ },
196
+ SnackbarContext: {
197
+ children: jest.fn(),
198
+ },
199
+ Popover: {
200
+ children: <div />,
201
+ },
202
+ Progress: {
203
+ progress: { value: 50, max: 100 },
204
+ },
205
+ ProgressBar: {
206
+ progress: { value: 50, max: 100 },
207
+ },
208
+ Field: {
209
+ model: 'a model',
210
+ type: 'text',
211
+ children: <input />,
212
+ },
213
+ Input: {
214
+ children: undefined,
215
+ },
216
+ SearchInput: {
217
+ children: undefined,
218
+ },
219
+ TextArea: {
220
+ children: undefined,
221
+ },
222
+ Summary: {
223
+ status: 'done',
224
+ content: undefined,
225
+ },
226
+ Modal: { position: 'top' },
227
+ ActionOption: { action: 'hello' },
228
+ DateLookup: { value: new Date() },
229
+ Link: { size: 16 },
230
+ Tooltip: { children: <>yo</> },
231
+ SelectOption: { placeholder: { media: <img alt="img" /> } },
232
+ };
233
+
234
+ const { Provider } = exposedLibraryItems;
235
+ type ComponentWithProvider = React.ComponentType<unknown> & {
236
+ Provider?: React.ComponentType<unknown>;
237
+ };
238
+
239
+ componentNames.forEach((componentName: ExposedLibraryKeysType) => {
240
+ it(`can render component: ${componentName}`, () => {
241
+ const Component = exposedLibraryItems[componentName] as ComponentWithProvider;
242
+ const newProps = { ...allProps };
243
+
244
+ Object.keys(overrideProps[componentName] ?? {}).forEach((propertyToOverrideKey) => {
245
+ const key = propertyToOverrideKey as keyof (typeof overrideProps)[typeof componentName];
246
+ newProps[key] = overrideProps?.[componentName]?.[key];
247
+ });
248
+
249
+ const view = renderToString(
250
+ <Provider i18n={{ locale: 'en-GB', messages: en }}>
251
+ {componentName.endsWith('Context') && Component.Provider ? (
252
+ <Component.Provider {...newProps} />
253
+ ) : (
254
+ <div>
255
+ <Component {...newProps} />
256
+ </div>
257
+ )}
258
+ </Provider>,
259
+ );
260
+
261
+ expect(view).toStrictEqual(expect.any(String));
262
+ });
263
+ });
264
+ });
@@ -1,8 +1,9 @@
1
+ import { ReactElement, FC } from 'react';
1
2
  import { render, renderHook } from '@testing-library/react';
2
3
  import { userEvent } from '@testing-library/user-event';
3
4
 
4
5
  import { Provider } from '..';
5
- import { DEFAULT_LOCALE } from '../common/locale';
6
+ import { DEFAULT_LOCALE } from '../common';
6
7
  import en from '../i18n/en.json';
7
8
 
8
9
  /**
@@ -10,9 +11,11 @@ import en from '../i18n/en.json';
10
11
  * Source: https://testing-library.com/docs/example-react-intl/#creating-a-custom-render-function
11
12
  *
12
13
  */
13
- function customRender(ui, { locale = DEFAULT_LOCALE, messages = en, ...renderOptions } = {}) {
14
- // eslint-disable-next-line react/prop-types
15
- const Wrapper = ({ children }) => {
14
+ function customRender(
15
+ ui: ReactElement,
16
+ { locale = DEFAULT_LOCALE, messages = en, ...renderOptions } = {},
17
+ ): ReturnType<typeof render> {
18
+ const Wrapper: FC<{ children: React.ReactNode }> = ({ children }) => {
16
19
  return <Provider i18n={{ locale, messages }}>{children}</Provider>;
17
20
  };
18
21
  return render(ui, { wrapper: Wrapper, ...renderOptions });
@@ -21,9 +24,11 @@ function customRender(ui, { locale = DEFAULT_LOCALE, messages = en, ...renderOpt
21
24
  /**
22
25
  * Custom `renderHook` function which wraps passed elements in Provider component
23
26
  * For more info: https://react-hooks-testing-library.com/usage/advanced-hooks#context
24
- *
25
27
  */
26
- function customRenderHook(callback, { locale = DEFAULT_LOCALE, messages = en } = {}) {
28
+ function customRenderHook(
29
+ callback: () => unknown,
30
+ { locale = DEFAULT_LOCALE, messages = en } = {},
31
+ ) {
27
32
  return renderHook(callback, {
28
33
  wrapper: ({ children }) => <Provider i18n={{ locale, messages }}>{children}</Provider>,
29
34
  });
@@ -1,14 +1,19 @@
1
- require('@testing-library/jest-dom');
1
+ import util from 'node:util';
2
+ import '@testing-library/jest-dom';
2
3
 
3
- const { default: Adapter } = require('@cfaester/enzyme-adapter-react-18');
4
- const Enzyme = require('enzyme');
5
- const util = require('node:util');
4
+ import Adapter from '@cfaester/enzyme-adapter-react-18';
5
+ import Enzyme from 'enzyme';
6
+ import fetchMock from 'jest-fetch-mock';
6
7
 
7
- global.fetch = require('jest-fetch-mock');
8
+ global.fetch = fetchMock as unknown as typeof global.fetch;
8
9
 
10
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
9
11
  Enzyme.configure({ adapter: new Adapter() });
10
12
 
11
- global.requestAnimationFrame = (callback) => callback();
13
+ global.requestAnimationFrame = (callback: (time: number) => void): number => {
14
+ callback(performance.now());
15
+ return 0;
16
+ };
12
17
 
13
18
  Object.defineProperty(global, 'TextEncoder', {
14
19
  value: util.TextEncoder,
@@ -18,7 +23,7 @@ Object.defineProperty(global, 'TextEncoder', {
18
23
  // This mock will make tests fail when props error occurs.
19
24
  const { error, warn } = console;
20
25
  // eslint-disable-next-line no-console
21
- console.error = (message, ...args) => {
26
+ console.error = (message: string, ...args: unknown[]): void => {
22
27
  if (/(Invalid prop|Failed prop type)/i.test(message)) {
23
28
  throw new Error(message);
24
29
  }
@@ -27,7 +32,7 @@ console.error = (message, ...args) => {
27
32
  };
28
33
 
29
34
  // eslint-disable-next-line no-console
30
- console.warn = (message, ...args) => {
35
+ console.warn = (message: string, ...args: unknown[]): void => {
31
36
  if (/(Call to useTheme outside a ThemeProvider)/i.test(message)) {
32
37
  return;
33
38
  }