Update component tests for categories

This commit is contained in:
Matt Rider 2019-06-26 18:21:12 -03:00
parent 07576d084c
commit bb40e9d432

View File

@ -3,6 +3,7 @@ import ContributionForm from './index.vue'
import Styleguide from '@human-connection/styleguide'
import Vuex from 'vuex'
import PostMutations from '~/graphql/PostMutations.js'
import CategoriesSelect from '~/components/CategoriesSelect/CategoriesSelect'
const localVue = createLocalVue()
@ -100,7 +101,13 @@ describe('ContributionForm.vue', () => {
beforeEach(async () => {
expectedParams = {
mutation: PostMutations().CreatePost,
variables: { title: postTitle, content: postContent, language: 'en', id: null },
variables: {
title: postTitle,
content: postContent,
language: 'en',
id: null,
categories: null,
},
}
postTitleInput = wrapper.find('.ds-input')
postTitleInput.setValue(postTitle)
@ -124,6 +131,14 @@ describe('ContributionForm.vue', () => {
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams))
})
it('supports adding categories', async () => {
const categories = ['cat12', 'cat15', 'cat37']
expectedParams.variables.categories = categories
wrapper.find(CategoriesSelect).vm.$emit('updateCategories', categories)
await wrapper.find('form').trigger('submit')
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams))
})
it("pushes the user to the post's page", async () => {
expect(mocks.$router.push).toHaveBeenCalledTimes(1)
})
@ -200,6 +215,7 @@ describe('ContributionForm.vue', () => {
content: postContent,
language: propsData.contribution.language,
id: propsData.contribution.id,
categories: null,
},
}
postTitleInput = wrapper.find('.ds-input')