@transferwise/components 0.0.0-experimental-4fd9ff3 → 0.0.0-experimental-2015f7e

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transferwise/components",
3
- "version": "0.0.0-experimental-4fd9ff3",
3
+ "version": "0.0.0-experimental-2015f7e",
4
4
  "description": "Neptune React components",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -95,9 +95,9 @@
95
95
  "rollup-preserve-directives": "^1.1.1",
96
96
  "storybook": "^8.2.2",
97
97
  "@transferwise/less-config": "3.1.1",
98
- "@wise/wds-configs": "0.0.0",
99
98
  "@transferwise/neptune-css": "14.24.4",
100
- "@wise/components-theming": "1.6.2"
99
+ "@wise/components-theming": "1.6.2",
100
+ "@wise/wds-configs": "0.0.0"
101
101
  },
102
102
  "peerDependencies": {
103
103
  "@transferwise/icons": "^3.21.0",
@@ -76,6 +76,11 @@ describe('Upload Component', () => {
76
76
  dispatchEvent: jest.fn(),
77
77
  })),
78
78
  });
79
+ props.onStart.mockReset();
80
+ props.onSuccess.mockReset();
81
+ props.onFailure.mockReset();
82
+ props.onCancel.mockReset();
83
+ props.onChange.mockReset();
79
84
  });
80
85
 
81
86
  afterEach(async () => {
@@ -292,4 +297,66 @@ describe('Upload Component', () => {
292
297
  const errorIcon = await screen.findByLabelText(/Custom error label/i);
293
298
  expect(errorIcon).toBeInTheDocument();
294
299
  });
300
+
301
+ test('should respect the animationDelay prop', async () => {
302
+ const shortDelay = 50;
303
+ const longDelay = 500;
304
+
305
+ (asyncFileRead as jest.Mock).mockResolvedValue('mockBase64Image');
306
+ (postData as jest.Mock).mockResolvedValue('mockSuccessResponse');
307
+
308
+ const { container, unmount } = render(<Upload {...props} animationDelay={shortDelay} />);
309
+
310
+ await act(async () => {
311
+ const droppableElement = await waitFor(() => container.querySelector('.droppable-area'));
312
+ const dataTransfer = new DataTransfer();
313
+ dataTransfer.items.add(TEST_FILE);
314
+ fireEvent.drop(droppableElement!, { dataTransfer });
315
+ });
316
+
317
+ await act(async () => {
318
+ jest.advanceTimersByTime(shortDelay + 10);
319
+ });
320
+
321
+ expect(container.querySelector('.droppable-complete')).toBeInTheDocument();
322
+ unmount();
323
+
324
+ const { container: container2 } = render(<Upload {...props} animationDelay={longDelay} />);
325
+
326
+ await act(async () => {
327
+ const droppableElement = await waitFor(() => container2.querySelector('.droppable-area'));
328
+ const dataTransfer = new DataTransfer();
329
+ dataTransfer.items.add(TEST_FILE);
330
+ fireEvent.drop(droppableElement!, { dataTransfer });
331
+ });
332
+
333
+ await act(async () => {
334
+ jest.advanceTimersByTime(longDelay / 2);
335
+ });
336
+
337
+ expect(container2.querySelector('.droppable-processing')).toBeInTheDocument();
338
+ expect(container2.querySelector('.droppable-complete')).not.toBeInTheDocument();
339
+
340
+ await act(async () => {
341
+ jest.advanceTimersByTime(longDelay / 2 + 10);
342
+ });
343
+
344
+ expect(container2.querySelector('.droppable-complete')).toBeInTheDocument();
345
+ expect(container2.querySelector('.droppable-processing')).not.toBeInTheDocument();
346
+ });
347
+
348
+ test('should handle disabled state correctly', async () => {
349
+ const { container } = render(<Upload {...props} usDisabled />);
350
+ const droppableElement = await waitFor(() => container.querySelector('.droppable-area'));
351
+
352
+ const dataTransfer = new DataTransfer();
353
+ dataTransfer.items.add(TEST_FILE);
354
+
355
+ await act(async () => {
356
+ fireEvent.drop(droppableElement!, { dataTransfer });
357
+ });
358
+
359
+ expect(container.querySelector('.droppable-processing')).not.toBeInTheDocument();
360
+ expect(props.onStart).not.toHaveBeenCalled();
361
+ });
295
362
  });
@@ -38,54 +38,3 @@ export const Basic = {
38
38
  onCancel: fn(),
39
39
  },
40
40
  } satisfies Story;
