diff --git a/js/components/__tests__/upload_input.test.js b/js/components/__tests__/upload_input.test.js index c867eea3..c2853cc7 100644 --- a/js/components/__tests__/upload_input.test.js +++ b/js/components/__tests__/upload_input.test.js @@ -8,7 +8,8 @@ const UploadWrapper = makeTestWrapper({ components: { uploadinput }, templatePath: 'upload_input_template.html', data: function() { - return { initialvalue: this.initialData.initialvalue, token: this.token } + const { filename, objectName } = this.initialData + return { filename, objectName } }, }) @@ -16,7 +17,7 @@ const UploadErrorWrapper = makeTestWrapper({ components: { uploadinput }, templatePath: 'upload_input_error_template.html', data: function() { - return { initialvalue: null, token: null } + return { filename: null, objectName: null } }, }) @@ -24,7 +25,7 @@ describe('UploadInput Test', () => { it('should show input and button when no attachment present', () => { const wrapper = mount(UploadWrapper, { propsData: { - initialData: { initialvalue: null, token: 'token' }, + initialData: {}, }, }) @@ -35,21 +36,24 @@ describe('UploadInput Test', () => { it('should show file name and hide input', () => { const wrapper = mount(UploadWrapper, { propsData: { - initialData: { initialvalue: 'somepdf.pdf', token: 'token' }, + initialData: { + filename: 'somepdf.pdf', + objectName: 'abcd', + }, }, }) const fileInput = wrapper.find('input[type=file]').element - const fileNameSpan = wrapper.find('.uploaded-file__name') + const fileNameLink = wrapper.find('.uploaded-file__name') expect(fileInput).toBe(undefined) - expect(fileNameSpan.html()).toContain('somepdf.pdf') + expect(fileNameLink.html()).toContain('somepdf.pdf') }) it('should correctly display error treatment', () => { const wrapper = mount(UploadErrorWrapper, { propsData: { - initialData: { initialvalue: 'somepdf.pdf', token: 'token' }, + initialData: { initialvalue: 'somepdf.pdf', objectName: 'abcd' }, }, }) diff --git a/js/components/upload_input.js b/js/components/upload_input.js index 394c0057..b4927d1b 100644 --- a/js/components/upload_input.js +++ b/js/components/upload_input.js @@ -17,8 +17,11 @@ export default { props: { name: String, - initialData: { - type: Object, + filename: { + type: String, + }, + objectName: { + type: String, }, initialErrors: { type: Boolean, @@ -38,8 +41,8 @@ export default { data: function() { return { - hasInitialData: !!this.initialData, - attachment: this.initialData.filename || null, + hasInitialData: false, + attachment: this.filename || null, changed: false, uploadError: false, sizeError: false, @@ -54,9 +57,12 @@ export default { valid: this.hasAttachment, }) + this.hasInitialData = !!this.filename if (this.hasInitialData) { - const { filename, objectName } = this.initialData - this.downloadLink = await this.getDownloadLink(filename, objectName) + this.downloadLink = await this.getDownloadLink( + this.filename, + this.objectName + ) } }, diff --git a/js/test_templates/upload_input_error_template.html b/js/test_templates/upload_input_error_template.html index 50c1c3ab..ff3676ab 100644 --- a/js/test_templates/upload_input_error_template.html +++ b/js/test_templates/upload_input_error_template.html @@ -13,7 +13,7 @@ - + Remove