mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Start writing component test
- restructured directories
This commit is contained in:
parent
40f5b6acd5
commit
957d894322
74
webapp/components/comments/CommentForm/CommentForm.test.js
Normal file
74
webapp/components/comments/CommentForm/CommentForm.test.js
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
import { config, mount, createLocalVue } from '@vue/test-utils'
|
||||||
|
import CommentForm from './index.vue'
|
||||||
|
import Vue from 'vue'
|
||||||
|
import Styleguide from '@human-connection/styleguide'
|
||||||
|
|
||||||
|
const localVue = createLocalVue()
|
||||||
|
|
||||||
|
localVue.use(Styleguide)
|
||||||
|
|
||||||
|
config.stubs['no-ssr'] = '<span><slot /></span>'
|
||||||
|
|
||||||
|
describe('CommentForm.vue', () => {
|
||||||
|
let mocks
|
||||||
|
let wrapper
|
||||||
|
let form
|
||||||
|
let propsData
|
||||||
|
let submitBtn
|
||||||
|
let cancelBtn
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mocks = {
|
||||||
|
$t: jest.fn(),
|
||||||
|
$apollo: {
|
||||||
|
mutate: jest
|
||||||
|
.fn()
|
||||||
|
.mockRejectedValue({ message: 'Ouch!' })
|
||||||
|
.mockResolvedValueOnce({ data: { CreateComment: { contentExcerpt: 'this is a comment' } } })
|
||||||
|
},
|
||||||
|
$toast: {
|
||||||
|
error: jest.fn(),
|
||||||
|
success: jest.fn()
|
||||||
|
},
|
||||||
|
$root: {
|
||||||
|
$emit: jest.fn()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
propsData = {
|
||||||
|
post: { id: 1 }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('mount', () => {
|
||||||
|
const Wrapper = () => {
|
||||||
|
return mount(CommentForm, { mocks, localVue, propsData })
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper = Wrapper()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('calls the apollo mutation when form is submitted', () => {
|
||||||
|
wrapper.vm.updateEditorContent('ok')
|
||||||
|
form = wrapper.find('form')
|
||||||
|
form.trigger('submit')
|
||||||
|
expect(mocks.$apollo.mutate).toHaveBeenCalledTimes(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls clear method when the cancel button is clicked", () => {
|
||||||
|
const spy = jest.spyOn(wrapper.vm, 'clear')
|
||||||
|
wrapper.vm.updateEditorContent('ok')
|
||||||
|
cancelBtn = wrapper.find('.cancelBtn')
|
||||||
|
cancelBtn.trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledTimes(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shows a success toaster if the mutation resolves', () => {
|
||||||
|
wrapper.vm.updateEditorContent('ok')
|
||||||
|
form = wrapper.find('form')
|
||||||
|
form.trigger('submit')
|
||||||
|
expect(mocks.$root.$emit).toHaveBeenCalledTimes(1)
|
||||||
|
expect(mocks.$toast.success).toHaveBeenCalledTimes(1)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@ -21,6 +21,7 @@
|
|||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
ghost
|
ghost
|
||||||
@click.prevent="clear"
|
@click.prevent="clear"
|
||||||
|
class="cancelBtn"
|
||||||
>
|
>
|
||||||
{{ $t('actions.cancel') }}
|
{{ $t('actions.cancel') }}
|
||||||
</ds-button>
|
</ds-button>
|
||||||
@ -91,6 +92,7 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
|
// console.log(this.$toast.success.mockResolvedValue())
|
||||||
this.$root.$emit('addComment', res.data.CreateComment)
|
this.$root.$emit('addComment', res.data.CreateComment)
|
||||||
this.$refs.editor.clear()
|
this.$refs.editor.clear()
|
||||||
this.$toast.success(this.$t('post.comment.submitted'))
|
this.$toast.success(this.$t('post.comment.submitted'))
|
||||||
@ -5,7 +5,6 @@ export default app => {
|
|||||||
return gql(`
|
return gql(`
|
||||||
query Post($slug: String!) {
|
query Post($slug: String!) {
|
||||||
Post(slug: $slug) {
|
Post(slug: $slug) {
|
||||||
commentsCount
|
|
||||||
comments(orderBy: createdAt_asc) {
|
comments(orderBy: createdAt_asc) {
|
||||||
id
|
id
|
||||||
contentExcerpt
|
contentExcerpt
|
||||||
|
|||||||
@ -112,8 +112,8 @@ import HcTag from '~/components/Tag'
|
|||||||
import ContentMenu from '~/components/ContentMenu'
|
import ContentMenu from '~/components/ContentMenu'
|
||||||
import HcUser from '~/components/User'
|
import HcUser from '~/components/User'
|
||||||
import HcShoutButton from '~/components/ShoutButton.vue'
|
import HcShoutButton from '~/components/ShoutButton.vue'
|
||||||
import HcCommentForm from '~/components/CommentForm'
|
import HcCommentForm from '~/components/comments/CommentForm'
|
||||||
import HcCommentList from '~/components/CommentList'
|
import HcCommentList from '~/components/comments/CommentList'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
transition: {
|
transition: {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user