lint ok, specs for too long and too short content and title

This commit is contained in:
senderfm 2019-07-10 13:30:05 +02:00 committed by Matt Rider
parent 0dd600746a
commit 0fbf43af53
2 changed files with 53 additions and 9 deletions

View File

@ -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)
})
})

View File

@ -43,7 +43,7 @@
<div slot="footer" style="text-align: right">
<ds-button
class="cancel-button"
:disabled="loading || disabled"
:disabled="loading"
ghost
@click.prevent="$router.back()"
>{{ $t('actions.cancel') }}</ds-button>
@ -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
}
},