mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Fix tests
This commit is contained in:
parent
62b393b0f0
commit
a2dbe47f1f
@ -8,10 +8,12 @@ localVue.use(Styleguide)
|
|||||||
describe('CategoriesSelect.vue', () => {
|
describe('CategoriesSelect.vue', () => {
|
||||||
let wrapper
|
let wrapper
|
||||||
let mocks
|
let mocks
|
||||||
|
let provide
|
||||||
let democracyAndPolitics
|
let democracyAndPolitics
|
||||||
let environmentAndNature
|
let environmentAndNature
|
||||||
let consumptionAndSustainablity
|
let consumptionAndSustainablity
|
||||||
|
|
||||||
|
const propsData = { model: 'categoryIds' }
|
||||||
const categories = [
|
const categories = [
|
||||||
{
|
{
|
||||||
id: 'cat9',
|
id: 'cat9',
|
||||||
@ -35,6 +37,11 @@ describe('CategoriesSelect.vue', () => {
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
provide = {
|
||||||
|
$parentForm: {
|
||||||
|
update: jest.fn(),
|
||||||
|
},
|
||||||
|
}
|
||||||
mocks = {
|
mocks = {
|
||||||
$t: jest.fn(),
|
$t: jest.fn(),
|
||||||
}
|
}
|
||||||
@ -42,7 +49,7 @@ describe('CategoriesSelect.vue', () => {
|
|||||||
|
|
||||||
describe('shallowMount', () => {
|
describe('shallowMount', () => {
|
||||||
const Wrapper = () => {
|
const Wrapper = () => {
|
||||||
return mount(CategoriesSelect, { mocks, localVue })
|
return mount(CategoriesSelect, { propsData, mocks, localVue, provide })
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@ -60,8 +67,8 @@ describe('CategoriesSelect.vue', () => {
|
|||||||
expect(wrapper.vm.selectedCategoryIds).toEqual([categories[0].id])
|
expect(wrapper.vm.selectedCategoryIds).toEqual([categories[0].id])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('emits an updateCategories event when the selectedCategoryIds changes', () => {
|
it('calls $parent.update with selected category ids', () => {
|
||||||
expect(wrapper.emitted().updateCategories[0][0]).toEqual([categories[0].id])
|
expect(provide.$parentForm.update).toHaveBeenCalledWith('categoryIds', ['cat9'])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('removes categories when clicked a second time', () => {
|
it('removes categories when clicked a second time', () => {
|
||||||
|
|||||||
@ -20,6 +20,34 @@ config.stubs['client-only'] = '<span><slot /></span>'
|
|||||||
config.stubs['nuxt-link'] = '<span><slot /></span>'
|
config.stubs['nuxt-link'] = '<span><slot /></span>'
|
||||||
config.stubs['v-popover'] = '<span><slot /></span>'
|
config.stubs['v-popover'] = '<span><slot /></span>'
|
||||||
|
|
||||||
|
const categories = [
|
||||||
|
{
|
||||||
|
"id": "cat3",
|
||||||
|
"slug": "health-wellbeing",
|
||||||
|
"icon": "medkit"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "cat12",
|
||||||
|
"slug": "it-internet-data-privacy",
|
||||||
|
"icon": "mouse-pointer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "cat9",
|
||||||
|
"slug": "democracy-politics",
|
||||||
|
"icon": "university"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "cat15",
|
||||||
|
"slug": "consumption-sustainability",
|
||||||
|
"icon": "shopping-cart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "cat4",
|
||||||
|
"slug": "environment-nature",
|
||||||
|
"icon": "tree"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
describe('ContributionForm.vue', () => {
|
describe('ContributionForm.vue', () => {
|
||||||
let wrapper
|
let wrapper
|
||||||
let postTitleInput
|
let postTitleInput
|
||||||
@ -130,13 +158,13 @@ describe('ContributionForm.vue', () => {
|
|||||||
|
|
||||||
describe('invalid form submission', () => {
|
describe('invalid form submission', () => {
|
||||||
it('title and content should not be empty ', async () => {
|
it('title and content should not be empty ', async () => {
|
||||||
wrapper.find('.submit-button-for-test').trigger('click')
|
wrapper.find('form').trigger('submit')
|
||||||
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('title should not be empty', async () => {
|
it('title should not be empty', async () => {
|
||||||
await wrapper.vm.updateEditorContent(postContent)
|
await wrapper.vm.updateEditorContent(postContent)
|
||||||
wrapper.find('.submit-button-for-test').trigger('click')
|
wrapper.find('form').trigger('submit')
|
||||||
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -144,7 +172,7 @@ describe('ContributionForm.vue', () => {
|
|||||||
postTitleInput = wrapper.find('.ds-input')
|
postTitleInput = wrapper.find('.ds-input')
|
||||||
postTitleInput.setValue(postTitleTooLong)
|
postTitleInput.setValue(postTitleTooLong)
|
||||||
await wrapper.vm.updateEditorContent(postContent)
|
await wrapper.vm.updateEditorContent(postContent)
|
||||||
wrapper.find('.submit-button-for-test').trigger('click')
|
wrapper.find('form').trigger('submit')
|
||||||
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -152,14 +180,14 @@ describe('ContributionForm.vue', () => {
|
|||||||
postTitleInput = wrapper.find('.ds-input')
|
postTitleInput = wrapper.find('.ds-input')
|
||||||
postTitleInput.setValue(postTitleTooShort)
|
postTitleInput.setValue(postTitleTooShort)
|
||||||
await wrapper.vm.updateEditorContent(postContent)
|
await wrapper.vm.updateEditorContent(postContent)
|
||||||
wrapper.find('.submit-button-for-test').trigger('click')
|
wrapper.find('form').trigger('submit')
|
||||||
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('content should not be empty', async () => {
|
it('content should not be empty', async () => {
|
||||||
postTitleInput = wrapper.find('.ds-input')
|
postTitleInput = wrapper.find('.ds-input')
|
||||||
postTitleInput.setValue(postTitle)
|
postTitleInput.setValue(postTitle)
|
||||||
await wrapper.find('.submit-button-for-test').trigger('click')
|
await wrapper.find('form').trigger('submit')
|
||||||
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -167,7 +195,7 @@ describe('ContributionForm.vue', () => {
|
|||||||
postTitleInput = wrapper.find('.ds-input')
|
postTitleInput = wrapper.find('.ds-input')
|
||||||
postTitleInput.setValue(postTitle)
|
postTitleInput.setValue(postTitle)
|
||||||
await wrapper.vm.updateEditorContent(postContentTooShort)
|
await wrapper.vm.updateEditorContent(postContentTooShort)
|
||||||
wrapper.find('.submit-button-for-test').trigger('click')
|
wrapper.find('form').trigger('submit')
|
||||||
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -175,7 +203,7 @@ describe('ContributionForm.vue', () => {
|
|||||||
postTitleInput = wrapper.find('.ds-input')
|
postTitleInput = wrapper.find('.ds-input')
|
||||||
postTitleInput.setValue(postTitle)
|
postTitleInput.setValue(postTitle)
|
||||||
await wrapper.vm.updateEditorContent(postContentTooLong)
|
await wrapper.vm.updateEditorContent(postContentTooLong)
|
||||||
wrapper.find('.submit-button-for-test').trigger('click')
|
wrapper.find('form').trigger('submit')
|
||||||
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -183,7 +211,7 @@ describe('ContributionForm.vue', () => {
|
|||||||
postTitleInput = wrapper.find('.ds-input')
|
postTitleInput = wrapper.find('.ds-input')
|
||||||
postTitleInput.setValue(postTitle)
|
postTitleInput.setValue(postTitle)
|
||||||
await wrapper.vm.updateEditorContent(postContent)
|
await wrapper.vm.updateEditorContent(postContent)
|
||||||
wrapper.find('.submit-button-for-test').trigger('click')
|
wrapper.find('form').trigger('submit')
|
||||||
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -192,7 +220,7 @@ describe('ContributionForm.vue', () => {
|
|||||||
postTitleInput.setValue(postTitle)
|
postTitleInput.setValue(postTitle)
|
||||||
await wrapper.vm.updateEditorContent(postContent)
|
await wrapper.vm.updateEditorContent(postContent)
|
||||||
wrapper.vm.form.categoryIds = ['cat4', 'cat9', 'cat15', 'cat27']
|
wrapper.vm.form.categoryIds = ['cat4', 'cat9', 'cat15', 'cat27']
|
||||||
wrapper.find('.submit-button-for-test').trigger('click')
|
wrapper.find('form').trigger('submit')
|
||||||
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -214,17 +242,17 @@ describe('ContributionForm.vue', () => {
|
|||||||
postTitleInput = wrapper.find('.ds-input')
|
postTitleInput = wrapper.find('.ds-input')
|
||||||
postTitleInput.setValue(postTitle)
|
postTitleInput.setValue(postTitle)
|
||||||
await wrapper.vm.updateEditorContent(postContent)
|
await wrapper.vm.updateEditorContent(postContent)
|
||||||
categoryIds = ['cat12']
|
wrapper.find(CategoriesSelect).setData({categories})
|
||||||
wrapper.find(CategoriesSelect).vm.$emit('updateCategories', categoryIds)
|
await wrapper.find(CategoriesSelect).findAll('button').at(1).trigger('click')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('creates a post with valid title, content, and at least one category', async () => {
|
it('creates a post with valid title, content, and at least one category', async () => {
|
||||||
await wrapper.find('.submit-button-for-test').trigger('click')
|
await wrapper.find('form').trigger('submit')
|
||||||
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams))
|
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams))
|
||||||
})
|
})
|
||||||
|
|
||||||
it("sends a fallback language based on a user's locale", () => {
|
it("sends a fallback language based on a user's locale", () => {
|
||||||
wrapper.find('.submit-button-for-test').trigger('click')
|
wrapper.find('form').trigger('submit')
|
||||||
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams))
|
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams))
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -232,25 +260,25 @@ describe('ContributionForm.vue', () => {
|
|||||||
expectedParams.variables.language = 'de'
|
expectedParams.variables.language = 'de'
|
||||||
deutschOption = wrapper.findAll('li').at(0)
|
deutschOption = wrapper.findAll('li').at(0)
|
||||||
deutschOption.trigger('click')
|
deutschOption.trigger('click')
|
||||||
wrapper.find('.submit-button-for-test').trigger('click')
|
wrapper.find('form').trigger('submit')
|
||||||
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams))
|
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('supports adding a teaser image', async () => {
|
it('supports adding a teaser image', async () => {
|
||||||
expectedParams.variables.imageUpload = imageUpload
|
expectedParams.variables.imageUpload = imageUpload
|
||||||
wrapper.find(TeaserImage).vm.$emit('addTeaserImage', imageUpload)
|
wrapper.find(TeaserImage).vm.$emit('addTeaserImage', imageUpload)
|
||||||
await wrapper.find('.submit-button-for-test').trigger('click')
|
await wrapper.find('form').trigger('submit')
|
||||||
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams))
|
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams))
|
||||||
})
|
})
|
||||||
|
|
||||||
it("pushes the user to the post's page", async () => {
|
it("pushes the user to the post's page", async () => {
|
||||||
wrapper.find('.submit-button-for-test').trigger('click')
|
wrapper.find('form').trigger('submit')
|
||||||
await mocks.$apollo.mutate
|
await mocks.$apollo.mutate
|
||||||
expect(mocks.$router.push).toHaveBeenCalledTimes(1)
|
expect(mocks.$router.push).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shows a success toaster', async () => {
|
it('shows a success toaster', async () => {
|
||||||
wrapper.find('.submit-button-for-test').trigger('click')
|
wrapper.find('form').trigger('submit')
|
||||||
await mocks.$apollo.mutate
|
await mocks.$apollo.mutate
|
||||||
expect(mocks.$toast.success).toHaveBeenCalledTimes(1)
|
expect(mocks.$toast.success).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
@ -275,11 +303,12 @@ describe('ContributionForm.vue', () => {
|
|||||||
postTitleInput.setValue(postTitle)
|
postTitleInput.setValue(postTitle)
|
||||||
await wrapper.vm.updateEditorContent(postContent)
|
await wrapper.vm.updateEditorContent(postContent)
|
||||||
categoryIds = ['cat12']
|
categoryIds = ['cat12']
|
||||||
wrapper.find(CategoriesSelect).vm.$emit('updateCategories', categoryIds)
|
wrapper.find(CategoriesSelect).setData({categories})
|
||||||
|
await wrapper.find(CategoriesSelect).findAll('button').at(1).trigger('click')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shows an error toaster when apollo mutation rejects', async () => {
|
it('shows an error toaster when apollo mutation rejects', async () => {
|
||||||
await wrapper.find('.submit-button-for-test').trigger('click')
|
await wrapper.find('form').trigger('submit')
|
||||||
await mocks.$apollo.mutate
|
await mocks.$apollo.mutate
|
||||||
await expect(mocks.$toast.error).toHaveBeenCalledWith('Not Authorised!')
|
await expect(mocks.$toast.error).toHaveBeenCalledWith('Not Authorised!')
|
||||||
})
|
})
|
||||||
@ -345,7 +374,7 @@ describe('ContributionForm.vue', () => {
|
|||||||
content: postContent,
|
content: postContent,
|
||||||
language: propsData.contribution.language,
|
language: propsData.contribution.language,
|
||||||
id: propsData.contribution.id,
|
id: propsData.contribution.id,
|
||||||
categoryIds,
|
categoryIds: ['cat12'],
|
||||||
image,
|
image,
|
||||||
imageUpload: null,
|
imageUpload: null,
|
||||||
},
|
},
|
||||||
@ -356,19 +385,20 @@ describe('ContributionForm.vue', () => {
|
|||||||
postTitleInput = wrapper.find('.ds-input')
|
postTitleInput = wrapper.find('.ds-input')
|
||||||
postTitleInput.setValue(postTitle)
|
postTitleInput.setValue(postTitle)
|
||||||
wrapper.vm.updateEditorContent(postContent)
|
wrapper.vm.updateEditorContent(postContent)
|
||||||
wrapper.find(CategoriesSelect).vm.$emit('updateCategories', categoryIds)
|
await wrapper.find('form').trigger('submit')
|
||||||
wrapper.find('.submit-button-for-test').trigger('click')
|
|
||||||
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams))
|
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('supports updating categories', async () => {
|
it('supports updating categories', async () => {
|
||||||
const categoryIds = ['cat3', 'cat51', 'cat37']
|
expectedParams.variables.categoryIds = ['cat12', 'cat3', 'cat15']
|
||||||
postTitleInput = wrapper.find('.ds-input')
|
postTitleInput = wrapper.find('.ds-input')
|
||||||
postTitleInput.setValue(postTitle)
|
postTitleInput.setValue(postTitle)
|
||||||
wrapper.vm.updateEditorContent(postContent)
|
wrapper.vm.updateEditorContent(postContent)
|
||||||
expectedParams.variables.categoryIds = categoryIds
|
wrapper.find(CategoriesSelect).setData({categories})
|
||||||
wrapper.find(CategoriesSelect).vm.$emit('updateCategories', categoryIds)
|
await wrapper.find(CategoriesSelect).findAll('button').at(0).trigger('click')
|
||||||
await wrapper.find('.submit-button-for-test').trigger('click')
|
await wrapper.find(CategoriesSelect).findAll('button').at(3).trigger('click')
|
||||||
|
await wrapper.find(CategoriesSelect).findAll('button').at(4).trigger('click')
|
||||||
|
await wrapper.find('form').trigger('submit')
|
||||||
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams))
|
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<ds-form ref="contributionForm" v-model="form" :schema="formSchema">
|
<ds-form ref="contributionForm" v-model="form" :schema="formSchema" @submit="submit">
|
||||||
<template slot-scope="{ errors }">
|
<template slot-scope="{ errors }">
|
||||||
<hc-teaser-image :contribution="contribution" @addTeaserImage="addTeaserImage">
|
<hc-teaser-image :contribution="contribution" @addTeaserImage="addTeaserImage">
|
||||||
<img
|
<img
|
||||||
@ -78,13 +78,11 @@
|
|||||||
{{ $t('actions.cancel') }}
|
{{ $t('actions.cancel') }}
|
||||||
</ds-button>
|
</ds-button>
|
||||||
<ds-button
|
<ds-button
|
||||||
class="submit-button-for-test"
|
|
||||||
type="submit"
|
type="submit"
|
||||||
icon="check"
|
icon="check"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
:disabled="errors"
|
:disabled="errors"
|
||||||
primary
|
primary
|
||||||
@click.prevent="submit"
|
|
||||||
>
|
>
|
||||||
{{ $t('actions.save') }}
|
{{ $t('actions.save') }}
|
||||||
</ds-button>
|
</ds-button>
|
||||||
@ -141,8 +139,8 @@ export default {
|
|||||||
required: true,
|
required: true,
|
||||||
validator: (rule, value) => {
|
validator: (rule, value) => {
|
||||||
const errors = []
|
const errors = []
|
||||||
if (!value || value.length <= 0) {
|
if (!(value && 1 <= value.length && value.length <= 3)) {
|
||||||
errors.push(new Error('Choose at least 1 but at most 3 categories'))
|
errors.push(new Error(this.$t('common.validations.categories')))
|
||||||
}
|
}
|
||||||
return errors
|
return errors
|
||||||
},
|
},
|
||||||
|
|||||||
@ -434,7 +434,8 @@
|
|||||||
"reportContent": "Melden",
|
"reportContent": "Melden",
|
||||||
"validations": {
|
"validations": {
|
||||||
"email": "muss eine gültige E-Mail Adresse sein",
|
"email": "muss eine gültige E-Mail Adresse sein",
|
||||||
"url": "muss eine gültige URL sein"
|
"url": "muss eine gültige URL sein",
|
||||||
|
"categories": "es müssen eine bis drei Kategorien ausgewählt werden"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"actions": {
|
"actions": {
|
||||||
|
|||||||
@ -435,7 +435,8 @@
|
|||||||
"reportContent": "Report",
|
"reportContent": "Report",
|
||||||
"validations": {
|
"validations": {
|
||||||
"email": "must be a valid e-mail address",
|
"email": "must be a valid e-mail address",
|
||||||
"url": "must be a valid URL"
|
"url": "must be a valid URL",
|
||||||
|
"categories": "at least one and at most three categories must be selected"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"actions": {
|
"actions": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user