mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Delete CommentForm.test.js, remove console.log
- this test is not part of this PR and I'll create another issue and put in a different PR for it
This commit is contained in:
parent
957d894322
commit
ebc290c6af
@ -1,74 +0,0 @@
|
|||||||
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)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@ -20,8 +20,8 @@
|
|||||||
<ds-button
|
<ds-button
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
ghost
|
ghost
|
||||||
@click.prevent="clear"
|
|
||||||
class="cancelBtn"
|
class="cancelBtn"
|
||||||
|
@click.prevent="clear"
|
||||||
>
|
>
|
||||||
{{ $t('actions.cancel') }}
|
{{ $t('actions.cancel') }}
|
||||||
</ds-button>
|
</ds-button>
|
||||||
@ -92,7 +92,6 @@ 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'))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user