Stub component, rename component, refactor

- We need to stub the Editor since it throws difficult to interpret
  errors about view.root.getSelection, but we want to stub it's methods
as well, so that we don't need a guard clause just for tests.

- CommentForm is already multiword
- Favor update over result for Vue apollo smart queries
This commit is contained in:
mattwr18 2020-01-23 14:03:14 +01:00
parent d15037607c
commit 853ff9b92b
6 changed files with 19 additions and 19 deletions

View File

@ -7,14 +7,9 @@ localVue.directive('scrollTo', jest.fn())
config.stubs['client-only'] = '<span><slot /></span>' config.stubs['client-only'] = '<span><slot /></span>'
config.stubs['nuxt-link'] = '<span><slot /></span>' config.stubs['nuxt-link'] = '<span><slot /></span>'
config.stubs['content-viewer'] = '<span><slot /></span>'
describe('Comment.vue', () => { describe('Comment.vue', () => {
let propsData let propsData, mocks, stubs, getters, wrapper, Wrapper
let mocks
let getters
let wrapper
let Wrapper
beforeEach(() => { beforeEach(() => {
propsData = {} propsData = {}
@ -42,6 +37,9 @@ describe('Comment.vue', () => {
}), }),
}, },
} }
stubs = {
ContentViewer: true,
}
getters = { getters = {
'auth/user': () => { 'auth/user': () => {
return {} return {}
@ -62,6 +60,7 @@ describe('Comment.vue', () => {
propsData, propsData,
mocks, mocks,
localVue, localVue,
stubs,
}) })
} }

View File

@ -33,7 +33,7 @@
</client-only> </client-only>
</ds-space> </ds-space>
<div v-if="openEditCommentMenu"> <div v-if="openEditCommentMenu">
<hc-comment-form <comment-form
:update="true" :update="true"
:post="post" :post="post"
:comment="comment" :comment="comment"
@ -73,7 +73,7 @@ import { COMMENT_MAX_UNTRUNCATED_LENGTH, COMMENT_TRUNCATE_TO_LENGTH } from '~/co
import UserTeaser from '~/components/UserTeaser/UserTeaser' import UserTeaser from '~/components/UserTeaser/UserTeaser'
import ContentMenu from '~/components/ContentMenu/ContentMenu' import ContentMenu from '~/components/ContentMenu/ContentMenu'
import ContentViewer from '~/components/Editor/ContentViewer' import ContentViewer from '~/components/Editor/ContentViewer'
import HcCommentForm from '~/components/CommentForm/CommentForm' import CommentForm 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'
import BaseButton from '~/components/_new/generic/BaseButton/BaseButton' import BaseButton from '~/components/_new/generic/BaseButton/BaseButton'
@ -95,7 +95,7 @@ export default {
UserTeaser, UserTeaser,
ContentMenu, ContentMenu,
ContentViewer, ContentViewer,
HcCommentForm, CommentForm,
BaseButton, BaseButton,
}, },
props: { props: {

View File

@ -52,7 +52,6 @@ export default {
}, },
methods: { methods: {
reply(message) { reply(message) {
if (!this.$refs.editor.insertReply) return null
this.$refs.editor.insertReply(message) this.$refs.editor.insertReply(message)
}, },
updateEditorContent(value) { updateEditorContent(value) {

View File

@ -105,7 +105,7 @@ export default {
postId: this.post.id, postId: this.post.id,
} }
}, },
result({ data: { PostsEmotionsByCurrentUser } }) { update({ PostsEmotionsByCurrentUser }) {
this.selectedEmotions = PostsEmotionsByCurrentUser this.selectedEmotions = PostsEmotionsByCurrentUser
}, },
}, },

View File

@ -6,15 +6,12 @@ import CommentList from '~/components/CommentList/CommentList'
config.stubs['client-only'] = '<span><slot /></span>' config.stubs['client-only'] = '<span><slot /></span>'
config.stubs['nuxt-link'] = '<span><slot /></span>' config.stubs['nuxt-link'] = '<span><slot /></span>'
config.stubs['router-link'] = '<span><slot /></span>' config.stubs['router-link'] = '<span><slot /></span>'
config.stubs['content-viewer'] = '<span><slot /></span>'
config.stubs['hc-editor'] = '<span><slot /></span>'
config.stubs['hc-emotions'] = '<span><slot /></span>'
const localVue = global.localVue const localVue = global.localVue
localVue.directive('scrollTo', jest.fn()) localVue.directive('scrollTo', jest.fn())
describe('PostSlug', () => { describe('PostSlug', () => {
let wrapper, Wrapper, store, mocks, propsData, spy let store, propsData, mocks, stubs, wrapper, Wrapper, spy
beforeEach(() => { beforeEach(() => {
store = new Vuex.Store({ store = new Vuex.Store({
@ -47,7 +44,7 @@ describe('PostSlug', () => {
}, },
$apollo: { $apollo: {
mutate: jest.fn().mockResolvedValue(), mutate: jest.fn().mockResolvedValue(),
query: jest.fn().mockResolvedValue(), query: jest.fn().mockResolvedValue({ data: { PostEmotionsCountByEmotion: {} } }),
}, },
$scrollTo: jest.fn(), $scrollTo: jest.fn(),
$refs: { $refs: {
@ -59,6 +56,10 @@ describe('PostSlug', () => {
}, },
}, },
} }
stubs = {
HcEditor: { render: () => {}, methods: { insertReply: () => null } },
ContentViewer: true,
}
jest.useFakeTimers() jest.useFakeTimers()
wrapper = Wrapper() wrapper = Wrapper()
wrapper.setData({ wrapper.setData({
@ -91,6 +92,7 @@ describe('PostSlug', () => {
mocks, mocks,
localVue, localVue,
propsData, propsData,
stubs,
}) })
} }

View File

@ -91,7 +91,7 @@
@reply="reply" @reply="reply"
/> />
<ds-space margin-bottom="large" /> <ds-space margin-bottom="large" />
<hc-comment-form <comment-form
ref="commentForm" ref="commentForm"
v-if="showNewCommentForm" v-if="showNewCommentForm"
:post="post" :post="post"
@ -109,7 +109,7 @@ import HcHashtag from '~/components/Hashtag/Hashtag'
import ContentMenu from '~/components/ContentMenu/ContentMenu' import ContentMenu from '~/components/ContentMenu/ContentMenu'
import UserTeaser from '~/components/UserTeaser/UserTeaser' import UserTeaser from '~/components/UserTeaser/UserTeaser'
import HcShoutButton from '~/components/ShoutButton.vue' import HcShoutButton from '~/components/ShoutButton.vue'
import HcCommentForm from '~/components/CommentForm/CommentForm' import CommentForm from '~/components/CommentForm/CommentForm'
import CommentList from '~/components/CommentList/CommentList' import CommentList from '~/components/CommentList/CommentList'
import { postMenuModalsData, deletePostMutation } from '~/components/utils/PostHelpers' import { postMenuModalsData, deletePostMutation } from '~/components/utils/PostHelpers'
import PostQuery from '~/graphql/PostQuery' import PostQuery from '~/graphql/PostQuery'
@ -128,7 +128,7 @@ export default {
UserTeaser, UserTeaser,
HcShoutButton, HcShoutButton,
ContentMenu, ContentMenu,
HcCommentForm, CommentForm,
CommentList, CommentList,
HcEmotions, HcEmotions,
ContentViewer, ContentViewer,