Added the user that writes the comment to the authentication. Test reply to comment edited. Test update comment added. Test delete comment pending.

This commit is contained in:
Hannes Heine 2020-08-11 16:01:42 +02:00
parent 34ba9d8c0b
commit 823056b59e

View File

@ -1,6 +1,5 @@
import { config, mount } from '@vue/test-utils' import { config, mount } from '@vue/test-utils'
import CommentList from './CommentList' import CommentList from './CommentList'
import CommentCard from '~/components/CommentCard/CommentCard'
import Vuex from 'vuex' import Vuex from 'vuex'
import Vue from 'vue' import Vue from 'vue'
@ -26,7 +25,10 @@ describe('CommentList.vue', () => {
id: 'comment134', id: 'comment134',
contentExcerpt: 'this is a comment', contentExcerpt: 'this is a comment',
content: 'this is a comment', content: 'this is a comment',
author: { id: 'some-user' }, author: {
id: 'some-user',
slug: 'some-slug',
},
}, },
{ {
id: 'comment135', id: 'comment135',
@ -49,7 +51,7 @@ describe('CommentList.vue', () => {
getters: { getters: {
'auth/isModerator': () => false, 'auth/isModerator': () => false,
'auth/user': () => { 'auth/user': () => {
return {} return { id: 'some-user' }
}, },
}, },
}) })
@ -115,26 +117,63 @@ describe('CommentList.vue', () => {
}) })
}) })
describe('Comment', () => { describe('Respond to Comment', () => {
beforeEach(() => { beforeEach(() => {
wrapper = Wrapper() wrapper = Wrapper()
}) })
it('Comment emitted reply()', () => { it('emits reply to comment', () => {
wrapper.find(CommentCard).vm.$emit('reply', { wrapper.find('.reply-button').trigger('click')
id: 'commentAuthorId',
slug: 'ogerly',
})
Vue.nextTick()
expect(wrapper.emitted('reply')).toEqual([ expect(wrapper.emitted('reply')).toEqual([
[ [
{ {
id: 'commentAuthorId', id: 'some-user',
slug: 'ogerly', slug: 'some-slug',
}, },
], ],
]) ])
}) })
}) })
describe('edit Comment', () => {
beforeEach(() => {
wrapper = Wrapper()
})
it('updates comment after edit', () => {
wrapper.vm.updateCommentList({
id: 'comment134',
contentExcerpt: 'this is an edited comment',
content: 'this is an edited comment',
author: {
id: 'some-user',
slug: 'some-slug',
},
})
expect(wrapper.props('post').comments[0].content).toEqual('this is an edited comment')
})
})
describe('delete Comment', () => {
beforeEach(() => {
wrapper = Wrapper()
})
// TODO: Test does not find .count = 0 but 1. Can't understand why...
it.skip('sets counter to 0', async () => {
wrapper.vm.updateCommentList({
id: 'comment134',
contentExcerpt: 'this is another deleted comment',
content: 'this is an another deleted comment',
deleted: true,
author: {
id: 'some-user',
slug: 'some-slug',
},
})
await Vue.nextTick()
await expect(wrapper.find('.count').text()).toEqual('0')
})
})
}) })
}) })