@transferwise/components 46.94.1 → 46.94.2
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/dateLookup/dateHeader/DateHeader.js +27 -22
- package/build/dateLookup/dateHeader/DateHeader.js.map +1 -1
- package/build/dateLookup/dateHeader/DateHeader.mjs +27 -22
- package/build/dateLookup/dateHeader/DateHeader.mjs.map +1 -1
- package/build/i18n/nl.json +73 -0
- package/build/main.css +2 -7
- package/build/styles/button/Button.css +2 -2
- package/build/styles/dateLookup/DateLookup.css +0 -5
- package/build/styles/main.css +2 -7
- package/build/types/dateLookup/dateHeader/DateHeader.d.ts.map +1 -1
- package/build/types/upload/Upload.d.ts.map +1 -1
- package/build/upload/Upload.js +3 -1
- package/build/upload/Upload.js.map +1 -1
- package/build/upload/Upload.mjs +3 -1
- package/build/upload/Upload.mjs.map +1 -1
- package/package.json +4 -4
- package/src/button/Button.css +2 -2
- package/src/button/Button.less +2 -2
- package/src/dateLookup/DateLookup.css +0 -5
- package/src/dateLookup/DateLookup.less +0 -4
- package/src/dateLookup/dateHeader/DateHeader.tsx +24 -26
- package/src/i18n/nl.json +73 -0
- package/src/main.css +2 -7
- package/src/upload/Upload.spec.tsx +293 -0
- package/src/upload/Upload.tsx +5 -1
- package/src/upload/steps/completeStep/completeStep.spec.tsx +51 -0
- package/src/upload/steps/processingStep/processingStep.spec.tsx +59 -0
- package/src/upload/steps/uploadImageStep/uploadImageStep.spec.tsx +79 -0
- package/src/upload/Upload.events.spec.js +0 -49
- package/src/upload/Upload.spec.js +0 -305
- package/src/upload/steps/completeStep/completeStep.spec.js +0 -51
- package/src/upload/steps/processingStep/processingStep.spec.js +0 -55
- package/src/upload/steps/uploadImageStep/uploadImageStep.spec.js +0 -91
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
import { shallow, mount } from 'enzyme';
|
|
2
|
-
import { act } from 'react';
|
|
3
|
-
import { mockMatchMedia } from '../test-utils';
|
|
4
|
-
|
|
5
|
-
import { ANIMATION_DURATION_IN_MS } from '../processIndicator';
|
|
6
|
-
|
|
7
|
-
import { CompleteStep, UploadImageStep, ProcessingStep } from './steps';
|
|
8
|
-
|
|
9
|
-
import Upload from '.';
|
|
10
|
-
import { Cross } from '@transferwise/icons';
|
|
11
|
-
|
|
12
|
-
mockMatchMedia();
|
|
13
|
-
|
|
14
|
-
jest.mock('./utils/postData', () => ({
|
|
15
|
-
postData: async () => 'ServerResponse',
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
jest.mock('./utils/asyncFileRead');
|
|
19
|
-
const { asyncFileRead } = require('./utils/asyncFileRead');
|
|
20
|
-
|
|
21
|
-
const defaultLocale = 'en-GB';
|
|
22
|
-
const formatMessage = (id) => String(id);
|
|
23
|
-
jest.mock('react-intl', () => ({
|
|
24
|
-
injectIntl: (Component) =>
|
|
25
|
-
function (props) {
|
|
26
|
-
return (
|
|
27
|
-
<Component {...props} intl={{ locale: defaultLocale, formatMessage: (id) => String(id) }} />
|
|
28
|
-
);
|
|
29
|
-
},
|
|
30
|
-
useIntl: () => ({ formatMessage }),
|
|
31
|
-
defineMessages: (translations) => translations,
|
|
32
|
-
}));
|
|
33
|
-
|
|
34
|
-
const TEST_FILE = new File(['(⌐□_□)'], 'chucknorris.png', { type: 'image/png' });
|
|
35
|
-
const ANIMATION_DELAY = ANIMATION_DURATION_IN_MS * 2;
|
|
36
|
-
|
|
37
|
-
const props = {
|
|
38
|
-
animationDelay: 1000,
|
|
39
|
-
csButtonText: 'csButtonText',
|
|
40
|
-
csFailureText: 'csFailureText',
|
|
41
|
-
csSuccessText: 'csSuccessText',
|
|
42
|
-
csTooLargeMessage: 'csTooLargeMessage',
|
|
43
|
-
maxSize: 5000000,
|
|
44
|
-
onCancel: jest.fn(),
|
|
45
|
-
onChange: jest.fn(),
|
|
46
|
-
onFailure: jest.fn(),
|
|
47
|
-
onStart: jest.fn(),
|
|
48
|
-
onSuccess: jest.fn(),
|
|
49
|
-
psButtonText: 'psButtonText',
|
|
50
|
-
psProcessingText: 'psProcessingText',
|
|
51
|
-
usAccept: 'image/*',
|
|
52
|
-
usButtonText: 'Or Select File',
|
|
53
|
-
usButtonRetryText: 'Try again',
|
|
54
|
-
usDropMessage: 'Drop file to start upload',
|
|
55
|
-
usPlaceholder: 'Drag and drop a file less than 5MB',
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const UPLOADIMAGE_STEP_PROPS = {
|
|
59
|
-
fileDropped: expect.any(Function),
|
|
60
|
-
isComplete: false,
|
|
61
|
-
usAccept: props.usAccept,
|
|
62
|
-
usButtonText: props.usButtonText,
|
|
63
|
-
usDisabled: false,
|
|
64
|
-
usHelpImage: undefined,
|
|
65
|
-
usLabel: '',
|
|
66
|
-
usPlaceholder: props.usPlaceholder,
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const PROCESSING_STEP_PROPS = {
|
|
70
|
-
isComplete: false,
|
|
71
|
-
isError: false,
|
|
72
|
-
isSuccess: false,
|
|
73
|
-
onAnimationCompleted: expect.any(Function),
|
|
74
|
-
onClear: expect.any(Function),
|
|
75
|
-
psButtonText: props.psButtonText,
|
|
76
|
-
psProcessingText: props.psProcessingText,
|
|
77
|
-
psButtonDisabled: false,
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const COMPLETED_STEP_PROPS = {
|
|
81
|
-
csButtonText: props.csButtonText,
|
|
82
|
-
csFailureText: props.csFailureText,
|
|
83
|
-
csSuccessText: props.csSuccessText,
|
|
84
|
-
fileName: TEST_FILE.name,
|
|
85
|
-
isComplete: true,
|
|
86
|
-
isError: false,
|
|
87
|
-
isImage: true,
|
|
88
|
-
onClear: expect.any(Function),
|
|
89
|
-
uploadedImage: 'data:image/png;base64,KOKMkOKWoV/ilqEp',
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
describe('Upload', () => {
|
|
93
|
-
let component;
|
|
94
|
-
beforeEach(() => {
|
|
95
|
-
jest.useFakeTimers();
|
|
96
|
-
component = shallow(<Upload {...props} />).dive();
|
|
97
|
-
asyncFileRead.mockImplementation(async () => 'a value');
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
afterEach(async () => {
|
|
101
|
-
await jest.runOnlyPendingTimersAsync();
|
|
102
|
-
jest.useRealTimers();
|
|
103
|
-
jest.clearAllMocks();
|
|
104
|
-
jest.clearAllTimers();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('renders container', () => {
|
|
108
|
-
expect(component.find('.droppable-md')).toHaveLength(1);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('renders the UploadImageStep by default', () => {
|
|
112
|
-
expect(component.find(UploadImageStep)).toHaveLength(1);
|
|
113
|
-
expect(component.find(ProcessingStep)).toHaveLength(0);
|
|
114
|
-
expect(component.find(CompleteStep)).toHaveLength(0);
|
|
115
|
-
expect(component.find('.droppable-dropping-card')).toHaveLength(1);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('renders the ProcessingStep when state is processing', () => {
|
|
119
|
-
component.setState({ isProcessing: true });
|
|
120
|
-
|
|
121
|
-
expect(component.find(UploadImageStep)).toHaveLength(0);
|
|
122
|
-
expect(component.find(ProcessingStep)).toHaveLength(1);
|
|
123
|
-
expect(component.find(CompleteStep)).toHaveLength(0);
|
|
124
|
-
expect(component.find('.droppable-dropping-card')).toHaveLength(0);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('renders the CompleteStep when state is completed', () => {
|
|
128
|
-
component.setState({ isComplete: true });
|
|
129
|
-
|
|
130
|
-
expect(component.find(UploadImageStep)).toHaveLength(0);
|
|
131
|
-
expect(component.find(ProcessingStep)).toHaveLength(0);
|
|
132
|
-
expect(component.find(CompleteStep)).toHaveLength(1);
|
|
133
|
-
expect(component.find('.droppable-dropping-card')).toHaveLength(1);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
describe('before file is dropped', () => {
|
|
137
|
-
it('renders the UploadImageStep with right props', () => {
|
|
138
|
-
expect(component.find(UploadImageStep).props()).toStrictEqual(UPLOADIMAGE_STEP_PROPS);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
describe('when file is dropped', () => {
|
|
143
|
-
it('onStart is called with file', async () => {
|
|
144
|
-
await component.instance().fileDropped(TEST_FILE);
|
|
145
|
-
|
|
146
|
-
expect(props.onStart).toHaveBeenCalledWith(TEST_FILE);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('step changes from UploadImageStep to ProcessingStep', async () => {
|
|
150
|
-
expect(component.find(UploadImageStep)).toHaveLength(1);
|
|
151
|
-
expect(component.find(ProcessingStep)).toHaveLength(0);
|
|
152
|
-
expect(component.find(CompleteStep)).toHaveLength(0);
|
|
153
|
-
|
|
154
|
-
await component.instance().fileDropped(TEST_FILE);
|
|
155
|
-
component.update();
|
|
156
|
-
|
|
157
|
-
expect(component.find(UploadImageStep)).toHaveLength(0);
|
|
158
|
-
expect(component.find(ProcessingStep)).toHaveLength(1);
|
|
159
|
-
expect(component.find(CompleteStep)).toHaveLength(0);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('step changes from UploadImageStep to ProcessingStep with right props', async () => {
|
|
163
|
-
await component.instance().fileDropped(TEST_FILE);
|
|
164
|
-
component.update();
|
|
165
|
-
|
|
166
|
-
expect(component.find(ProcessingStep).props()).toStrictEqual(PROCESSING_STEP_PROPS);
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
describe('when file is being processed', () => {
|
|
171
|
-
it('step ProcessingStep is called with success props', async () => {
|
|
172
|
-
await component.instance().fileDropped(TEST_FILE);
|
|
173
|
-
jest.advanceTimersByTime(props.animationDelay);
|
|
174
|
-
component.update();
|
|
175
|
-
|
|
176
|
-
expect(component.find(ProcessingStep).props()).toStrictEqual({
|
|
177
|
-
...PROCESSING_STEP_PROPS,
|
|
178
|
-
isSuccess: true,
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('step ProcessingStep is called with error props', async () => {
|
|
183
|
-
asyncFileRead.mockImplementation(async () => {
|
|
184
|
-
throw 'An error';
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
await component.instance().fileDropped(TEST_FILE);
|
|
188
|
-
jest.advanceTimersByTime(props.animationDelay);
|
|
189
|
-
component.update();
|
|
190
|
-
|
|
191
|
-
expect(component.find(ProcessingStep).props()).toStrictEqual({
|
|
192
|
-
...PROCESSING_STEP_PROPS,
|
|
193
|
-
isError: true,
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('should disable processing button when psButtonDisabled is true', async () => {
|
|
198
|
-
component.setProps({ psButtonDisabled: true });
|
|
199
|
-
await component.instance().fileDropped(TEST_FILE);
|
|
200
|
-
jest.advanceTimersByTime(props.animationDelay);
|
|
201
|
-
component.update();
|
|
202
|
-
|
|
203
|
-
expect(component.find(ProcessingStep).props()).toStrictEqual({
|
|
204
|
-
...PROCESSING_STEP_PROPS,
|
|
205
|
-
psButtonDisabled: true,
|
|
206
|
-
isError: false,
|
|
207
|
-
isSuccess: true,
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
describe('when file is processed', () => {
|
|
213
|
-
const waitForUpload = async () => {
|
|
214
|
-
for (let i = 0; i < 4; i += 1) {
|
|
215
|
-
await act(async () => {
|
|
216
|
-
await jest.runOnlyPendingTimersAsync();
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
it('step changes from UploadImageStep to CompleteStep', async () => {
|
|
222
|
-
component = mount(<Upload {...props} />);
|
|
223
|
-
const upload = component.children();
|
|
224
|
-
expect(upload.find(UploadImageStep)).toHaveLength(1);
|
|
225
|
-
expect(upload.find(ProcessingStep)).toHaveLength(0);
|
|
226
|
-
expect(upload.find(CompleteStep)).toHaveLength(0);
|
|
227
|
-
|
|
228
|
-
await act(async () => {
|
|
229
|
-
await upload.instance().fileDropped(TEST_FILE);
|
|
230
|
-
});
|
|
231
|
-
await waitForUpload();
|
|
232
|
-
component.update();
|
|
233
|
-
|
|
234
|
-
expect(component.find(UploadImageStep)).toHaveLength(0);
|
|
235
|
-
expect(component.find(ProcessingStep)).toHaveLength(0);
|
|
236
|
-
expect(component.find(CompleteStep)).toHaveLength(1);
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it('step UploadImageStep is called with error props', async () => {
|
|
240
|
-
component = mount(<Upload {...props} />);
|
|
241
|
-
const upload = component.children();
|
|
242
|
-
asyncFileRead.mockImplementation(async () => {
|
|
243
|
-
throw 'An error';
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
await act(async () => {
|
|
247
|
-
await upload.instance().fileDropped(TEST_FILE);
|
|
248
|
-
});
|
|
249
|
-
await waitForUpload();
|
|
250
|
-
component.update();
|
|
251
|
-
|
|
252
|
-
expect(component.find(UploadImageStep).props()).toStrictEqual({
|
|
253
|
-
...UPLOADIMAGE_STEP_PROPS,
|
|
254
|
-
isComplete: false,
|
|
255
|
-
errorMessage: 'csFailureText',
|
|
256
|
-
errorIconLabel: undefined,
|
|
257
|
-
usButtonText: 'Try again',
|
|
258
|
-
usHelpImage: null,
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
it('onSuccess is called with response when httpOptions are provided', async () => {
|
|
263
|
-
component = mount(<Upload {...props} httpOptions={{ url: 'a-url' }} />).children();
|
|
264
|
-
|
|
265
|
-
await act(async () => {
|
|
266
|
-
await component.instance().fileDropped(TEST_FILE);
|
|
267
|
-
});
|
|
268
|
-
await waitForUpload();
|
|
269
|
-
|
|
270
|
-
expect(props.onSuccess).toHaveBeenCalledWith('ServerResponse', TEST_FILE.name);
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
it('wont process new file while current process is in progress', async () => {
|
|
274
|
-
component = mount(<Upload {...props} httpOptions={{ url: 'a-url' }} />).children();
|
|
275
|
-
|
|
276
|
-
await act(async () => {
|
|
277
|
-
await component.instance().fileDropped(TEST_FILE);
|
|
278
|
-
});
|
|
279
|
-
const result = await act(async () => component.instance().fileDropped(TEST_FILE));
|
|
280
|
-
|
|
281
|
-
expect(result).toBe(false);
|
|
282
|
-
|
|
283
|
-
await waitForUpload();
|
|
284
|
-
|
|
285
|
-
expect(props.onSuccess).toHaveBeenCalledTimes(1);
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
it('should respect `errorIconLabel` override', async () => {
|
|
289
|
-
const errorIconLabel = 'Custom error icon label';
|
|
290
|
-
component = mount(<Upload {...props} errorIconLabel={errorIconLabel} />);
|
|
291
|
-
const upload = component.children();
|
|
292
|
-
asyncFileRead.mockImplementation(async () => {
|
|
293
|
-
throw 'An error';
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
await act(async () => {
|
|
297
|
-
await upload.instance().fileDropped(TEST_FILE);
|
|
298
|
-
});
|
|
299
|
-
await waitForUpload();
|
|
300
|
-
component.update();
|
|
301
|
-
|
|
302
|
-
expect(component.find(Cross).at(1).prop('title')).toBe(errorIconLabel);
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Document as DocumentIcon } from '@transferwise/icons';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
|
|
4
|
-
import Body from '../../../body';
|
|
5
|
-
import Button from '../../../button';
|
|
6
|
-
|
|
7
|
-
import CompleteStep from '.';
|
|
8
|
-
|
|
9
|
-
describe('CompleteStep', () => {
|
|
10
|
-
const COMPLETED_STEP_PROPS = {
|
|
11
|
-
isComplete: true,
|
|
12
|
-
uploadedImage: '',
|
|
13
|
-
fileName: 'fileName',
|
|
14
|
-
isError: false,
|
|
15
|
-
isImage: true,
|
|
16
|
-
csSuccessText: 'csSuccessText',
|
|
17
|
-
csFailureText: 'csFailureText',
|
|
18
|
-
csButtonText: 'csButtonText',
|
|
19
|
-
onClear: jest.fn(),
|
|
20
|
-
usLabel: 'usLabel',
|
|
21
|
-
};
|
|
22
|
-
let component;
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
component = shallow(<CompleteStep {...COMPLETED_STEP_PROPS} />);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('renders container', () => {
|
|
28
|
-
expect(component.find('.droppable-complete-card')).toHaveLength(1);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe('when error is false', () => {
|
|
32
|
-
it('renders isImage or Upload icon', () => {
|
|
33
|
-
expect(component.find(DocumentIcon)).toHaveLength(1);
|
|
34
|
-
component.setProps({ uploadedImage: 'uploadedImage' });
|
|
35
|
-
expect(component.find('img.thumbnail')).toHaveLength(1);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('renders filename when error is false', () => {
|
|
39
|
-
expect(component.find(Body).props().children).toBe(COMPLETED_STEP_PROPS.fileName);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('renders button when csButtonText is set up', () => {
|
|
44
|
-
expect(component.find(Button)).toHaveLength(1);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('calls onClear when button is clicked', () => {
|
|
48
|
-
component.find(Button).simulate('click', {});
|
|
49
|
-
expect(COMPLETED_STEP_PROPS.onClear).toHaveBeenCalledTimes(1);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { shallow } from 'enzyme';
|
|
2
|
-
|
|
3
|
-
import Button from '../../../button';
|
|
4
|
-
import ProcessIndicator from '../../../processIndicator';
|
|
5
|
-
import Title from '../../../title/Title';
|
|
6
|
-
|
|
7
|
-
import ProcessingStep from '.';
|
|
8
|
-
|
|
9
|
-
describe('ProcessingStep', () => {
|
|
10
|
-
const PROCESSING_STEP_PROPS = {
|
|
11
|
-
isComplete: false,
|
|
12
|
-
isError: false,
|
|
13
|
-
isSuccess: false,
|
|
14
|
-
onAnimationCompleted: jest.fn(),
|
|
15
|
-
onClear: jest.fn(),
|
|
16
|
-
psButtonText: 'psButtonText',
|
|
17
|
-
psProcessingText: 'psProcessingText',
|
|
18
|
-
};
|
|
19
|
-
let component;
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
component = shallow(<ProcessingStep {...PROCESSING_STEP_PROPS} />);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('renders container', () => {
|
|
25
|
-
expect(component.find('.droppable-processing-card')).toHaveLength(1);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('renders ProcessIndicator with default status', () => {
|
|
29
|
-
expect(component.find(ProcessIndicator)).toHaveLength(1);
|
|
30
|
-
expect(component.find(ProcessIndicator).props().status).toBe('processing');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('renders ProcessIndicator with success status', () => {
|
|
34
|
-
component = shallow(<ProcessingStep {...PROCESSING_STEP_PROPS} isSuccess />);
|
|
35
|
-
expect(component.find(ProcessIndicator).props().status).toBe('succeeded');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('renders ProcessIndicator with error status', () => {
|
|
39
|
-
component = shallow(<ProcessingStep {...PROCESSING_STEP_PROPS} isError />);
|
|
40
|
-
expect(component.find(ProcessIndicator).props().status).toBe('failed');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('renders psProcessingText', () => {
|
|
44
|
-
expect(component.find(Title).props().children).toBe(PROCESSING_STEP_PROPS.psProcessingText);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('renders button when psButtonText is set up', () => {
|
|
48
|
-
expect(component.find(Button)).toHaveLength(1);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('calls onClear when button is clicked', () => {
|
|
52
|
-
component.find(Button).simulate('click', {});
|
|
53
|
-
expect(PROCESSING_STEP_PROPS.onClear).toHaveBeenCalledTimes(1);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { Upload as UploadIcon } from '@transferwise/icons';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
import StatusIcon from '../../../statusIcon/StatusIcon';
|
|
4
|
-
|
|
5
|
-
import UploadImageStep from '.';
|
|
6
|
-
import { InlineAlert } from '../../../index';
|
|
7
|
-
|
|
8
|
-
describe('uploadImageStep', () => {
|
|
9
|
-
const UPLOADIMAGE_STEP_PROPS = {
|
|
10
|
-
fileDropped: jest.fn(),
|
|
11
|
-
isComplete: false,
|
|
12
|
-
usAccept: 'usAccept',
|
|
13
|
-
usButtonText: '',
|
|
14
|
-
usDisabled: false,
|
|
15
|
-
usLabel: '',
|
|
16
|
-
usHelpImage: '',
|
|
17
|
-
usPlaceholder: '',
|
|
18
|
-
errorMessage: '',
|
|
19
|
-
};
|
|
20
|
-
let component;
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
component = shallow(<UploadImageStep {...UPLOADIMAGE_STEP_PROPS} />);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('renders container', () => {
|
|
26
|
-
expect(component.find('.droppable-default-card')).toHaveLength(1);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('renders helpImage or Upload icon', () => {
|
|
30
|
-
expect(component.find(UploadIcon)).toHaveLength(2);
|
|
31
|
-
component.setProps({ usHelpImage: 'usHelpImage' });
|
|
32
|
-
expect(component.find('img.thumbnail')).toHaveLength(1);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('renders label', () => {
|
|
36
|
-
expect(component.find('h4')).toHaveLength(0);
|
|
37
|
-
component.setProps({ usLabel: 'usLabel' });
|
|
38
|
-
expect(component.find('h4').text()).toBe('usLabel');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('renders placeholder', () => {
|
|
42
|
-
expect(component.find('p')).toHaveLength(0);
|
|
43
|
-
component.setProps({ usPlaceholder: 'usPlaceholder' });
|
|
44
|
-
expect(component.find('p').text()).toBe('usPlaceholder');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('renders buttonText or Icon', () => {
|
|
48
|
-
expect(component.find('.btn-primary')).toHaveLength(1);
|
|
49
|
-
expect(component.find(UploadIcon)).toHaveLength(2);
|
|
50
|
-
component.setProps({ usButtonText: 'usButtonText' });
|
|
51
|
-
expect(component.find('.btn-primary span').text()).toBe('usButtonText');
|
|
52
|
-
expect(component.find(UploadIcon)).toHaveLength(1);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('renders input file', () => {
|
|
56
|
-
expect(component.find('input[type="file"]')).toHaveLength(1);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('renders a custom usHelpImage file', () => {
|
|
60
|
-
component = shallow(
|
|
61
|
-
<UploadImageStep
|
|
62
|
-
{...UPLOADIMAGE_STEP_PROPS}
|
|
63
|
-
usHelpImage={<img src="https://test.com" alt="test" className="test-image" />}
|
|
64
|
-
/>,
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
expect(component.find('.test-image')).toHaveLength(1);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('should respect `errorIconLabel` override', () => {
|
|
71
|
-
const errorIconLabel = 'Error icon label';
|
|
72
|
-
component = shallow(
|
|
73
|
-
<UploadImageStep
|
|
74
|
-
{...UPLOADIMAGE_STEP_PROPS}
|
|
75
|
-
errorMessage="Maximum filesize is 2MB."
|
|
76
|
-
errorIconLabel={errorIconLabel}
|
|
77
|
-
/>,
|
|
78
|
-
);
|
|
79
|
-
expect(component.find(InlineAlert).prop('iconLabel')).toBe(errorIconLabel);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
describe('when errorMessage is not empty', () => {
|
|
83
|
-
it('renders errorMessage and icon when error is true', () => {
|
|
84
|
-
component = shallow(
|
|
85
|
-
<UploadImageStep {...UPLOADIMAGE_STEP_PROPS} errorMessage="error message" />,
|
|
86
|
-
);
|
|
87
|
-
expect(component.find('.upload-error-message').text()).toBe('<InlineAlert />');
|
|
88
|
-
expect(component.find(StatusIcon)).toHaveLength(1);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
});
|