Add test for upload error, update variable name

This commit is contained in:
Matt Rider 2019-06-24 12:45:53 -03:00
parent aff2b4aaf0
commit 7796483a46
2 changed files with 24 additions and 3 deletions

View File

@ -151,6 +151,7 @@ describe('ContributionForm.vue', () => {
describe('handles errors', () => {
beforeEach(async () => {
jest.useFakeTimers()
wrapper = Wrapper()
postTitleInput = wrapper.find('.ds-input')
postTitleInput.setValue('this is a title for a post')
@ -158,11 +159,31 @@ describe('ContributionForm.vue', () => {
// second submission causes mutation to reject
await wrapper.find('form').trigger('submit')
})
it('shows an error toaster when apollo mutation rejects', async () => {
await wrapper.find('form').trigger('submit')
await mocks.$apollo.mutate
expect(mocks.$toast.error).toHaveBeenCalledWith('Not Authorised!')
})
const message = 'File upload failed'
const fileError = { status: 'error' }
it('defaults to error false', () => {
expect(wrapper.vm.error).toEqual(false)
})
it('shows an error toaster when verror is called', () => {
wrapper.vm.verror(fileError, message)
expect(mocks.$toast.error).toHaveBeenCalledWith(fileError.status, message)
})
it('changes error status from false to true to false', () => {
wrapper.vm.verror(fileError, message)
expect(wrapper.vm.error).toEqual(true)
jest.runAllTimers()
expect(wrapper.vm.error).toEqual(false)
})
})
})
})

View File

@ -14,14 +14,14 @@
<div class="dz-message">
<div
:class="{
'hc-attachments-upload-area-post': createOrUpdate,
'hc-attachments-upload-area-post': createAndUpdate,
'hc-attachments-upload-area-update-post': contribution,
}"
>
<slot></slot>
<div
:class="{
'hc-drag-marker-post': createOrUpdate,
'hc-drag-marker-post': createAndUpdate,
'hc-drag-marker-update-post': contribution,
}"
>
@ -113,7 +113,7 @@ export default {
previewTemplate: this.template(),
},
error: false,
createOrUpdate: true,
createAndUpdate: true,
}
},
watch: {