add EditCommentForm spec.js

This commit is contained in:
ALau2088 2019-06-27 10:59:53 -07:00
parent 5e9f46405e
commit 912b94d43c
5 changed files with 36 additions and 40 deletions

View File

@ -74,9 +74,6 @@ export default {
session.close() session.close()
return commentReturnedWithAuthor return commentReturnedWithAuthor
}, },
UpdateComment: async (object, params, context, resolveInfo) => {
await neo4jgraphql(object, params, context, resolveInfo, false)
},
DeleteComment: async (object, params, context, resolveInfo) => { DeleteComment: async (object, params, context, resolveInfo) => {
const comment = await neo4jgraphql(object, params, context, resolveInfo, false) const comment = await neo4jgraphql(object, params, context, resolveInfo, false)

View File

@ -1,13 +1,13 @@
<template> <template>
<div v-if="(comment.deleted || comment.disabled) && !isModerator"> <div v-if="(comment.deleted || comment.disabled) && !isModerator">
<ds-text style="padding-left: 40px; font-weight: bold;" color="soft"> <ds-text style="padding-left: 40px; font-weight: bold;" color="soft">
<ds-icon name="ban"/> <ds-icon name="ban" />
{{ this.$t('comment.content.unavailable-placeholder') }} {{ this.$t('comment.content.unavailable-placeholder') }}
</ds-text> </ds-text>
</div> </div>
<div v-else :class="{ comment: true, 'disabled-content': comment.deleted || comment.disabled }"> <div v-else :class="{ comment: true, 'disabled-content': comment.deleted || comment.disabled }">
<ds-space margin-bottom="x-small"> <ds-space margin-bottom="x-small">
<hc-user :user="author" :date-time="comment.createdAt"/> <hc-user :user="author" :date-time="comment.createdAt" />
</ds-space> </ds-space>
<!-- Content Menu (can open Modals) --> <!-- Content Menu (can open Modals) -->
<no-ssr> <no-ssr>
@ -23,7 +23,7 @@
</no-ssr> </no-ssr>
<!-- eslint-disable vue/no-v-html --> <!-- eslint-disable vue/no-v-html -->
<!-- TODO: replace editor content with tiptap render view --> <!-- TODO: replace editor content with tiptap render view -->
<ds-space margin-bottom="small"/> <ds-space margin-bottom="small" />
<div v-if="openEditCommentMenu"> <div v-if="openEditCommentMenu">
<hc-edit-comment-form <hc-edit-comment-form
v-bind:comment="comment" v-bind:comment="comment"
@ -31,7 +31,7 @@
v-on:showEditCommentMenu="editCommentMenu" v-on:showEditCommentMenu="editCommentMenu"
/> />
</div> </div>
<div v-else style="padding-left: 40px;" v-html="comment.contentExcerpt"/> <div v-else style="padding-left: 40px;" v-html="comment.contentExcerpt" />
<!-- eslint-enable vue/no-v-html --> <!-- eslint-enable vue/no-v-html -->
</div> </div>
</template> </template>

View File

@ -3,7 +3,7 @@
<template slot="default" slot-scope="{ toggleMenu }"> <template slot="default" slot-scope="{ toggleMenu }">
<slot name="button" :toggleMenu="toggleMenu"> <slot name="button" :toggleMenu="toggleMenu">
<ds-button class="content-menu-trigger" size="small" ghost @click.prevent="toggleMenu"> <ds-button class="content-menu-trigger" size="small" ghost @click.prevent="toggleMenu">
<ds-icon name="ellipsis-v"/> <ds-icon name="ellipsis-v" />
</ds-button> </ds-button>
</slot> </slot>
</template> </template>
@ -16,7 +16,7 @@
:parents="item.parents" :parents="item.parents"
@click.stop.prevent="openItem(item.route, toggleMenu)" @click.stop.prevent="openItem(item.route, toggleMenu)"
> >
<ds-icon :name="item.route.icon"/> <ds-icon :name="item.route.icon" />
{{ item.route.name }} {{ item.route.name }}
</ds-menu-item> </ds-menu-item>
</ds-menu> </ds-menu>

View File

@ -2,17 +2,20 @@
<div id="comments"> <div id="comments">
<h3 style="margin-top: -10px;"> <h3 style="margin-top: -10px;">
<span> <span>
<ds-icon name="comments"/> <ds-icon name="comments" />
<ds-tag <ds-tag
v-if="comments" v-if="comments"
style="margin-top: -4px; margin-left: -12px; position: absolute;" style="margin-top: -4px; margin-left: -12px; position: absolute;"
color="primary" color="primary"
size="small" size="small"
round round
>{{ comments.length }}</ds-tag>&nbsp; Comments >
{{ comments.length }}
</ds-tag>
&nbsp; Comments
</span> </span>
</h3> </h3>
<ds-space margin-bottom="large"/> <ds-space margin-bottom="large" />
<div v-if="comments && comments.length" id="comments" class="comments"> <div v-if="comments && comments.length" id="comments" class="comments">
<comment <comment
v-for="(comment, index) in comments" v-for="(comment, index) in comments"
@ -22,7 +25,7 @@
@deleteComment="comments.splice(index, 1)" @deleteComment="comments.splice(index, 1)"
/> />
</div> </div>
<hc-empty v-else name="empty" icon="messages"/> <hc-empty v-else name="empty" icon="messages" />
</div> </div>
</template> </template>
<script> <script>

View File

@ -3,26 +3,25 @@
<template slot-scope="{ errors }"> <template slot-scope="{ errors }">
<ds-card> <ds-card>
<!-- <no-ssr> --> <!-- <no-ssr> -->
<hc-editor ref="editor" :users="users" :value="form.content" @input="updateEditorContent"/> <hc-editor ref="editor" :users="users" :value="form.content" @input="updateEditorContent" />
<!-- </no-ssr> --> <!-- </no-ssr> -->
<ds-space/> <ds-space />
<ds-flex :gutter="{ base: 'small', md: 'small', sm: 'x-large', xs: 'x-large' }"> <ds-flex :gutter="{ base: 'small', md: 'small', sm: 'x-large', xs: 'x-large' }">
<ds-flex-item :width="{ base: '0%', md: '50%', sm: '0%', xs: '0%' }"/> <ds-flex-item :width="{ base: '0%', md: '50%', sm: '0%', xs: '0%' }" />
<ds-flex-item :width="{ base: '40%', md: '20%', sm: '30%', xs: '30%' }"> <ds-flex-item :width="{ base: '40%', md: '20%', sm: '30%', xs: '30%' }">
<ds-button <ds-button
:disabled="disabled" :disabled="disabled"
ghost ghost
class="cancelBtn" class="cancelBtn"
@click.prevent="closeEditWindow" @click.prevent="closeEditWindow"
>{{ $t('actions.cancel') }}</ds-button> >
{{ $t('actions.cancel') }}
</ds-button>
</ds-flex-item> </ds-flex-item>
<ds-flex-item :width="{ base: '40%', md: '20%', sm: '40%', xs: '40%' }"> <ds-flex-item :width="{ base: '40%', md: '20%', sm: '40%', xs: '40%' }">
<ds-button <ds-button type="submit" :loading="loading" :disabled="disabled || errors" primary>
type="submit" {{ $t('post.comment.submit') }}
:loading="loading" </ds-button>
:disabled="disabled || errors"
primary
>{{ $t('post.comment.submit') }}</ds-button>
</ds-flex-item> </ds-flex-item>
</ds-flex> </ds-flex>
</ds-card> </ds-card>
@ -36,26 +35,24 @@ import HcEditor from '~/components/Editor'
export default { export default {
components: { components: {
HcEditor HcEditor,
}, },
props: { props: {
post: { type: Object, default: () => {} },
comments: { type: Array, default: () => [] },
comment: { comment: {
type: Object, type: Object,
default() { default() {
return {} return {}
} },
} },
}, },
data() { data() {
return { return {
disabled: false, disabled: false,
loading: false, loading: false,
form: { form: {
content: this.comment.contentExcerpt content: this.comment.contentExcerpt,
}, },
users: [] users: [],
} }
}, },
methods: { methods: {
@ -77,22 +74,21 @@ export default {
this.$apollo this.$apollo
.mutate({ .mutate({
mutation: gql` mutation: gql`
mutation($postId: ID, $content: String!, $id: ID!) { mutation($content: String!, $id: ID!) {
UpdateComment(postId: $postId, content: $content, id: $id) { UpdateComment(content: $content, id: $id) {
id id
content content
} }
} }
`, `,
variables: { variables: {
postId: this.post.id,
content: this.form.content, content: this.form.content,
id: this.comment.id id: this.comment.id,
} },
}) })
.then(res => { .then(res => {
this.loading = false this.loading = false
this.$root.$emit('refetchPostComments')
this.$toast.success(this.$t('post.comment.updated')) this.$toast.success(this.$t('post.comment.updated'))
this.disabled = false this.disabled = false
this.$emit('showEditCommentMenu', false) this.$emit('showEditCommentMenu', false)
@ -100,7 +96,7 @@ export default {
.catch(err => { .catch(err => {
this.$toast.error(err.message) this.$toast.error(err.message)
}) })
} },
}, },
apollo: { apollo: {
User: { User: {
@ -114,8 +110,8 @@ export default {
}, },
result(result) { result(result) {
this.users = result.data.User this.users = result.data.User
} },
} },
} },
} }
</script> </script>