@oiz/stzh-components 4.1.1-beta2 → 4.1.1-beta3
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/dist/cjs/{app-globals-4591a5a9.js → app-globals-6b2bb7e2.js} +2 -2
- package/dist/cjs/{app-globals-4591a5a9.js.map → app-globals-6b2bb7e2.js.map} +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/stzh-components.cjs.js +1 -1
- package/dist/cjs/stzh-upload.cjs.entry.js +23 -37
- package/dist/cjs/stzh-upload.cjs.entry.js.map +1 -1
- package/dist/collection/components/stzh-upload/stzh-upload.e2e.js +6 -2
- package/dist/collection/components/stzh-upload/stzh-upload.e2e.js.map +1 -1
- package/dist/collection/components/stzh-upload/stzh-upload.js +24 -38
- package/dist/collection/components/stzh-upload/stzh-upload.js.map +1 -1
- package/dist/collection/components/stzh-upload/stzh-upload.stories.js +524 -28
- package/dist/components/index.js +1 -1
- package/dist/components/stzh-upload.js +23 -37
- package/dist/components/stzh-upload.js.map +1 -1
- package/dist/esm/{app-globals-b6c1c47f.js → app-globals-d150c886.js} +2 -2
- package/dist/esm/{app-globals-b6c1c47f.js.map → app-globals-d150c886.js.map} +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/stzh-components.js +1 -1
- package/dist/esm/stzh-upload.entry.js +23 -37
- package/dist/esm/stzh-upload.entry.js.map +1 -1
- package/dist/stzh-components/{p-0895d027.js → p-cac56a03.js} +2 -2
- package/dist/stzh-components/{p-f91f7483.entry.js → p-e4bf1c8d.entry.js} +2 -2
- package/dist/stzh-components/p-e4bf1c8d.entry.js.map +1 -0
- package/dist/stzh-components/stzh-components.esm.js +1 -1
- package/dist/types/components/stzh-upload/stzh-upload.d.ts +3 -2
- package/dist/types/components.d.ts +2 -2
- package/dist/vscode-data.json +1 -1
- package/package.json +1 -1
- package/dist/stzh-components/p-f91f7483.entry.js.map +0 -1
- /package/dist/stzh-components/{p-0895d027.js.map → p-cac56a03.js.map} +0 -0
|
@@ -3,29 +3,59 @@ import { withActions } from '@storybook/addon-actions/decorator';
|
|
|
3
3
|
import readme from './readme.md?raw';
|
|
4
4
|
|
|
5
5
|
import { getFigmaLink } from '../../../figma';
|
|
6
|
+
import {
|
|
7
|
+
expectIsVisible,
|
|
8
|
+
getComponentByTestId, sleep,
|
|
9
|
+
waitForElement,
|
|
10
|
+
waitForEvent
|
|
11
|
+
} from "../../../.storybook/utils/component-test-utils";
|
|
12
|
+
import { expect } from "@storybook/jest";
|
|
13
|
+
import { fireEvent } from "@storybook/testing-library";
|
|
6
14
|
|
|
7
15
|
const COMPONENT_NAME = 'stzh-upload';
|
|
8
16
|
const story = createComponentStory(COMPONENT_NAME);
|
|
9
|
-
const
|
|
10
|
-
|
|
17
|
+
const UPLOAD_TEST_ID = 'UPLOAD_TEST_ID';
|
|
18
|
+
let stzhUploadEl;
|
|
11
19
|
|
|
12
20
|
const TEMPLATE = `
|
|
13
|
-
<stzh-upload
|
|
21
|
+
<stzh-upload hide-progress data-testid="${UPLOAD_TEST_ID}"></stzh-upload>
|
|
14
22
|
`;
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Simulates uploading files into stzh-upload component via file browser.
|
|
26
|
+
*
|
|
27
|
+
* @param targetEl The host element (stzh-upload) with the file input.
|
|
28
|
+
* @param files Array of files: each { filename, filetype, content }
|
|
29
|
+
*/
|
|
30
|
+
async function chooseFilesToUpload(
|
|
31
|
+
targetEl,
|
|
32
|
+
files,
|
|
33
|
+
) {
|
|
34
|
+
// Prepare DataTransfer with files
|
|
35
|
+
const dataTransfer = new DataTransfer();
|
|
36
|
+
files.forEach(fileDef => {
|
|
37
|
+
const file = new File(
|
|
38
|
+
[fileDef.content ?? 'dummy content'],
|
|
39
|
+
fileDef.filename,
|
|
40
|
+
{ type: fileDef.filetype }
|
|
41
|
+
);
|
|
42
|
+
dataTransfer.items.add(file);
|
|
43
|
+
});
|
|
21
44
|
|
|
22
|
-
|
|
23
|
-
|
|
45
|
+
const fileInput = targetEl.querySelector('input[type="file"]');
|
|
46
|
+
if (!fileInput) throw new Error('File input not found');
|
|
24
47
|
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
|
|
48
|
+
// Assign files (using DataTransfer for realism)
|
|
49
|
+
fileInput.focus();
|
|
50
|
+
// @ts-ignore: files is readonly, but works in test envs
|
|
51
|
+
fileInput.files = dataTransfer.files;
|
|
52
|
+
|
|
53
|
+
fileInput.dispatchEvent(new Event('input', { bubbles: true }));
|
|
54
|
+
await new Promise(r => setTimeout(r, 0));
|
|
55
|
+
fileInput.dispatchEvent(new Event('change', { bubbles: true }));
|
|
56
|
+
await new Promise(r => setTimeout(r, 0));
|
|
57
|
+
fileInput.blur();
|
|
58
|
+
}
|
|
29
59
|
|
|
30
60
|
export default {
|
|
31
61
|
title: 'Components/Upload',
|
|
@@ -72,43 +102,509 @@ export const Default = {
|
|
|
72
102
|
render: (args) => story(args, TEMPLATE),
|
|
73
103
|
args: {
|
|
74
104
|
url: '/upload',
|
|
75
|
-
|
|
76
|
-
'accepted-files': acceptedFilesDefault,
|
|
77
|
-
'max-filesize-total': 15,
|
|
78
|
-
'max-filesize': 5
|
|
105
|
+
'auto-process-queue': false
|
|
79
106
|
},
|
|
107
|
+
play: async ({ canvasElement, step }) => {
|
|
108
|
+
stzhUploadEl = await getComponentByTestId( canvasElement, UPLOAD_TEST_ID);
|
|
109
|
+
|
|
110
|
+
await step('Assert attributes', async () => {
|
|
111
|
+
expect(stzhUploadEl).toHaveAttribute('auto-process-queue', 'false');
|
|
112
|
+
expect(stzhUploadEl).toHaveAttribute('hide-progress');
|
|
113
|
+
expect(stzhUploadEl).toHaveAttribute('url', '/upload');
|
|
114
|
+
expect(stzhUploadEl).toHaveAttribute('accepted-files', '.jpg,.png,.pdf');
|
|
115
|
+
expect(stzhUploadEl).not.toHaveAttribute('label');
|
|
116
|
+
expect(stzhUploadEl).not.toHaveAttribute('disabled');
|
|
117
|
+
expect(stzhUploadEl).not.toHaveAttribute('max-filesize-total');
|
|
118
|
+
expect(stzhUploadEl).not.toHaveAttribute('max-filesize');
|
|
119
|
+
expect(stzhUploadEl).not.toHaveAttribute('photographing-enabled');
|
|
120
|
+
expect(stzhUploadEl).not.toHaveAttribute('prevent-duplicate-file-names');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
await step('Upload button and hints for file formats and max size are visible', async () => {
|
|
124
|
+
const uploadButtonEl = stzhUploadEl.querySelector('.stzh-upload__button');
|
|
125
|
+
expectIsVisible(uploadButtonEl);
|
|
126
|
+
|
|
127
|
+
const uploadInstructionsEl = stzhUploadEl.querySelector('.stzh-upload__instructions');
|
|
128
|
+
expectIsVisible(uploadInstructionsEl);
|
|
129
|
+
|
|
130
|
+
expect(uploadInstructionsEl.textContent).toContain('Allowed file formats: .jpg,.png,.pdf (max. 25 MB per file)');
|
|
131
|
+
expect(uploadInstructionsEl.textContent).toContain('Max. size of all files: 100 MB');
|
|
132
|
+
|
|
133
|
+
// photographing button is not visible
|
|
134
|
+
const uploadButtonScanEl = stzhUploadEl.querySelector('.stzh-upload__button-scan');
|
|
135
|
+
expect(uploadButtonScanEl).toBeNull();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
await step('Assert event details of stzhFilesAdded, stzhFileRemove and stzhFileRemoved', async () => {
|
|
139
|
+
|
|
140
|
+
const stzhFilesAddedEventDetailPromise = waitForEvent(stzhUploadEl, 'stzhFilesAdded');
|
|
141
|
+
|
|
142
|
+
chooseFilesToUpload(stzhUploadEl, [
|
|
143
|
+
{ filename: 'file-1.pdf', filetype: 'application/pdf', content: 'file 1 pdf' },
|
|
144
|
+
{ filename: 'file-2.png', filetype: 'image/png', content: 'file 2 png' }
|
|
145
|
+
]);
|
|
146
|
+
|
|
147
|
+
const stzhFilesAddedEventDetail = await stzhFilesAddedEventDetailPromise;
|
|
148
|
+
expect(stzhFilesAddedEventDetail).toHaveProperty('component', 'stzh-upload');
|
|
149
|
+
const files = stzhFilesAddedEventDetail.files;
|
|
150
|
+
expect(files).toHaveLength(2);
|
|
151
|
+
expect(files[0]).toHaveProperty('status', 'queued');
|
|
152
|
+
expect(files[0].upload).toHaveProperty('filename', 'file-1.pdf');
|
|
153
|
+
expect(files[1]).toHaveProperty('status', 'queued');
|
|
154
|
+
expect(files[1].upload).toHaveProperty('filename', 'file-2.png');
|
|
155
|
+
|
|
156
|
+
// Remove files
|
|
157
|
+
const uploadActions = await waitForElement(() => stzhUploadEl, '.stzh-upload__delete', {multiple: true});
|
|
158
|
+
expect(uploadActions.length).toBe(2);
|
|
159
|
+
|
|
160
|
+
let stzhFileRemoveDetail;
|
|
161
|
+
stzhUploadEl.addEventListener('stzhFileRemove', (ev) => {
|
|
162
|
+
stzhFileRemoveDetail = ev.detail;
|
|
163
|
+
});
|
|
164
|
+
let stzhFileRemovedDetail;
|
|
165
|
+
stzhUploadEl.addEventListener('stzhFileRemoved', (ev) => {
|
|
166
|
+
stzhFileRemovedDetail = ev.detail;
|
|
167
|
+
});
|
|
168
|
+
fireEvent.click(uploadActions[0]);
|
|
169
|
+
expect(stzhFileRemoveDetail).toHaveProperty('component', 'stzh-upload');
|
|
170
|
+
expect(stzhFileRemoveDetail.file.upload).toHaveProperty('filename', 'file-1.pdf');
|
|
171
|
+
|
|
172
|
+
expect(stzhFileRemovedDetail).toHaveProperty('component', 'stzh-upload');
|
|
173
|
+
expect(stzhFileRemovedDetail.file.upload).toHaveProperty('filename', 'file-1.pdf');
|
|
174
|
+
|
|
175
|
+
fireEvent.click(uploadActions[1]);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
80
178
|
};
|
|
81
179
|
|
|
82
180
|
export const ExistingFiles = {
|
|
83
181
|
render: (args) => story(args, TEMPLATE),
|
|
84
182
|
args: {
|
|
85
183
|
url: '/upload',
|
|
86
|
-
label:
|
|
87
|
-
'accepted-files': acceptedFilesDefault,
|
|
184
|
+
label: 'Lohnausweise',
|
|
88
185
|
existingFiles: [
|
|
89
186
|
{ name: 'Filename.pdf', url: 'media/samples/document.pdf', size: 12572426, id: 'upload-1' },
|
|
90
|
-
{ name: 'Filename2.
|
|
91
|
-
{ name: 'Filename3.
|
|
187
|
+
{ name: 'Filename2.png', url: 'media/samples/document.png', size: 22345, id: 'upload-2' },
|
|
188
|
+
{ name: 'Filename3.jpg', url: 'media/samples/document.jpg', size: 2705487, id: 'upload-3' },
|
|
92
189
|
],
|
|
190
|
+
'auto-process-queue': false
|
|
93
191
|
},
|
|
192
|
+
play: async ({ canvasElement, step }) => {
|
|
193
|
+
stzhUploadEl = await getComponentByTestId( canvasElement, UPLOAD_TEST_ID);
|
|
194
|
+
|
|
195
|
+
await step('Assert attributes', async () => {
|
|
196
|
+
expect(stzhUploadEl).toHaveAttribute('label', 'Lohnausweise');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
await step('Existing files are being displayed', async () => {
|
|
200
|
+
const uploadPreviewsContainerEl = stzhUploadEl.querySelector('.stzh-upload__previews');
|
|
201
|
+
const uploadPreviews = uploadPreviewsContainerEl.querySelectorAll('.stzh-upload__preview');
|
|
202
|
+
expect(uploadPreviews.length).toBe(3);
|
|
203
|
+
|
|
204
|
+
// Preview elements contain correct filename, size and type
|
|
205
|
+
const expectedFilename1 = 'Filename.pdf';
|
|
206
|
+
const expectedFiletype1 = 'pdf';
|
|
207
|
+
const expectedFilesize1 = '11.99 MiB';
|
|
208
|
+
const actualTextPreview1 = uploadPreviews[0].textContent || '';
|
|
209
|
+
expect(actualTextPreview1).toContain(expectedFilename1);
|
|
210
|
+
expect(actualTextPreview1).toContain(expectedFiletype1);
|
|
211
|
+
expect(actualTextPreview1).toContain(expectedFilesize1);
|
|
212
|
+
|
|
213
|
+
const expectedFilename2 = 'Filename2.png';
|
|
214
|
+
const expectedFiletype2 = 'png';
|
|
215
|
+
const expectedFilesize2 = '21.82 KiB';
|
|
216
|
+
const actualTextPreview2 = uploadPreviews[1].textContent || '';
|
|
217
|
+
expect(actualTextPreview2).toContain(expectedFilename2);
|
|
218
|
+
expect(actualTextPreview2).toContain(expectedFiletype2);
|
|
219
|
+
expect(actualTextPreview2).toContain(expectedFilesize2);
|
|
220
|
+
|
|
221
|
+
const expectedFilename3 = 'Filename3.jpg';
|
|
222
|
+
const expectedFiletype3 = 'jpg';
|
|
223
|
+
const expectedFilesize3 = '2.58 MiB';
|
|
224
|
+
const actualTextPreview3 = uploadPreviews[2].textContent || '';
|
|
225
|
+
expect(actualTextPreview3).toContain(expectedFilename3);
|
|
226
|
+
expect(actualTextPreview3).toContain(expectedFiletype3);
|
|
227
|
+
expect(actualTextPreview3).toContain(expectedFilesize3);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
94
230
|
};
|
|
95
231
|
|
|
96
|
-
export const
|
|
232
|
+
export const PhotographingEnabled = {
|
|
97
233
|
render: (args) => story(args, TEMPLATE),
|
|
98
234
|
args: {
|
|
99
235
|
url: '/upload',
|
|
100
|
-
label:
|
|
101
|
-
'accepted-files': '.jpg,.jpeg,.png',
|
|
236
|
+
label: 'Lohnausweis',
|
|
102
237
|
'photographing-enabled': true,
|
|
238
|
+
'auto-process-queue': false
|
|
239
|
+
},
|
|
240
|
+
play: async ({ canvasElement, step }) => {
|
|
241
|
+
stzhUploadEl = await getComponentByTestId(canvasElement, UPLOAD_TEST_ID);
|
|
242
|
+
|
|
243
|
+
await step('Assert attributes', async () => {
|
|
244
|
+
expect(stzhUploadEl).toHaveAttribute('photographing-enabled', 'true');
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
await step('Click on photograph document button shows instruction', async () => {
|
|
248
|
+
const uploadButtonScanEl = await waitForElement(() => stzhUploadEl, '.stzh-upload__button-scan');
|
|
249
|
+
expect(uploadButtonScanEl).not.toBeNull();
|
|
250
|
+
uploadButtonScanEl.click();
|
|
251
|
+
|
|
252
|
+
const dialogEl = await waitForElement(() => stzhUploadEl, '.stzh-dialog');
|
|
253
|
+
expect(dialogEl.textContent).toContain('Connect smartphone or tablet');
|
|
254
|
+
expect(dialogEl.textContent).toContain('Scan the QR code with the camera of your mobile device');
|
|
255
|
+
|
|
256
|
+
// QR-Code canvas exists
|
|
257
|
+
const canvasEl = dialogEl.querySelector('canvas.stzh-upload-photographing-qrcode');
|
|
258
|
+
expect(canvasEl).not.toBeNull();
|
|
259
|
+
|
|
260
|
+
// click back Button
|
|
261
|
+
const backButtonEl = dialogEl.querySelector('.stzh-upload-photographing__back-button');
|
|
262
|
+
expect(backButtonEl).not.toBeNull();
|
|
263
|
+
backButtonEl.click();
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
export const LimitedFileSize = {
|
|
269
|
+
render: (args) => story(args, TEMPLATE),
|
|
270
|
+
args: {
|
|
271
|
+
url: '/upload',
|
|
272
|
+
"max-filesize-total": 6,
|
|
273
|
+
"max-filesize": 2,
|
|
274
|
+
"accepted-files": '.pdf',
|
|
275
|
+
'auto-process-queue': false
|
|
103
276
|
},
|
|
277
|
+
parameters: {
|
|
278
|
+
test: {
|
|
279
|
+
dangerouslyIgnoreUnhandledErrors: true
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
play: async ({ canvasElement, step }) => {
|
|
283
|
+
stzhUploadEl = await getComponentByTestId( canvasElement, UPLOAD_TEST_ID);
|
|
284
|
+
|
|
285
|
+
await step('Assert attributes', async () => {
|
|
286
|
+
expect(stzhUploadEl).toHaveAttribute('max-filesize', '2');
|
|
287
|
+
expect(stzhUploadEl).toHaveAttribute('max-filesize-total', '6');
|
|
288
|
+
expect(stzhUploadEl).toHaveAttribute('accepted-files', '.pdf');
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
await step('Non-default max sizes are being displayed', async () => {
|
|
292
|
+
const uploadInstructionsEl = stzhUploadEl.querySelector('.stzh-upload__instructions');
|
|
293
|
+
expect(uploadInstructionsEl.textContent).toContain('Allowed file formats: .pdf (max. 2 MB per file)');
|
|
294
|
+
expect(uploadInstructionsEl.textContent).toContain('Max. size of all files: 6 MB');
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
await step('Exceeding max-filesize renders file preview with error status and triggers stzhError event', async () => {
|
|
298
|
+
const MB = 1024 * 1024;
|
|
299
|
+
|
|
300
|
+
const stzhErrorEventDetailPromise = waitForEvent(stzhUploadEl, 'stzhError');
|
|
301
|
+
|
|
302
|
+
chooseFilesToUpload(stzhUploadEl, [
|
|
303
|
+
{ filename: 'below-2-MB.pdf', filetype: 'application/pdf', content: 'a'.repeat(1.99 * MB) },
|
|
304
|
+
{ filename: 'above-2-MB.pdf', filetype: 'application/pdf', content: 'b'.repeat(2.01 * MB) }
|
|
305
|
+
]);
|
|
306
|
+
|
|
307
|
+
// too large file in .stzh-upload__errors container and contains message
|
|
308
|
+
const uploadErrorsContainerEl = await waitForElement(() => stzhUploadEl, '.stzh-upload__errors');
|
|
309
|
+
const uploadErrorPreviews = await waitForElement(() => uploadErrorsContainerEl, '.stzh-upload__info-wrapper', {multiple: true});
|
|
310
|
+
expect(uploadErrorPreviews).toHaveLength(1);
|
|
311
|
+
expect(uploadErrorPreviews[0].textContent).toContain('File is too big (2.01MiB). Max filesize: 2MiB.');
|
|
312
|
+
|
|
313
|
+
// stzhError event is triggered and has correct values
|
|
314
|
+
const stzhErrorEventDetail = await stzhErrorEventDetailPromise;
|
|
315
|
+
expect(stzhErrorEventDetail).toHaveProperty('component', 'stzh-upload');
|
|
316
|
+
expect(stzhErrorEventDetail).toHaveProperty('message', 'File is too big (2.01MiB). Max filesize: 2MiB.');
|
|
317
|
+
expect(stzhErrorEventDetail.file).toHaveProperty('accepted', false);
|
|
318
|
+
expect(stzhErrorEventDetail.file).toHaveProperty('status', 'error');
|
|
319
|
+
expect(stzhErrorEventDetail.file.upload).toHaveProperty('filename', 'above-2-MB.pdf');
|
|
320
|
+
|
|
321
|
+
// reset to initial state
|
|
322
|
+
const uploadActions = await waitForElement(() => stzhUploadEl, '.stzh-upload__delete', {multiple: true});
|
|
323
|
+
fireEvent.click(uploadActions[0]);
|
|
324
|
+
fireEvent.click(uploadActions[1]);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
await step('Exceeding max-filesize-total displays message and does not add last file', async () => {
|
|
328
|
+
const MB = 1024 * 1024;
|
|
329
|
+
|
|
330
|
+
chooseFilesToUpload(stzhUploadEl, [
|
|
331
|
+
{ filename: '1-MB.pdf', filetype: 'application/pdf', content: 'a'.repeat(1 * MB) },
|
|
332
|
+
{ filename: '2-MB.pdf', filetype: 'application/pdf', content: 'a'.repeat(2 * MB) },
|
|
333
|
+
{ filename: '2-MB-2.pdf', filetype: 'application/pdf', content: 'a'.repeat(2 * MB) },
|
|
334
|
+
{ filename: 'above-1-MB.pdf', filetype: 'application/pdf', content: 'b'.repeat(1.01 * MB) }
|
|
335
|
+
]);
|
|
336
|
+
|
|
337
|
+
// the 4th file won't appear in the previews
|
|
338
|
+
const uploadPreviewsContainerEl = await waitForElement(() => stzhUploadEl, '.stzh-upload__previews');
|
|
339
|
+
|
|
340
|
+
const uploadPreviews = await waitForElement(() => uploadPreviewsContainerEl, '.stzh-upload__preview', {multiple: true});
|
|
341
|
+
expect(uploadPreviews).toHaveLength(3);
|
|
342
|
+
|
|
343
|
+
// message
|
|
344
|
+
const stzhUploadMessageTextWrapperEl = await waitForElement(() => stzhUploadEl, '.stzh-message__text-wrapper');
|
|
345
|
+
expect(stzhUploadMessageTextWrapperEl.textContent).toContain('File(s) could not be uploaded.');
|
|
346
|
+
expect(stzhUploadMessageTextWrapperEl.textContent).toContain('The total size of all files is too big (6.0MiB). Maximum allowed size: 6MiB.');
|
|
347
|
+
});
|
|
348
|
+
}
|
|
104
349
|
};
|
|
105
350
|
|
|
106
|
-
export const
|
|
351
|
+
export const PreventDuplicateFileNames = {
|
|
107
352
|
render: (args) => story(args, TEMPLATE),
|
|
108
353
|
args: {
|
|
109
354
|
url: '/upload',
|
|
110
|
-
label:
|
|
111
|
-
'accepted-files': acceptedFilesDefault,
|
|
355
|
+
label: 'Lohnausweis',
|
|
112
356
|
'prevent-duplicate-file-names': true,
|
|
357
|
+
'auto-process-queue': false
|
|
358
|
+
},
|
|
359
|
+
play: async ({ canvasElement, step }) => {
|
|
360
|
+
stzhUploadEl = await getComponentByTestId( canvasElement, UPLOAD_TEST_ID);
|
|
361
|
+
|
|
362
|
+
await step('Assert attributes', async () => {
|
|
363
|
+
expect(stzhUploadEl).toHaveAttribute('prevent-duplicate-file-names', 'true');
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
await step('Duplicate filename message is being displayed', async () => {
|
|
367
|
+
chooseFilesToUpload(stzhUploadEl, [
|
|
368
|
+
{ filename: 'file-1.pdf', filetype: 'application/pdf', content: 'file 1 pdf' },
|
|
369
|
+
{ filename: 'file-1.pdf', filetype: 'application/pdf', content: 'file 1 **different content** pdf' },
|
|
370
|
+
]);
|
|
371
|
+
|
|
372
|
+
const stzhUploadMessageTextWrapperEl = await waitForElement(() => stzhUploadEl, '.stzh-message__text-wrapper');
|
|
373
|
+
expect(stzhUploadMessageTextWrapperEl.textContent).toContain('A file with that name already exists');
|
|
374
|
+
expect(stzhUploadMessageTextWrapperEl.textContent).toContain('file-1.pdf');
|
|
375
|
+
|
|
376
|
+
// wait until duplicate preview dissolves
|
|
377
|
+
await sleep(2100);
|
|
378
|
+
|
|
379
|
+
const uploadPreviews = await waitForElement(() => stzhUploadEl, '.stzh-upload__preview', {multiple: true});
|
|
380
|
+
expect(uploadPreviews.length).toBe(1);
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
export const Disabled = {
|
|
386
|
+
render: (args) => story(args, TEMPLATE),
|
|
387
|
+
args: {
|
|
388
|
+
url: '/upload',
|
|
389
|
+
disabled: true,
|
|
390
|
+
'auto-process-queue': false
|
|
391
|
+
},
|
|
392
|
+
play: async ({ canvasElement, step }) => {
|
|
393
|
+
stzhUploadEl = await getComponentByTestId( canvasElement, UPLOAD_TEST_ID);
|
|
394
|
+
|
|
395
|
+
await step('Assert attributes', async () => {
|
|
396
|
+
expect(stzhUploadEl).toHaveAttribute('disabled');
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
await step('Upload button is disabled', async () => {
|
|
400
|
+
const uploadButtonEl = stzhUploadEl.querySelector('.stzh-upload__button');
|
|
401
|
+
expect(uploadButtonEl).toHaveAttribute('disabled');
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
const TEMPLATE_FORM_DATA = `
|
|
407
|
+
<form action="/upload" method="post" enctype="multipart/form-data">
|
|
408
|
+
<stzh-vspace>
|
|
409
|
+
<stzh-text size="milli">Make sure to set prevent-hidden-input-clear=true if you use stzh-upload inside a multipart/formdata form with method=post.</stzh-text>
|
|
410
|
+
<stzh-upload name="stzh-file" hide-progress data-testid="${UPLOAD_TEST_ID}"></stzh-upload>
|
|
411
|
+
<stzh-text size="milli">Native file input as comparison</stzh-text>
|
|
412
|
+
<input type="file" name="stzh-native-file-input">
|
|
413
|
+
<div>
|
|
414
|
+
<stzh-input name="stzh-input" label="Text input" hide-optional="true" value="Default value" default-value="Default value">
|
|
415
|
+
</div>
|
|
416
|
+
</stzh-vspace>
|
|
417
|
+
<stzh-vspace></stzh-vspace>
|
|
418
|
+
<stzh-button type="submit">Submit</stzh-button>
|
|
419
|
+
<stzh-button type="reset" variant="secondary">Reset</stzh-button>
|
|
420
|
+
</form>
|
|
421
|
+
`;
|
|
422
|
+
|
|
423
|
+
// prevent redirecting to upload url after submit in the next test
|
|
424
|
+
let submitEvent;
|
|
425
|
+
function handleSubmit(ev) {
|
|
426
|
+
submitEvent = ev;
|
|
427
|
+
ev.preventDefault();
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export const InsideNativeFormUsingPost = {
|
|
431
|
+
render: (args) => story(args, TEMPLATE_FORM_DATA),
|
|
432
|
+
args: {
|
|
433
|
+
url: '/upload',
|
|
434
|
+
'prevent-hidden-input-clear': true,
|
|
435
|
+
'auto-process-queue': false,
|
|
436
|
+
'hide-progress': true
|
|
437
|
+
},
|
|
438
|
+
play: async ({ canvasElement, step }) => {
|
|
439
|
+
stzhUploadEl = await getComponentByTestId(canvasElement, UPLOAD_TEST_ID);
|
|
440
|
+
const formEl = canvasElement.querySelector('form');
|
|
441
|
+
const nativeFileInput = formEl.querySelector('input[type="file"][name="stzh-native-file-input"]');
|
|
442
|
+
const textInput = formEl.querySelector('stzh-input');
|
|
443
|
+
const submitButton = formEl.querySelector('stzh-button button[type="submit"]');
|
|
444
|
+
|
|
445
|
+
await step('FormData contains all form fields after submit', async () => {
|
|
446
|
+
|
|
447
|
+
// Upload file to stzh-upload
|
|
448
|
+
await chooseFilesToUpload(stzhUploadEl, [
|
|
449
|
+
{ filename: 'file1.pdf', filetype: 'application/pdf', content: 'file one' }
|
|
450
|
+
]);
|
|
451
|
+
|
|
452
|
+
// Upload file to native input
|
|
453
|
+
const nativeFile = new File(['native file'], 'nativefile.txt', { type: 'text/plain' });
|
|
454
|
+
const dataTransfer = new DataTransfer();
|
|
455
|
+
dataTransfer.items.add(nativeFile);
|
|
456
|
+
nativeFileInput.files = dataTransfer.files;
|
|
457
|
+
nativeFileInput.dispatchEvent(new Event('input', { bubbles: true }));
|
|
458
|
+
nativeFileInput.dispatchEvent(new Event('change', { bubbles: true }));
|
|
459
|
+
|
|
460
|
+
// Spy on submit event > don’t reload page
|
|
461
|
+
formEl.addEventListener('submit', handleSubmit, { once: true });
|
|
462
|
+
|
|
463
|
+
// Submit the form
|
|
464
|
+
submitButton.click();
|
|
465
|
+
await new Promise(r => setTimeout(r, 0));
|
|
466
|
+
|
|
467
|
+
// Assert submit event happened
|
|
468
|
+
expect(submitEvent).toBeDefined();
|
|
469
|
+
|
|
470
|
+
// Assert FormData fields
|
|
471
|
+
const formData = new FormData(formEl);
|
|
472
|
+
expect([...formData.keys()]).toEqual(
|
|
473
|
+
expect.arrayContaining(['stzh-file', 'stzh-native-file-input', 'stzh-input'])
|
|
474
|
+
);
|
|
475
|
+
|
|
476
|
+
const uploadedFile = formData.get('stzh-file');
|
|
477
|
+
expect(uploadedFile && uploadedFile.constructor.name).toBe('File');
|
|
478
|
+
expect(uploadedFile.name).toBe('file1.pdf');
|
|
479
|
+
|
|
480
|
+
const uploadedNativeFile = formData.get('stzh-native-file-input');
|
|
481
|
+
expect(uploadedNativeFile && uploadedNativeFile.constructor.name).toBe('File');
|
|
482
|
+
expect(uploadedNativeFile.name).toBe('nativefile.txt');
|
|
483
|
+
|
|
484
|
+
expect(formData.get('stzh-input')).toBe('Default value');
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
await step('reset clears formdata', async () => {
|
|
488
|
+
// Find the reset button (target the native button inside stzh-button)
|
|
489
|
+
const resetButton = formEl.querySelector('stzh-button[type="reset"] button[type="reset"]');
|
|
490
|
+
|
|
491
|
+
// Click the reset button
|
|
492
|
+
resetButton.click();
|
|
493
|
+
await new Promise(r => setTimeout(r, 200));
|
|
494
|
+
|
|
495
|
+
// Native file input should have no files
|
|
496
|
+
expect(nativeFileInput.files.length).toBe(0);
|
|
497
|
+
|
|
498
|
+
// Custom upload previews should be gone
|
|
499
|
+
const uploadPreviewsContainerEl = await waitForElement(() => stzhUploadEl, '.stzh-upload__previews');
|
|
500
|
+
const uploadPreviews = uploadPreviewsContainerEl.querySelectorAll('.stzh-upload__preview');//await waitForElement(() => uploadPreviewsContainerEl, '.stzh-upload__preview', {multiple: true});
|
|
501
|
+
expect(uploadPreviews).toHaveLength(0);
|
|
502
|
+
|
|
503
|
+
// Text input should be reset to default value
|
|
504
|
+
const actualTextInput = textInput.querySelector('input');
|
|
505
|
+
expect(actualTextInput.value).toBe('Default value');
|
|
506
|
+
|
|
507
|
+
// assert FormData to verify all fields are reset
|
|
508
|
+
const formDataAfterReset = new FormData(formEl);
|
|
509
|
+
|
|
510
|
+
// stzh-input is reset to its defautl value
|
|
511
|
+
expect(formDataAfterReset.get('stzh-input')).toBe('Default value');
|
|
512
|
+
|
|
513
|
+
// File inputs after reset
|
|
514
|
+
const uploadedFile = formDataAfterReset.get('stzh-file');
|
|
515
|
+
expect(
|
|
516
|
+
uploadedFile === null ||
|
|
517
|
+
(typeof uploadedFile === 'object' && Object.keys(uploadedFile).length === 0)
|
|
518
|
+
).toBe(true);
|
|
519
|
+
|
|
520
|
+
const uploadedFileNative = formDataAfterReset.get('stzh-native-file-input');
|
|
521
|
+
expect(
|
|
522
|
+
uploadedFileNative === null ||
|
|
523
|
+
(typeof uploadedFileNative === 'object' && Object.keys(uploadedFileNative).length === 0)
|
|
524
|
+
).toBe(true);
|
|
525
|
+
});
|
|
526
|
+
},
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
export const AutoProcessQueue = {
|
|
530
|
+
render: (args) => story(args, TEMPLATE),
|
|
531
|
+
args: {
|
|
532
|
+
url: '/upload',
|
|
533
|
+
'auto-process-queue': true,
|
|
534
|
+
'disable-toasts': true
|
|
535
|
+
},
|
|
536
|
+
play: async ({ canvasElement, step }) => {
|
|
537
|
+
stzhUploadEl = await getComponentByTestId(canvasElement, UPLOAD_TEST_ID);
|
|
538
|
+
|
|
539
|
+
await step('stzhProcessing, stzhSending, stzhProgress, stzhProgressTotal, stzhError (404) and stzhComplete events are being triggered', async () => {
|
|
540
|
+
|
|
541
|
+
const stzhProcessingEventDetailPromise = waitForEvent(stzhUploadEl, 'stzhProcessing');
|
|
542
|
+
const stzhSendingEventDetailPromise = waitForEvent(stzhUploadEl, 'stzhSending');
|
|
543
|
+
const stzhProgressEventDetailPromise = waitForEvent(stzhUploadEl, 'stzhProgress');
|
|
544
|
+
const stzhProgressTotalEventDetailPromise = waitForEvent(stzhUploadEl, 'stzhProgressTotal');
|
|
545
|
+
const stzhErrorEventDetailPromise = waitForEvent(stzhUploadEl, 'stzhError');
|
|
546
|
+
const stzhCompleteEventDetailPromise = waitForEvent(stzhUploadEl, 'stzhComplete');
|
|
547
|
+
|
|
548
|
+
chooseFilesToUpload(stzhUploadEl, [
|
|
549
|
+
{ filename: 'file-1.pdf', filetype: 'application/pdf', content: 'file 1 pdf' }
|
|
550
|
+
]);
|
|
551
|
+
|
|
552
|
+
const stzhProcessingEventDetail = await stzhProcessingEventDetailPromise;
|
|
553
|
+
expect(stzhProcessingEventDetail).toHaveProperty('component', 'stzh-upload');
|
|
554
|
+
const stzhProcessingEventDetailFile = stzhProcessingEventDetail.file;
|
|
555
|
+
expect(stzhProcessingEventDetailFile).toHaveProperty('status', 'uploading');
|
|
556
|
+
const stzhProcessingEventDetailUpload = stzhProcessingEventDetail.file.upload;
|
|
557
|
+
expect(stzhProcessingEventDetailUpload).toHaveProperty('filename', 'file-1.pdf');
|
|
558
|
+
expect(stzhProcessingEventDetailUpload).toHaveProperty('progress', 0);
|
|
559
|
+
expect(stzhProcessingEventDetailUpload).toHaveProperty('uuid');
|
|
560
|
+
|
|
561
|
+
const stzhSendingEventDetail = await stzhSendingEventDetailPromise;
|
|
562
|
+
expect(stzhSendingEventDetail).toHaveProperty('component', 'stzh-upload');
|
|
563
|
+
const stzhSendingEventDetailFile = stzhSendingEventDetail.file;
|
|
564
|
+
expect(stzhSendingEventDetailFile).toHaveProperty('status', 'uploading');
|
|
565
|
+
const stzhSendingEventDetailUpload = stzhProcessingEventDetail.file.upload;
|
|
566
|
+
expect(stzhSendingEventDetailUpload).toHaveProperty('filename', 'file-1.pdf');
|
|
567
|
+
expect(stzhSendingEventDetailUpload).toHaveProperty('progress', 0);
|
|
568
|
+
expect(stzhSendingEventDetailUpload).toHaveProperty('uuid');
|
|
569
|
+
|
|
570
|
+
const stzhProgressEventDetail = await stzhProgressEventDetailPromise;
|
|
571
|
+
expect(stzhProgressEventDetail).toHaveProperty('component', 'stzh-upload');
|
|
572
|
+
expect(stzhProgressEventDetail).toHaveProperty('bytesSent', 199);
|
|
573
|
+
const stzhProgressEventDetailFile = stzhProgressEventDetail.file;
|
|
574
|
+
expect(stzhProgressEventDetailFile).toHaveProperty('status', 'uploading');
|
|
575
|
+
const stzhProgressEventDetailUpload = stzhProgressEventDetail.file.upload;
|
|
576
|
+
expect(stzhProgressEventDetailUpload).toHaveProperty('filename', 'file-1.pdf');
|
|
577
|
+
expect(stzhProgressEventDetailUpload).toHaveProperty('progress', 100);
|
|
578
|
+
expect(stzhProgressEventDetailUpload).toHaveProperty('uuid');
|
|
579
|
+
|
|
580
|
+
const stzhProgressTotalEventDetail = await stzhProgressTotalEventDetailPromise;
|
|
581
|
+
expect(stzhProgressTotalEventDetail).toHaveProperty('component', 'stzh-upload');
|
|
582
|
+
expect(stzhProgressTotalEventDetail).toHaveProperty('totalBytes', 199);
|
|
583
|
+
expect(stzhProgressTotalEventDetail).toHaveProperty('totalBytesSent', 199);
|
|
584
|
+
expect(stzhProgressTotalEventDetail).toHaveProperty('totalUploadProgress', 100);
|
|
585
|
+
|
|
586
|
+
const stzhErrorEventDetail = await stzhErrorEventDetailPromise;
|
|
587
|
+
expect(stzhErrorEventDetail).toHaveProperty('component', 'stzh-upload');
|
|
588
|
+
expect(stzhErrorEventDetail).toHaveProperty('message');
|
|
589
|
+
const stzhErrorEventDetailFile = stzhErrorEventDetail.file;
|
|
590
|
+
expect(stzhErrorEventDetailFile).toHaveProperty('status', 'error');
|
|
591
|
+
const stzhErrorEventDetailUpload = stzhErrorEventDetail.file.upload;
|
|
592
|
+
expect(stzhErrorEventDetailUpload).toHaveProperty('filename', 'file-1.pdf');
|
|
593
|
+
expect(stzhErrorEventDetailUpload).toHaveProperty('progress', 100);
|
|
594
|
+
expect(stzhErrorEventDetailUpload).toHaveProperty('total', 199);
|
|
595
|
+
expect(stzhErrorEventDetailUpload).toHaveProperty('uuid');
|
|
596
|
+
|
|
597
|
+
const stzhCompleteEventDetail = await stzhCompleteEventDetailPromise;
|
|
598
|
+
expect(stzhCompleteEventDetail).toHaveProperty('component', 'stzh-upload');
|
|
599
|
+
const stzhCompleteEventDetailFile = stzhCompleteEventDetail.file;
|
|
600
|
+
expect(stzhCompleteEventDetailFile).toHaveProperty('status', 'error');
|
|
601
|
+
const stzhCompleteEventDetailUpload = stzhCompleteEventDetail.file.upload;
|
|
602
|
+
expect(stzhCompleteEventDetailUpload).toHaveProperty('filename', 'file-1.pdf');
|
|
603
|
+
expect(stzhCompleteEventDetailUpload).toHaveProperty('bytesSent', 199);
|
|
604
|
+
expect(stzhCompleteEventDetailUpload).toHaveProperty('total', 199);
|
|
605
|
+
expect(stzhCompleteEventDetailUpload).toHaveProperty('progress', 100);
|
|
606
|
+
expect(stzhCompleteEventDetailUpload).toHaveProperty('uuid');
|
|
607
|
+
|
|
608
|
+
});
|
|
113
609
|
},
|
|
114
610
|
};
|
package/dist/components/index.js
CHANGED
|
@@ -2,7 +2,7 @@ export { g as getAssetPath, s as setAssetPath, a as setNonce, b as setPlatformOp
|
|
|
2
2
|
export { S as StzhSocialmediastreamItemActionVariant, V as VBZ, t as tc } from './p-f5779736.js';
|
|
3
3
|
|
|
4
4
|
const name = "@oiz/stzh-components";
|
|
5
|
-
const version = "4.1.1-
|
|
5
|
+
const version = "4.1.1-beta3";
|
|
6
6
|
|
|
7
7
|
const packageName = name.substring(name.indexOf('/')+1);
|
|
8
8
|
// let focused = false;
|