Skip to content

Commit 438538c

Browse files
committed
corrected buggy modal from uploader.vue
1 parent 261cc59 commit 438538c

File tree

5 files changed

+75
-201
lines changed

5 files changed

+75
-201
lines changed

contentcuration/contentcuration/frontend/channelEdit/views/files/__tests__/thumbnailGenerator.spec.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { mount } from '@vue/test-utils';
22
import ThumbnailGenerator from '../thumbnails/ThumbnailGenerator';
33
import { factory } from '../../../store';
44

5-
function makeWrapper(filePath) {
5+
async function makeWrapper(filePath) {
66
const store = factory();
77
const handleFiles = jest.fn(() => true);
88

@@ -22,30 +22,33 @@ function makeWrapper(filePath) {
2222
const generateVideoThumbnail = jest.spyOn(wrapper.vm, 'generateVideoThumbnail');
2323
generateVideoThumbnail.mockImplementation(() => Promise.resolve());
2424

25-
return [wrapper, { fileExists, generateVideoThumbnail, handleFiles }];
25+
const handleGenerated = jest.spyOn(wrapper.vm, 'handleGenerated');
26+
handleGenerated.mockImplementation(() => {});
27+
28+
return [wrapper, { fileExists, generateVideoThumbnail, handleFiles, handleGenerated }];
2629
}
2730

2831
describe('thumbnailGenerator', () => {
2932
let wrapper, mocks;
3033

3134
it.each(
3235
['test.mp4', 'test.webm', 'test.mp3'],
33-
'correct generation code should be called',
34-
fileName => {
35-
[wrapper, mocks] = makeWrapper(fileName);
36-
wrapper.vm.generate();
36+
'correct generation code should be called for %s',
37+
async fileName => {
38+
[wrapper, mocks] = await makeWrapper(fileName);
39+
await wrapper.vm.generate();
3740
expect(mocks.generateVideoThumbnail).toHaveBeenCalled();
3841
},
3942
);
4043

41-
it('error alert should show if the file path is an unrecognized type', () => {
42-
[wrapper, mocks] = makeWrapper('test.wut');
43-
wrapper.vm.generate();
44+
it('error alert should show if the file path is an unrecognized type', async () => {
45+
[wrapper, mocks] = await makeWrapper('test.wut');
46+
await wrapper.vm.generate();
4447
expect(wrapper.vm.showErrorAlert).toBe(true);
4548
});
4649

4750
it('handleGenerated should not call handleFiles if cancelled', async () => {
48-
[wrapper, mocks] = makeWrapper('test.wut');
51+
[wrapper, mocks] = await makeWrapper('test.wut');
4952
await wrapper.setData({ cancelled: true });
5053
wrapper.vm.handleGenerated('');
5154
expect(mocks.handleFiles).not.toHaveBeenCalled();

contentcuration/contentcuration/frontend/channelEdit/views/files/thumbnails/ThumbnailGenerator.vue

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<template>
22

33
<div>
4-
<Alert
5-
v-model="showErrorAlert"
6-
:header="$tr('thumbnailGenerationFailedHeader')"
7-
:text="$tr('thumbnailGenerationFailedText')"
8-
/>
4+
<KModal
5+
v-if="showErrorAlert"
6+
:title="$tr('thumbnailGenerationFailedHeader')"
7+
:submitText="$tr('closeButtonLabel')"
8+
@submit="showErrorAlert = false"
9+
>
10+
<p>{{ $tr('thumbnailGenerationFailedText') }}</p>
11+
</KModal>
912
<slot :generate="generate"></slot>
1013
</div>
1114

@@ -22,7 +25,6 @@
2225
import epubJS from 'epubjs';
2326
import PDFJSWorker from '!!file-loader!pdfjs-dist/build/pdf.worker.min.js';
2427
import client from 'shared/client';
25-
import Alert from 'shared/views/Alert';
2628
import { ASPECT_RATIO, THUMBNAIL_WIDTH } from 'shared/constants';
2729
// Based off of solution here: https://github.com/mozilla/pdf.js/issues/7612#issuecomment-576807171
2830
const pdfJSLib = require('pdfjs-dist');
@@ -32,9 +34,7 @@
3234
3335
export default {
3436
name: 'ThumbnailGenerator',
35-
components: {
36-
Alert,
37-
},
37+
components: {},
3838
props: {
3939
filePath: {
4040
type: String,
@@ -241,6 +241,7 @@
241241
thumbnailGenerationFailedHeader: 'Unable to generate thumbnail',
242242
thumbnailGenerationFailedText: 'There was a problem generating a thumbnail',
243243
generatedDefaultFilename: 'Generated thumbnail',
244+
closeButtonLabel: 'OK',
244245
},
245246
};
246247

contentcuration/contentcuration/frontend/shared/views/Alert.vue

Lines changed: 0 additions & 111 deletions
This file was deleted.

contentcuration/contentcuration/frontend/shared/views/__tests__/alert.spec.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

contentcuration/contentcuration/frontend/shared/views/files/Uploader.vue

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,57 @@
2222
data-test="upload-dialog"
2323
@change="handleFiles($event.target.files)"
2424
>
25-
<Alert
26-
v-model="showUnsupportedFilesAlert"
27-
:header="$tr('unsupportedFilesHeader')"
28-
:text="unsupportedFilesText"
29-
/>
30-
<Alert
31-
v-model="showTooLargeFilesAlert"
32-
:header="$tr('tooLargeFilesHeader')"
33-
:text="
34-
$tr('maxFileSizeText', {
35-
count: tooLargeFiles.length,
36-
size: formatFileSize(maxFileSize),
37-
})
25+
<KModal
26+
v-if="showUnsupportedFilesAlert"
27+
:title="$tr('unsupportedFilesHeader')"
28+
:submitText="$tr('closeButtonLabel')"
29+
@submit="
30+
showUnsupportedFilesAlert = false;
31+
resetFileInput();
3832
"
39-
/>
40-
<Alert
41-
v-model="showStorageExceededAlert"
42-
:header="$tr('noStorageHeader')"
43-
text=""
4433
>
45-
<template #default>
46-
<div class="storage-alert">
47-
<p>{{ $tr('uploadSize', { size: formatFileSize(totalUploadSize) }) }}</p>
48-
<p>
49-
{{ $tr('remainingStorage', { size: formatFileSize(availableSpace) }) }}
50-
</p>
51-
<div class="storage-usage">
52-
<FileStorage />
53-
</div>
34+
<p>{{ unsupportedFilesText }}</p>
35+
</KModal>
36+
<KModal
37+
v-if="showTooLargeFilesAlert"
38+
:title="$tr('tooLargeFilesHeader')"
39+
:submitText="$tr('closeButtonLabel')"
40+
@submit="
41+
showTooLargeFilesAlert = false;
42+
resetFileInput();
43+
"
44+
>
45+
<p>
46+
{{
47+
$tr('maxFileSizeText', {
48+
count: tooLargeFiles.length,
49+
size: formatFileSize(maxFileSize),
50+
})
51+
}}
52+
</p>
53+
</KModal>
54+
<KModal
55+
v-if="showStorageExceededAlert"
56+
:title="$tr('noStorageHeader')"
57+
:submitText="$tr('closeButtonLabel')"
58+
@submit="
59+
showStorageExceededAlert = false;
60+
resetFileInput();
61+
"
62+
>
63+
<div class="storage-alert">
64+
<p>{{ $tr('uploadSize', { size: formatFileSize(totalUploadSize) }) }}</p>
65+
<p>
66+
{{ $tr('remainingStorage', { size: formatFileSize(availableSpace) }) }}
67+
</p>
68+
<div
69+
class="storage-usage"
70+
:style="{ color: $themeTokens.annotation }"
71+
>
72+
<FileStorage />
5473
</div>
55-
</template>
56-
</Alert>
74+
</div>
75+
</KModal>
5776
</div>
5877

5978
</template>
@@ -67,19 +86,16 @@
6786
import uniq from 'lodash/uniq';
6887
import flatMap from 'lodash/flatMap';
6988
import isFunction from 'lodash/isFunction';
70-
7189
import { validateFile } from '../../vuex/file/validation';
7290
import FileStorage from './FileStorage';
7391
import FileDropzone from './FileDropzone';
7492
import { MAX_FILE_SIZE } from 'shared/constants';
7593
import { fileSizeMixin } from 'shared/mixins';
76-
import Alert from 'shared/views/Alert';
7794
import { FormatPresetsList } from 'shared/leUtils/FormatPresets';
7895
7996
export default {
8097
name: 'Uploader',
8198
components: {
82-
Alert,
8399
FileStorage,
84100
FileDropzone,
85101
},
@@ -248,6 +264,9 @@
248264
return fileUploads.filter(Boolean);
249265
});
250266
},
267+
resetFileInput() {
268+
this.$refs.fileUpload.value = '';
269+
},
251270
},
252271
$trs: {
253272
unsupportedFilesHeader: 'Unsupported files',
@@ -260,6 +279,7 @@
260279
tooLargeFilesHeader: 'Max file size exceeded',
261280
maxFileSizeText:
262281
'{count, plural,\n =1 {# file will not be uploaded.}\n other {# files will not be uploaded.}} File size must be under {size}',
282+
closeButtonLabel: 'OK',
263283
},
264284
};
265285
@@ -275,7 +295,6 @@
275295
.storage-usage {
276296
margin-top: -5px;
277297
font-size: 10pt;
278-
color: gray;
279298
}
280299
281300
</style>

0 commit comments

Comments
 (0)