@transferwise/components 46.74.0 → 46.74.1
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/dimmer/Dimmer.js +3 -1
- package/build/dimmer/Dimmer.js.map +1 -1
- package/build/dimmer/Dimmer.mjs +3 -1
- package/build/dimmer/Dimmer.mjs.map +1 -1
- package/build/drawer/Drawer.js +2 -0
- package/build/drawer/Drawer.js.map +1 -1
- package/build/drawer/Drawer.mjs +2 -0
- package/build/drawer/Drawer.mjs.map +1 -1
- package/build/modal/Modal.js +3 -0
- package/build/modal/Modal.js.map +1 -1
- package/build/modal/Modal.mjs +3 -0
- package/build/modal/Modal.mjs.map +1 -1
- package/build/types/dimmer/Dimmer.d.ts +2 -1
- package/build/types/dimmer/Dimmer.d.ts.map +1 -1
- package/build/types/drawer/Drawer.d.ts +2 -1
- package/build/types/drawer/Drawer.d.ts.map +1 -1
- package/build/types/modal/Modal.d.ts +2 -1
- package/build/types/modal/Modal.d.ts.map +1 -1
- package/build/types/uploadInput/UploadInput.d.ts +9 -0
- package/build/types/uploadInput/UploadInput.d.ts.map +1 -1
- package/build/types/uploadInput/uploadItem/UploadItem.d.ts +16 -1
- package/build/types/uploadInput/uploadItem/UploadItem.d.ts.map +1 -1
- package/build/types/uploadInput/uploadItem/UploadItemLink.d.ts.map +1 -1
- package/build/uploadInput/UploadInput.js +71 -66
- package/build/uploadInput/UploadInput.js.map +1 -1
- package/build/uploadInput/UploadInput.mjs +72 -67
- package/build/uploadInput/UploadInput.mjs.map +1 -1
- package/build/uploadInput/uploadItem/UploadItem.js +13 -4
- package/build/uploadInput/uploadItem/UploadItem.js.map +1 -1
- package/build/uploadInput/uploadItem/UploadItem.mjs +13 -4
- package/build/uploadInput/uploadItem/UploadItem.mjs.map +1 -1
- package/build/uploadInput/uploadItem/UploadItemLink.js +1 -0
- package/build/uploadInput/uploadItem/UploadItemLink.js.map +1 -1
- package/build/uploadInput/uploadItem/UploadItemLink.mjs +1 -0
- package/build/uploadInput/uploadItem/UploadItemLink.mjs.map +1 -1
- package/package.json +2 -2
- package/src/dimmer/Dimmer.spec.js +8 -0
- package/src/dimmer/Dimmer.tsx +4 -0
- package/src/drawer/Drawer.spec.js +25 -6
- package/src/drawer/Drawer.tsx +3 -1
- package/src/modal/Modal.spec.js +19 -1
- package/src/modal/Modal.tsx +4 -0
- package/src/uploadInput/UploadInput.spec.tsx +121 -9
- package/src/uploadInput/UploadInput.tests.story.tsx +207 -140
- package/src/uploadInput/UploadInput.tsx +110 -77
- package/src/uploadInput/uploadItem/UploadItem.spec.tsx +1 -0
- package/src/uploadInput/uploadItem/UploadItem.tsx +30 -6
- package/src/uploadInput/uploadItem/UploadItemLink.tsx +9 -1
|
@@ -1,52 +1,52 @@
|
|
|
1
1
|
import { action } from '@storybook/addon-actions';
|
|
2
|
-
import {
|
|
2
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
3
3
|
|
|
4
4
|
import { Status } from '../common';
|
|
5
|
-
|
|
6
5
|
import UploadInput, { UploadInputProps } from './UploadInput';
|
|
7
6
|
import { UploadedFile, UploadResponse } from './types';
|
|
7
|
+
import { userEvent, within } from '@storybook/test';
|
|
8
8
|
|
|
9
9
|
const meta: Meta<typeof UploadInput> = {
|
|
10
10
|
title: 'Forms/UploadInput/Tests',
|
|
11
11
|
component: UploadInput,
|
|
12
12
|
};
|
|
13
|
-
|
|
14
13
|
export default meta;
|
|
15
|
-
type Story = StoryFn<UploadInputProps>;
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
type Story = StoryObj<UploadInputProps>;
|
|
16
|
+
|
|
17
|
+
const files: UploadedFile[] = [
|
|
18
18
|
{
|
|
19
|
-
id:
|
|
19
|
+
id: '0hd8hf8',
|
|
20
20
|
filename: 'purchase-receipt-0.pdf',
|
|
21
21
|
url: 'https://wise.com/public-resources/assets/logos/wise/brand_logo_inverse.svg',
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
|
-
id:
|
|
24
|
+
id: '1r7hgc83',
|
|
25
25
|
filename: 'purchase-receipt-1.pdf',
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
|
-
id:
|
|
28
|
+
id: '2nhc7387hc8h',
|
|
29
29
|
filename: 'purchase-receipt-2.pdf',
|
|
30
30
|
url: 'https://wise.com/public-resources/assets/logos/wise/brand_logo_inverse.svg',
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
|
-
id:
|
|
33
|
+
id: '39wd8uc',
|
|
34
34
|
filename: 'receipt failed.png',
|
|
35
35
|
status: Status.FAILED,
|
|
36
36
|
},
|
|
37
37
|
{
|
|
38
|
-
id:
|
|
38
|
+
id: '437yyf8hf',
|
|
39
39
|
filename: 'receipt failed With error string.png',
|
|
40
40
|
status: Status.FAILED,
|
|
41
41
|
error: 'Something went wrong',
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
|
-
id:
|
|
44
|
+
id: '5biehveifh',
|
|
45
45
|
filename: 'receipt failed With error object.png',
|
|
46
46
|
status: Status.FAILED,
|
|
47
47
|
error: { message: 'Something went wrong' },
|
|
48
48
|
},
|
|
49
|
-
]
|
|
49
|
+
];
|
|
50
50
|
|
|
51
51
|
const createDelayedPromise = async ({
|
|
52
52
|
successful = true,
|
|
@@ -65,163 +65,230 @@ const createDelayedPromise = async ({
|
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
const props = {
|
|
68
|
-
onUploadFile: async (formData: FormData) =>
|
|
69
|
-
|
|
68
|
+
onUploadFile: async (formData: FormData) => createDelayedPromise(),
|
|
69
|
+
onDeleteFile: async (id: string | number) => createDelayedPromise(),
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const UploadInputWithDescriptionFromProps: Story = {
|
|
73
|
+
args: {
|
|
74
|
+
...props,
|
|
75
|
+
multiple: true,
|
|
76
|
+
description: 'Custom file description from prop',
|
|
70
77
|
},
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const Disabled: Story = {
|
|
81
|
+
args: {
|
|
82
|
+
...props,
|
|
83
|
+
disabled: true,
|
|
73
84
|
},
|
|
74
85
|
};
|
|
75
86
|
|
|
76
|
-
const
|
|
87
|
+
export const WithAnyFileType: Story = {
|
|
88
|
+
args: {
|
|
89
|
+
...props,
|
|
90
|
+
fileTypes: '*',
|
|
91
|
+
},
|
|
92
|
+
};
|
|
77
93
|
|
|
78
|
-
export const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
94
|
+
export const WithSingleFileType: Story = {
|
|
95
|
+
args: {
|
|
96
|
+
...props,
|
|
97
|
+
fileTypes: '.zip,application/zip',
|
|
98
|
+
},
|
|
83
99
|
};
|
|
84
100
|
|
|
85
|
-
export const
|
|
86
|
-
|
|
101
|
+
export const WithMultipleExistingFiles: Story = {
|
|
102
|
+
args: {
|
|
103
|
+
...props,
|
|
104
|
+
files,
|
|
105
|
+
multiple: true,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
87
108
|
|
|
88
|
-
export const
|
|
89
|
-
|
|
109
|
+
export const WithFileErrors: Story = {
|
|
110
|
+
args: {
|
|
111
|
+
...props,
|
|
112
|
+
files: [
|
|
113
|
+
{ id: 1, filename: 'Error with default message.png', status: Status.FAILED },
|
|
114
|
+
{
|
|
115
|
+
id: 2,
|
|
116
|
+
filename: 'Error with `string` error.png',
|
|
117
|
+
status: Status.FAILED,
|
|
118
|
+
error: 'Single string error',
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
id: 3,
|
|
122
|
+
filename: 'Error with `obj` error ({ message : `string` }).png',
|
|
123
|
+
status: Status.FAILED,
|
|
124
|
+
error: { message: 'Single obj error' },
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
id: 4,
|
|
128
|
+
filename: 'Error with single error passed in `array`.png',
|
|
129
|
+
status: Status.FAILED,
|
|
130
|
+
errors: ['Single error in array'],
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
id: 5,
|
|
134
|
+
filename: 'Error with multiple `string` errors passed in `array`.png',
|
|
135
|
+
status: Status.FAILED,
|
|
136
|
+
errors: [
|
|
137
|
+
'Error 1',
|
|
138
|
+
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
|
|
139
|
+
'Error 3',
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
id: 6,
|
|
144
|
+
filename: 'Error with multiple `obj` errors passed in `array`.png',
|
|
145
|
+
status: Status.FAILED,
|
|
146
|
+
errors: [
|
|
147
|
+
{ message: 'Error 1' },
|
|
148
|
+
{
|
|
149
|
+
message:
|
|
150
|
+
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
|
|
151
|
+
},
|
|
152
|
+
{ message: 'Error 3' },
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
multiple: true,
|
|
157
|
+
},
|
|
158
|
+
};
|
|
90
159
|
|
|
91
|
-
export const
|
|
92
|
-
|
|
160
|
+
export const WithoutDelete: Story = {
|
|
161
|
+
args: {
|
|
162
|
+
...props,
|
|
163
|
+
files,
|
|
164
|
+
onDeleteFile: undefined,
|
|
165
|
+
multiple: true,
|
|
166
|
+
},
|
|
167
|
+
};
|
|
93
168
|
|
|
94
|
-
export const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
169
|
+
export const WithUploadFailed: Story = {
|
|
170
|
+
args: {
|
|
171
|
+
...props,
|
|
172
|
+
files: files.slice(0),
|
|
173
|
+
onUploadFile: async () => createDelayedPromise({ successful: false }),
|
|
174
|
+
multiple: true,
|
|
175
|
+
},
|
|
99
176
|
};
|
|
100
177
|
|
|
101
|
-
export const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
{
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
status: Status.FAILED,
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
id: 2,
|
|
112
|
-
filename: 'Error with `string` error.png',
|
|
113
|
-
status: Status.FAILED,
|
|
114
|
-
error: 'Single string error',
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
id: 3,
|
|
118
|
-
filename: 'Error with `obj` error ({ message : `string` }).png',
|
|
119
|
-
status: Status.FAILED,
|
|
120
|
-
error: { message: 'Single obj error' },
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
id: 4,
|
|
124
|
-
filename: 'Error with single error passed in `array`.png',
|
|
125
|
-
status: Status.FAILED,
|
|
126
|
-
errors: ['Single error in array'],
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
id: 5,
|
|
130
|
-
filename: 'Error with multiple `string` errors passed in `array`.png',
|
|
131
|
-
status: Status.FAILED,
|
|
132
|
-
errors: [
|
|
133
|
-
'Error 1',
|
|
134
|
-
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
|
|
135
|
-
'Error 3',
|
|
136
|
-
],
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
id: 6,
|
|
140
|
-
filename: 'Error with multiple `obj` errors passed in `array`.png',
|
|
141
|
-
status: Status.FAILED,
|
|
142
|
-
errors: [
|
|
143
|
-
{ message: 'Error 1' },
|
|
144
|
-
{
|
|
145
|
-
message:
|
|
146
|
-
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
|
|
147
|
-
},
|
|
148
|
-
{ message: 'Error 3' },
|
|
149
|
-
],
|
|
150
|
-
},
|
|
151
|
-
],
|
|
152
|
-
multiple: true,
|
|
178
|
+
export const WithDeleteFailed: Story = {
|
|
179
|
+
args: {
|
|
180
|
+
...props,
|
|
181
|
+
files: files.slice(0),
|
|
182
|
+
onDeleteFile: async () => createDelayedPromise({ successful: false }),
|
|
183
|
+
multiple: true,
|
|
184
|
+
},
|
|
153
185
|
};
|
|
154
186
|
|
|
155
|
-
export const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
187
|
+
export const CustomConfirmMessage: Story = {
|
|
188
|
+
args: {
|
|
189
|
+
...props,
|
|
190
|
+
files: files.slice(0),
|
|
191
|
+
deleteConfirm: {
|
|
192
|
+
title: 'Sure you want to remove this invoice?',
|
|
193
|
+
body: (
|
|
194
|
+
<img
|
|
195
|
+
alt="brand logo"
|
|
196
|
+
src="https://wise.com/public-resources/assets/logos/wise/brand_logo.svg"
|
|
197
|
+
/>
|
|
198
|
+
),
|
|
199
|
+
},
|
|
200
|
+
},
|
|
161
201
|
};
|
|
162
202
|
|
|
163
|
-
export const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
203
|
+
export const WithManualDownloadHandler: Story = {
|
|
204
|
+
args: {
|
|
205
|
+
...props,
|
|
206
|
+
files,
|
|
207
|
+
onDownload: action('Manual download handler'),
|
|
208
|
+
},
|
|
169
209
|
};
|
|
170
210
|
|
|
171
|
-
export const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
211
|
+
export const WithFilesChangeHandler: Story = {
|
|
212
|
+
args: {
|
|
213
|
+
...props,
|
|
214
|
+
files,
|
|
215
|
+
onFilesChange: action('Files change handler'),
|
|
216
|
+
},
|
|
177
217
|
};
|
|
178
218
|
|
|
179
|
-
export const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
body: (
|
|
186
|
-
<img
|
|
187
|
-
alt="brand logo"
|
|
188
|
-
src="https://wise.com/public-resources/assets/logos/wise/brand_logo.svg"
|
|
189
|
-
/>
|
|
190
|
-
),
|
|
219
|
+
export const WithMaxFilesToUploadLimit: Story = {
|
|
220
|
+
args: {
|
|
221
|
+
...props,
|
|
222
|
+
multiple: true,
|
|
223
|
+
maxFiles: 5,
|
|
224
|
+
maxFilesErrorMessage: "Can't upload as maximum number of files allowed are already uploaded",
|
|
191
225
|
},
|
|
192
226
|
};
|
|
193
227
|
|
|
194
|
-
export const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
228
|
+
export const WithFileSizeErrorMessage: Story = {
|
|
229
|
+
args: {
|
|
230
|
+
...props,
|
|
231
|
+
sizeLimit: 1,
|
|
232
|
+
sizeLimitErrorMessage: 'The file is oversized',
|
|
233
|
+
},
|
|
199
234
|
};
|
|
200
235
|
|
|
201
|
-
export const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
236
|
+
export const WithCustomUploadButtonTitle: Story = {
|
|
237
|
+
args: {
|
|
238
|
+
...props,
|
|
239
|
+
uploadButtonTitle: 'Upload the VAT receipts for FY 2022-23',
|
|
240
|
+
},
|
|
206
241
|
};
|
|
207
242
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
243
|
+
const triggerModalAndConfirm = async ({ isLink = true } = {}) => {
|
|
244
|
+
if (isLink) {
|
|
245
|
+
await wait();
|
|
246
|
+
await userEvent.tab();
|
|
247
|
+
}
|
|
248
|
+
await wait();
|
|
249
|
+
await userEvent.keyboard('{Enter}');
|
|
250
|
+
await wait();
|
|
251
|
+
await userEvent.tab();
|
|
252
|
+
await wait();
|
|
253
|
+
await userEvent.tab();
|
|
254
|
+
await wait();
|
|
255
|
+
await userEvent.tab();
|
|
256
|
+
await wait();
|
|
257
|
+
await userEvent.keyboard('{Enter}');
|
|
258
|
+
await wait();
|
|
214
259
|
};
|
|
260
|
+
const wait = async (time = 250) =>
|
|
261
|
+
new Promise((resolve) => {
|
|
262
|
+
setTimeout(resolve, time);
|
|
263
|
+
});
|
|
215
264
|
|
|
216
|
-
export const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
265
|
+
export const DeletingTop: Story = {
|
|
266
|
+
args: {
|
|
267
|
+
...props,
|
|
268
|
+
files: [files[0], files[1], files[2]],
|
|
269
|
+
multiple: true,
|
|
270
|
+
},
|
|
271
|
+
play: async ({ canvasElement }) => {
|
|
272
|
+
await userEvent.tab();
|
|
273
|
+
await triggerModalAndConfirm();
|
|
274
|
+
await triggerModalAndConfirm({ isLink: false });
|
|
275
|
+
await triggerModalAndConfirm();
|
|
276
|
+
},
|
|
221
277
|
};
|
|
222
278
|
|
|
223
|
-
export const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
279
|
+
export const DeletingBottom: Story = {
|
|
280
|
+
args: {
|
|
281
|
+
...props,
|
|
282
|
+
files: [files[0], files[1], files[2]],
|
|
283
|
+
multiple: true,
|
|
284
|
+
},
|
|
285
|
+
play: async ({ canvasElement }) => {
|
|
286
|
+
await userEvent.tab();
|
|
287
|
+
await userEvent.tab();
|
|
288
|
+
await userEvent.tab();
|
|
289
|
+
await userEvent.tab();
|
|
290
|
+
await triggerModalAndConfirm();
|
|
291
|
+
await triggerModalAndConfirm({ isLink: false });
|
|
292
|
+
await triggerModalAndConfirm();
|
|
293
|
+
},
|
|
227
294
|
};
|