From 7796483a469160bfaec9a68a1ff0e7b102fd326c Mon Sep 17 00:00:00 2001 From: Matt Rider Date: Mon, 24 Jun 2019 12:45:53 -0300 Subject: [PATCH] Add test for upload error, update variable name --- .../ContributionForm/ContributionForm.spec.js | 21 +++++++++++++++++++ webapp/components/ContributionForm/index.vue | 6 +++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/webapp/components/ContributionForm/ContributionForm.spec.js b/webapp/components/ContributionForm/ContributionForm.spec.js index 2275193df..5da3bdf04 100644 --- a/webapp/components/ContributionForm/ContributionForm.spec.js +++ b/webapp/components/ContributionForm/ContributionForm.spec.js @@ -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) + }) }) }) }) diff --git a/webapp/components/ContributionForm/index.vue b/webapp/components/ContributionForm/index.vue index e052860f0..f2a30a51a 100644 --- a/webapp/components/ContributionForm/index.vue +++ b/webapp/components/ContributionForm/index.vue @@ -14,14 +14,14 @@
@@ -113,7 +113,7 @@ export default { previewTemplate: this.template(), }, error: false, - createOrUpdate: true, + createAndUpdate: true, } }, watch: {