41
-
42
- export const MaxSizes = () => {
43
- const bKB = 1024;
44
- const bMB = 1024 * bKB;
45
-
46
- const dKB = 1000;
47
- const dMB = 1000 * dKB;
48
-
49
- const binarySizes = [
50
- 10 * bMB,
51
- 5 * bMB,
52
- 1 * bMB,
53
- 500 * bKB,
54
- 100 * bKB,
55
- 50 * bKB,
56
- 10 * bKB,
57
- 5 * bKB,
58
- 1 * bKB,
59
- ];
60
-
61
- const decimalSizes = [
62
- 10 * dMB,
63
- 5 * dMB,
64
- 1 * dMB,
65
- 500 * dKB,
66
- 100 * dKB,
67
- 50 * dKB,
68
- 10 * dKB,
69
- 5 * dKB,
70
- 1 * dKB,
71
- ];
72
-
73
- return (
74
- <div style={{ display: 'flex', gap: '1rem' }}>
75
- <div style={{ flex: 1 }}>
76
- {binarySizes.map((maxSize) => (
77
- <Field key={maxSize} label={`Max size: ${maxSize} bytes`}>
78
- <Upload usLabel="Pick a file, any file" maxSize={maxSize} />
79
- </Field>
80
- ))}
81
- </div>
82
- <div style={{ flex: 1 }}>
83
- {decimalSizes.map((maxSize) => (
84
- <Field key={maxSize} label={`Max size: ${maxSize} bytes`}>
85
- <Upload usLabel="Pick a file, any file" maxSize={maxSize} />
86
- </Field>
87
- ))}
88
- </div>
89
- </div>
90
- );
91
- };
@@ -0,0 +1,93 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { fn } from '@storybook/test';
3
+
4
+ import Upload from '.';
5
+ import { MAX_SIZE_DEFAULT } from './Upload';
6
+ import { Field } from '../field/Field';
7
+
8
+ const meta = {
9
+ component: Upload,
10
+ title: 'Forms/Upload/Tests',
11
+ argTypes: {
12
+ maxSize: {
13
+ control: {
14
+ type: 'number',
15
+ min: 0,
16
+ },
17
+ },
18
+ },
19
+ } satisfies Meta<typeof Upload>;
20
+
21
+ export default meta;
22
+
23
+ export const MaxSizes = () => {
24
+ const bKB = 1024;
25
+ const bMB = 1024 * bKB;
26
+
27
+ const dKB = 1000;
28
+ const dMB = 1000 * dKB;
29
+
30
+ const binarySizes = [
31
+ 10 * bMB,
32
+ 5 * bMB,
33
+ 1 * bMB,
34
+ 500 * bKB,
35
+ 100 * bKB,
36
+ 50 * bKB,
37
+ 10 * bKB,
38
+ 5 * bKB,
39
+ 1 * bKB,
40
+ ];
41
+
42
+ const decimalSizes = [
43
+ 10 * dMB,
44
+ 5 * dMB,
45
+ 1 * dMB,
46
+ 500 * dKB,
47
+ 100 * dKB,
48
+ 50 * dKB,
49
+ 10 * dKB,
50
+ 5 * dKB,
51
+ 1 * dKB,
52
+ ];
53
+
54
+ return (
55
+ <div style={{ display: 'flex', gap: '1rem' }}>
56
+ <div style={{ flex: 1 }}>
57
+ {binarySizes.map((maxSize) => (
58
+ <Field key={maxSize} label={`Max size: ${maxSize} bytes`}>
59
+ <Upload usLabel="Pick a file, any file" maxSize={maxSize} />
60
+ </Field>
61
+ ))}
62
+ </div>
63
+ <div style={{ flex: 1 }}>
64
+ {decimalSizes.map((maxSize) => (
65
+ <Field key={maxSize} label={`Max size: ${maxSize} bytes`}>
66
+ <Upload usLabel="Pick a file, any file" maxSize={maxSize} />
67
+ </Field>
68
+ ))}
69
+ </div>
70
+ </div>
71
+ );
72
+ };
73
+
74
+ export const AllVariants = () => {
75
+ return (
76
+ <div style={{ display: 'flex', gap: '1rem' }}>
77
+ <div style={{ flex: 1 }}>
78
+ <Field key="small" label="Small Upload">
79
+ <Upload usLabel="Pick a file, any file" size="sm" />
80
+ </Field>
81
+ <Field key="medium" label="Medium Upload">
82
+ <Upload usLabel="Pick a file, any file" size="md" />
83
+ </Field>
84
+ <Field key="large" label="Large Upload">
85
+ <Upload usLabel="Pick a file, any file" size="lg" />
86
+ </Field>
87
+ <Field key="disabled" label="Disabled Upload">
88
+ <Upload usLabel="Pick a file, any file" usDisabled />
89
+ </Field>
90
+ </div>
91
+ </div>
92
+ );
93
+ };