From 0fbf43af538835fa88fb00a361f6de3b5db53e3a Mon Sep 17 00:00:00 2001 From: senderfm Date: Wed, 10 Jul 2019 13:30:05 +0200 Subject: [PATCH] lint ok, specs for too long and too short content and title --- .../ContributionForm/ContributionForm.spec.js | 55 +++++++++++++++++-- .../ContributionForm/ContributionForm.vue | 7 +-- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/webapp/components/ContributionForm/ContributionForm.spec.js b/webapp/components/ContributionForm/ContributionForm.spec.js index 3efc7dd6d..c3a50c883 100644 --- a/webapp/components/ContributionForm/ContributionForm.spec.js +++ b/webapp/components/ContributionForm/ContributionForm.spec.js @@ -24,7 +24,17 @@ describe('ContributionForm.vue', () => { let mocks let propsData const postTitle = 'this is a title for a post' + const postTitleTooShort = '12' + let postTitleTooLong = '' + for (let i = 0; i < 100; i++) { + postTitleTooLong += 'x' + } const postContent = 'this is a post' + const postContentTooShort = '12' + let postContentTooLong = '' + for (let i = 0; i < 2001; i++) { + postContentTooLong += 'x' + } const imageUpload = { file: { filename: 'avataar.svg', @@ -109,15 +119,52 @@ describe('ContributionForm.vue', () => { }) describe('invalid form submission', () => { - it('title required for form submission', async () => { + it('title and content should not be empty ', async () => { + await wrapper.find('form').trigger('submit') + expect(mocks.$apollo.mutate).not.toHaveBeenCalled() + }) + + it('title should not be empty', async () => { + wrapper.vm.updateEditorContent(postContent) + await wrapper.find('form').trigger('submit') + expect(mocks.$apollo.mutate).not.toHaveBeenCalled() + }) + + it('title should not be too long', async () => { + postTitleInput = wrapper.find('.ds-input') + postTitleInput.setValue(postTitleTooLong) + wrapper.vm.updateEditorContent(postContent) + await wrapper.find('form').trigger('submit') + expect(mocks.$apollo.mutate).not.toHaveBeenCalled() + }) + + it('title should not be too short', async () => { + postTitleInput = wrapper.find('.ds-input') + postTitleInput.setValue(postTitleTooShort) + wrapper.vm.updateEditorContent(postContent) + await wrapper.find('form').trigger('submit') + expect(mocks.$apollo.mutate).not.toHaveBeenCalled() + }) + + it('content should not be empty', async () => { postTitleInput = wrapper.find('.ds-input') postTitleInput.setValue(postTitle) await wrapper.find('form').trigger('submit') expect(mocks.$apollo.mutate).not.toHaveBeenCalled() }) - it('content required for form submission', async () => { - wrapper.vm.updateEditorContent(postContent) + it('content should not be too long', async () => { + postTitleInput = wrapper.find('.ds-input') + postTitleInput.setValue(postTitle) + wrapper.vm.updateEditorContent(postContentTooLong) + await wrapper.find('form').trigger('submit') + expect(mocks.$apollo.mutate).not.toHaveBeenCalled() + }) + + it('content should not be too short', async () => { + postTitleInput = wrapper.find('.ds-input') + postTitleInput.setValue(postTitle) + wrapper.vm.updateEditorContent(postContentTooShort) await wrapper.find('form').trigger('submit') expect(mocks.$apollo.mutate).not.toHaveBeenCalled() }) @@ -187,7 +234,7 @@ describe('ContributionForm.vue', () => { it('calls $router.back() when cancel button clicked', () => { cancelBtn = wrapper.find('.cancel-button') cancelBtn.trigger('click') - expect(mocks.$router.back).toHaveBeenCalledTimes(0) + expect(mocks.$router.back).toHaveBeenCalledTimes(1) }) }) diff --git a/webapp/components/ContributionForm/ContributionForm.vue b/webapp/components/ContributionForm/ContributionForm.vue index 8b4aa6b9e..7fe9d6e55 100644 --- a/webapp/components/ContributionForm/ContributionForm.vue +++ b/webapp/components/ContributionForm/ContributionForm.vue @@ -43,7 +43,7 @@
{{ $t('actions.cancel') }} @@ -100,11 +100,8 @@ export default { disabled: true, slug: null, users: [], -<<<<<<< HEAD hashtags: [], -======= n: 0, ->>>>>>> maximum number of characters in content without html tags is 2000, characters are counted and number is displayed. regex is strongly shortened. } }, watch: { @@ -185,7 +182,7 @@ export default { this.n = value.replace(/<\/?[^>]+(>|$)/gm, '').length this.form.contentLength = this.n - if (this.n > 3 && this.n < 2000) { + if (this.n > this.formSchema.content.min && this.n < this.formSchema.content.max) { this.disabled = false } },