test: added some test

This commit is contained in:
ogerly 2020-01-20 11:18:35 +01:00
parent 8edb551c15
commit 73b005a900
7 changed files with 66 additions and 12 deletions

View File

@ -1,4 +1,4 @@
import { config, shallowMount } from '@vue/test-utils' import { config, mount } from '@vue/test-utils'
import Comment from './Comment.vue' import Comment from './Comment.vue'
import Vuex from 'vuex' import Vuex from 'vuex'
@ -47,14 +47,14 @@ describe('Comment.vue', () => {
} }
}) })
describe('shallowMount', () => { describe('mount', () => {
beforeEach(jest.useFakeTimers) beforeEach(jest.useFakeTimers)
Wrapper = () => { Wrapper = () => {
const store = new Vuex.Store({ const store = new Vuex.Store({
getters, getters,
}) })
return shallowMount(Comment, { return mount(Comment, {
store, store,
propsData, propsData,
mocks, mocks,
@ -68,6 +68,7 @@ describe('Comment.vue', () => {
id: '2', id: '2',
contentExcerpt: 'Hello I am a comment content', contentExcerpt: 'Hello I am a comment content',
content: 'Hello I am comment content', content: 'Hello I am comment content',
author: { id: 'commentAuthorId', slug: 'ogerly'}
} }
}) })
@ -199,6 +200,24 @@ describe('Comment.vue', () => {
}) })
}) })
}) })
describe('click reply button', () => {
beforeEach(async () => {
wrapper = Wrapper()
await wrapper.find('.reply-button').trigger('click')
})
it('emits "reply"', () => {
expect(wrapper.emitted('reply')).toEqual([
[
{
id: 'commentAuthorId',
slug: 'ogerly'
},
],
])
})
})
}) })
}) })
}) })

View File

@ -55,11 +55,11 @@
</div> </div>
<ds-space margin-bottom="small" /> <ds-space margin-bottom="small" />
<ds-button <ds-button
:title="this.$t('post.comment.answer')" :title="this.$t('post.comment.reply')"
icon="level-down" icon="level-down"
@click.prevent="reply" @click.prevent="reply"
v-scroll-to="'.editor'" v-scroll-to="'.editor'"
class="answerbutton" class="reply-button"
size="small" size="small"
></ds-button> ></ds-button>
</ds-card> </ds-card>
@ -76,6 +76,7 @@ import HcCommentForm from '~/components/CommentForm/CommentForm'
import CommentMutations from '~/graphql/CommentMutations' import CommentMutations from '~/graphql/CommentMutations'
import scrollToAnchor from '~/mixins/scrollToAnchor.js' import scrollToAnchor from '~/mixins/scrollToAnchor.js'
export default { export default {
mixins: [scrollToAnchor], mixins: [scrollToAnchor],
data() { data() {
@ -148,7 +149,7 @@ export default {
}, },
}, },
methods: { methods: {
reply(comment) { reply() {
const message = { slug: this.comment.author.slug, id: this.comment.author.id } const message = { slug: this.comment.author.slug, id: this.comment.author.id }
this.$emit('reply', message) this.$emit('reply', message)
}, },
@ -204,11 +205,11 @@ export default {
float: right; float: right;
} }
.answerbutton { .reply-button {
float: right; float: right;
top: 0px; top: 0px;
} }
.answerbutton:after { .reply-button:after {
clear: both; clear: both;
} }

View File

@ -103,4 +103,22 @@ describe('CommentList.vue', () => {
}) })
}) })
}) })
describe('Comment', () => {
beforeEach(() => {
wrapper = Wrapper()
})
it('Comment emitted reply()', () => {
wrapper.find('.comment-tag').vm.$emit('reply')
expect(wrapper.emitted('reply')).toEqual([
[
{
id: 'commentAuthorId',
slug: 'ogerly'
},
],
])
})
})
}) })

View File

@ -17,6 +17,7 @@
@deleteComment="updateCommentList" @deleteComment="updateCommentList"
@updateComment="updateCommentList" @updateComment="updateCommentList"
@toggleNewCommentForm="toggleNewCommentForm" @toggleNewCommentForm="toggleNewCommentForm"
class="comment-tag"
/> />
</div> </div>
</div> </div>

View File

@ -270,7 +270,7 @@
"submit": "Kommentiere", "submit": "Kommentiere",
"submitted": "Kommentar Gesendet", "submitted": "Kommentar Gesendet",
"updated": "Änderungen gespeichert", "updated": "Änderungen gespeichert",
"answer": "Antworten" "reply": "Antworten"
}, },
"edited": "bearbeitet" "edited": "bearbeitet"
}, },

View File

@ -424,7 +424,7 @@
"submit": "Comment", "submit": "Comment",
"submitted": "Comment Submitted", "submitted": "Comment Submitted",
"updated": "Changes Saved", "updated": "Changes Saved",
"answer": "Answer" "reply": "Reply"
}, },
"edited": "edited" "edited": "edited"
}, },

View File

@ -1,16 +1,16 @@
import { config, shallowMount } from '@vue/test-utils' import { config, shallowMount } from '@vue/test-utils'
import PostSlug from './index.vue' import PostSlug from './index.vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import CommentList from '~/components/CommentList/CommentList'
const localVue = global.localVue const localVue = global.localVue
config.stubs['client-only'] = '<span><slot /></span>'
describe('PostSlug', () => { describe('PostSlug', () => {
let wrapper let wrapper
let Wrapper let Wrapper
let store let store
let mocks let mocks
let propsData
beforeEach(() => { beforeEach(() => {
store = new Vuex.Store({ store = new Vuex.Store({
@ -20,6 +20,7 @@ describe('PostSlug', () => {
}, },
}, },
}) })
propsData = {}
mocks = { mocks = {
$t: jest.fn(), $t: jest.fn(),
$filters: { $filters: {
@ -44,12 +45,14 @@ describe('PostSlug', () => {
} }
}) })
describe('shallowMount', () => { describe('shallowMount', () => {
Wrapper = () => { Wrapper = () => {
return shallowMount(PostSlug, { return shallowMount(PostSlug, {
store, store,
mocks, mocks,
localVue, localVue,
propsData,
}) })
} }
@ -92,4 +95,16 @@ describe('PostSlug', () => {
}) })
}) })
}) })
describe('given a comment', () => {
wrapper = Wrapper()
const bar = wrapper.find(CommentList)
it('hc-comment-list', () => {
expect(bar).toBe({"selector": "Component"})
})
})
}) })