mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Started writing Jest tests for Deletion of Comments
This commit is contained in:
parent
52a430fc91
commit
b46016203a
@ -1,4 +1,8 @@
|
|||||||
import { config, shallowMount, createLocalVue } from '@vue/test-utils'
|
import {
|
||||||
|
config,
|
||||||
|
shallowMount,
|
||||||
|
createLocalVue
|
||||||
|
} from '@vue/test-utils'
|
||||||
import Comment from './Comment.vue'
|
import Comment from './Comment.vue'
|
||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
import Styleguide from '@human-connection/styleguide'
|
import Styleguide from '@human-connection/styleguide'
|
||||||
@ -14,6 +18,8 @@ describe('Comment.vue', () => {
|
|||||||
let propsData
|
let propsData
|
||||||
let mocks
|
let mocks
|
||||||
let getters
|
let getters
|
||||||
|
let wrapper
|
||||||
|
let Wrapper
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
propsData = {}
|
propsData = {}
|
||||||
@ -29,11 +35,16 @@ describe('Comment.vue', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('shallowMount', () => {
|
describe('shallowMount', () => {
|
||||||
const Wrapper = () => {
|
Wrapper = () => {
|
||||||
const store = new Vuex.Store({
|
const store = new Vuex.Store({
|
||||||
getters,
|
getters,
|
||||||
})
|
})
|
||||||
return shallowMount(Comment, { store, propsData, mocks, localVue })
|
return shallowMount(Comment, {
|
||||||
|
store,
|
||||||
|
propsData,
|
||||||
|
mocks,
|
||||||
|
localVue,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('given a comment', () => {
|
describe('given a comment', () => {
|
||||||
@ -45,7 +56,7 @@ describe('Comment.vue', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('renders content', () => {
|
it('renders content', () => {
|
||||||
const wrapper = Wrapper()
|
wrapper = Wrapper()
|
||||||
expect(wrapper.text()).toMatch('Hello I am a comment content')
|
expect(wrapper.text()).toMatch('Hello I am a comment content')
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -55,19 +66,22 @@ describe('Comment.vue', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('renders no comment data', () => {
|
it('renders no comment data', () => {
|
||||||
const wrapper = Wrapper()
|
wrapper = Wrapper()
|
||||||
expect(wrapper.text()).not.toMatch('comment content')
|
expect(wrapper.text()).not.toMatch('comment content')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has no "disabled-content" css class', () => {
|
it('has no "disabled-content" css class', () => {
|
||||||
const wrapper = Wrapper()
|
wrapper = Wrapper()
|
||||||
expect(wrapper.classes()).not.toContain('disabled-content')
|
expect(wrapper.classes()).not.toContain('disabled-content')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('translates a placeholder', () => {
|
it('translates a placeholder', () => {
|
||||||
/* const wrapper = */ Wrapper()
|
/* const wrapper = */
|
||||||
|
Wrapper()
|
||||||
const calls = mocks.$t.mock.calls
|
const calls = mocks.$t.mock.calls
|
||||||
const expected = [['comment.content.unavailable-placeholder']]
|
const expected = [
|
||||||
|
['comment.content.unavailable-placeholder']
|
||||||
|
]
|
||||||
expect(calls).toEqual(expect.arrayContaining(expected))
|
expect(calls).toEqual(expect.arrayContaining(expected))
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -77,16 +91,50 @@ describe('Comment.vue', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('renders comment data', () => {
|
it('renders comment data', () => {
|
||||||
const wrapper = Wrapper()
|
wrapper = Wrapper()
|
||||||
expect(wrapper.text()).toMatch('comment content')
|
expect(wrapper.text()).toMatch('comment content')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has a "disabled-content" css class', () => {
|
it('has a "disabled-content" css class', () => {
|
||||||
const wrapper = Wrapper()
|
wrapper = Wrapper()
|
||||||
expect(wrapper.classes()).toContain('disabled-content')
|
expect(wrapper.classes()).toContain('disabled-content')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
beforeEach(jest.useFakeTimers)
|
||||||
|
|
||||||
|
describe('test callbacks', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper = Wrapper()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('deletion of Comment from List by invoking "deleteCommentCallback()"', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper.vm.deleteCommentCallback()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('after timeout', () => {
|
||||||
|
beforeEach(jest.runAllTimers)
|
||||||
|
|
||||||
|
it('emits "deleteComment"', () => {
|
||||||
|
expect(wrapper.emitted().deleteComment.length).toBe(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
// it('does not go to index (main) page', () => {
|
||||||
|
// expect(mocks.$router.history.push).not.toHaveBeenCalled()
|
||||||
|
// })
|
||||||
|
|
||||||
|
it('does call mutation', () => {
|
||||||
|
expect(mocks.$apollo.mutate).toHaveBeenCalledTimes(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('mutation is successful', () => {
|
||||||
|
expect(mocks.$toast.success).toHaveBeenCalledTimes(1)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user