Fix vue warnings, fix tests, refactor

- was throwing an error when trying to update commentsCount because of new implementation by @roschaefer which uses countResolver, but there was no related for commentsCount, it was r... also commentsCount is no longer needed anywhere in the code base, it is commentedCount now
This commit is contained in:
Matt Rider 2019-08-16 13:28:55 +02:00
parent d511d6aa78
commit dbaa8e687f
29 changed files with 91 additions and 92 deletions

View File

@ -151,7 +151,6 @@ export default {
friendsCount: '<-[:FRIENDS]->(related:User)',
followingCount: '-[:FOLLOWS]->(related:User)',
followedByCount: '<-[:FOLLOWS]-(related:User)',
commentsCount: '-[:WROTE]->(r:Comment)',
commentedCount: '-[:WROTE]->(:Comment)-[:COMMENTS]->(related:Post)',
shoutedCount: '-[:SHOUTED]->(related:Post)',
badgesCount: '<-[:REWARDED]-(related:Badge)',

View File

@ -29,11 +29,6 @@ type Post {
categories: [Category]! @relation(name: "CATEGORIZED", direction: "OUT")
comments: [Comment]! @relation(name: "COMMENTS", direction: "IN")
commentsCount: Int!
@cypher(
statement: "MATCH (this)<-[:COMMENTS]-(r:Comment) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(r)"
)
shoutedBy: [User]! @relation(name: "SHOUTED", direction: "IN")
shoutedCount: Int!
@cypher(

View File

@ -64,7 +64,6 @@ type User {
)
comments: [Comment]! @relation(name: "WROTE", direction: "OUT")
commentsCount: Int! @cypher(statement: "MATCH (this)-[:WROTE]->(r:Comment) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(r)")
commentedCount: Int! @cypher(statement: "MATCH (this)-[:WROTE]->(r:Comment)-[:COMMENTS]->(p:Post) WHERE NOT r.deleted = true AND NOT r.disabled = true AND NOT p.deleted = true AND NOT p.disabled = true RETURN COUNT(DISTINCT(p))")
shouted: [Post]! @relation(name: "SHOUTED", direction: "OUT")
@ -143,7 +142,6 @@ type Query {
followedByCount: Int
followedByCurrentUser: Boolean
contributionsCount: Int
commentsCount: Int
commentedCount: Int
shoutedCount: Int
badgesCount: Int

View File

@ -67,7 +67,7 @@ import { mapGetters, mapMutations } from 'vuex'
import HcUser from '~/components/User'
import ContentMenu from '~/components/ContentMenu'
import ContentViewer from '~/components/Editor/ContentViewer'
import HcEditCommentForm from '~/components/comments/EditCommentForm/EditCommentForm'
import HcEditCommentForm from '~/components/EditCommentForm/EditCommentForm'
export default {
data: function() {

View File

@ -1,5 +1,5 @@
import { mount, createLocalVue } from '@vue/test-utils'
import CommentForm from './index.vue'
import CommentForm from './CommentForm'
import Styleguide from '@human-connection/styleguide'
import Vuex from 'vuex'
import MutationObserver from 'mutation-observer'

View File

@ -69,7 +69,7 @@ export default {
this.disabled = true
this.$apollo
.mutate({
mutation: CommentMutations().CreateComment,
mutation: CommentMutations(this.$i18n).CreateComment,
variables: {
postId: this.post.id,
content: this.form.content,

View File

@ -1,5 +1,5 @@
import { config, mount, createLocalVue } from '@vue/test-utils'
import CommentList from '.'
import CommentList from './CommentList'
import Empty from '~/components/Empty'
import Vuex from 'vuex'
import Styleguide from '@human-connection/styleguide'
@ -21,63 +21,52 @@ describe('CommentList.vue', () => {
let store
let wrapper
let propsData
let data
propsData = {
post: {
id: 1,
},
}
store = new Vuex.Store({
getters: {
'auth/user': () => {
return {}
},
},
})
mocks = {
$t: jest.fn(),
$filters: {
truncate: a => a,
},
$apollo: {
queries: {
Post: {
refetch: jest.fn(),
},
},
},
}
data = () => {
return {
comments: [],
}
}
describe('shallowMount', () => {
beforeEach(() => {
propsData = {
post: {
id: 1,
comments: [{ id: 'comment134', contentExcerpt: 'this is a comment' }],
},
}
store = new Vuex.Store({
getters: {
'auth/user': () => {
return {}
},
},
})
mocks = {
$t: jest.fn(),
$filters: {
truncate: a => a,
},
$apollo: {
queries: {
Post: {
refetch: jest.fn(),
},
},
},
}
})
const Wrapper = () => {
return mount(CommentList, {
store,
mocks,
localVue,
propsData,
data,
})
}
beforeEach(() => {
wrapper = Wrapper()
wrapper.setData({
comments: [
{
id: 'c1',
contentExcerpt: 'this is a comment',
},
],
})
})
it('displays a message icon when there are no comments to display', () => {
propsData.post.comments = []
expect(Wrapper().findAll(Empty)).toHaveLength(1)
})

View File

@ -4,7 +4,7 @@
<span>
<ds-icon name="comments" />
<ds-tag
v-if="post.comments"
v-if="post.comments.length"
style="margin-top: -4px; margin-left: -12px; position: absolute;"
color="primary"
size="small"

View File

@ -48,7 +48,7 @@ describe('DeleteData.vue', () => {
}
getters = {
'auth/user': () => {
return { id: 'u343', name: deleteAccountName, contributionsCount: 2, commentsCount: 3 }
return { id: 'u343', name: deleteAccountName, contributionsCount: 2, commentedCount: 3 }
},
}
actions = { 'auth/logout': jest.fn() }

View File

@ -30,12 +30,12 @@
}}
</label>
<ds-space margin-bottom="small" />
<label v-if="currentUser.commentsCount" class="checkbox-container">
<label v-if="currentUser.commentedCount" class="checkbox-container">
<input type="checkbox" v-model="deleteComments" />
<span class="checkmark"></span>
{{
$t('settings.deleteUserAccount.commentsCount', {
count: currentUser.commentsCount,
$t('settings.deleteUserAccount.commentedCount', {
count: currentUser.commentedCount,
})
}}
</label>

View File

@ -24,7 +24,7 @@ const post = {
deleted: false,
contributionsCount: 25,
shoutedCount: 5,
commentsCount: 39,
commentedCount: 39,
followedByCount: 2,
followedByCurrentUser: true,
location: null,
@ -38,7 +38,7 @@ const post = {
],
__typename: 'User',
},
commentsCount: 12,
commentedCount: 12,
categories: [],
shoutedCount: 421,
__typename: 'Post',

View File

@ -48,9 +48,9 @@
</span>
&nbsp;
<!-- Comments Count -->
<span :style="{ opacity: post.commentsCount ? 1 : 0.5 }">
<span :style="{ opacity: post.commentedCount ? 1 : 0.5 }">
<ds-icon name="comments" />
<small>{{ post.commentsCount }}</small>
<small>{{ post.commentedCount }}</small>
</span>
<!-- Menu -->
<content-menu

View File

@ -122,7 +122,7 @@ describe('SearchInput.vue', () => {
name: 'Trick',
slug: 'trick',
},
commentsCount: 0,
commentedCount: 0,
createdAt: '2019-03-13T11:00:20.835Z',
id: 'p10',
label: 'Eos aut illo omnis quis eaque et iure aut.',

View File

@ -46,7 +46,7 @@
<ds-flex-item>
<ds-text size="small" color="softer" class="search-meta">
<span style="text-align: right;">
<b>{{ option.commentsCount }}</b>
<b>{{ option.commentedCount }}</b>
<ds-icon name="comments" />
</span>
<span style="width: 36px; display: inline-block; text-align: right;">

View File

@ -64,8 +64,8 @@
<ds-flex-item class="ds-tab-nav-item">
<ds-space margin="small">
<ds-number
:count="user.commentsCount"
:label="$t('common.comment', null, user.commentsCount)"
:count="user.commentedCount"
:label="$t('common.comment', null, user.commentedCount)"
/>
</ds-space>
</ds-flex-item>

View File

@ -1,6 +1,6 @@
import gql from 'graphql-tag'
export default () => {
export default i18n => {
return {
CreateComment: gql`
mutation($postId: ID!, $content: String!) {
@ -8,15 +8,26 @@ export default () => {
id
contentExcerpt
content
createdAt
disabled
deleted
author {
id
slug
name
avatar
disabled
deleted
shoutedCount
contributionsCount
commentedCount
followedByCount
followedByCurrentUser
badges {
id
icon
}
}
createdAt
deleted
disabled
}
}
`,
@ -24,8 +35,19 @@ export default () => {
mutation($content: String!, $id: ID!) {
UpdateComment(content: $content, id: $id) {
id
content
contentExcerpt
content
createdAt
disabled
deleted
author {
id
slug
name
avatar
disabled
deleted
}
}
}
`,

View File

@ -17,7 +17,7 @@ export default app => {
deleted
shoutedCount
contributionsCount
commentsCount
commentedCount
followedByCount
followedByCurrentUser
location {

View File

@ -22,7 +22,7 @@ export default i18n => {
deleted
shoutedCount
contributionsCount
commentsCount
commentedCount
followedByCount
followedByCurrentUser
location {
@ -36,7 +36,6 @@ export default i18n => {
tags {
name
}
commentsCount
comments(orderBy: createdAt_asc) {
id
contentExcerpt
@ -53,7 +52,7 @@ export default i18n => {
deleted
shoutedCount
contributionsCount
commentsCount
commentedCount
followedByCount
followedByCurrentUser
location {
@ -100,7 +99,7 @@ export const filterPosts = i18n => {
deleted
contributionsCount
shoutedCount
commentsCount
commentedCount
followedByCount
followedByCurrentUser
location {
@ -111,7 +110,6 @@ export const filterPosts = i18n => {
icon
}
}
commentsCount
categories {
id
name

View File

@ -35,7 +35,7 @@ export default i18n => {
followedByCount
followedByCurrentUser
contributionsCount
commentsCount
commentedCount
badges {
id
icon
@ -57,7 +57,7 @@ export default i18n => {
followedByCount
followedByCurrentUser
contributionsCount
commentsCount
commentedCount
badges {
id
icon
@ -66,7 +66,6 @@ export default i18n => {
name: name${lang}
}
}
contributionsCount
socialMedia {
id
url

View File

@ -171,7 +171,7 @@
"deleteUserAccount": {
"name": "Daten löschen",
"contributionsCount": "Meine {count} Beiträge löschen",
"commentsCount": "Meine {count} Kommentare löschen",
"commentedCount": "Meine {count} Kommentare löschen",
"accountDescription": "Sei dir bewusst, dass deine Beiträge und Kommentare für unsere Community wichtig sind. Wenn du sie trotzdem löschen möchtest, musst du sie unten markieren.",
"accountWarning": "Dein Konto, deine Beiträge oder Kommentare kannst du nach dem Löschen <b>WEDER VERWALTEN NOCH WIEDERHERSTELLEN!</b>",
"success": "Konto erfolgreich gelöscht!",

View File

@ -171,7 +171,7 @@
"deleteUserAccount": {
"name": "Delete data",
"contributionsCount": "Delete my {count} posts",
"commentsCount": "Delete my {count} comments",
"commentedCount": "Delete my {count} comments",
"accountDescription": "Be aware that your Post and Comments are important to our community. If you still choose to delete them, you have to mark them below.",
"accountWarning": "You <b>CAN'T MANAGE</b> and <b>CAN'T RECOVER</b> your Account, Posts, or Comments after deleting your account!",
"success": "Account successfully deleted!",

View File

@ -121,7 +121,7 @@
"deleteUserAccount": {
"name": "Usuń dane",
"contributionsCount": "Usuń {count} moich postów",
"commentsCount": "Usuń {count} moich komentarzy",
"commentedCount": "Usuń {count} moich komentarzy",
"accountDescription": "Be aware that your Post and Comments are important to our community. If you still choose to delete them, you have to mark them below.",
"accountWarning": "Po usunięcie Twojego konta, nie możesz <b>ZARZĄDZAĆ</b> ani <b>ODZYSKAĆ</b> danych, wpisów oraz komentarzy!",
"success": "Konto zostało usunięte",

View File

@ -96,7 +96,7 @@ export default {
label: this.$t('sorting.commented'),
value: 'Commented',
icons: 'comment',
order: 'commentsCount_desc',
order: 'commentedCount_desc',
},
],
}

View File

@ -81,8 +81,8 @@ import HcTag from '~/components/Tag'
import ContentMenu from '~/components/ContentMenu'
import HcUser from '~/components/User'
import HcShoutButton from '~/components/ShoutButton.vue'
import HcCommentForm from '~/components/comments/CommentForm'
import HcCommentList from '~/components/comments/CommentList'
import HcCommentForm from '~/components/CommentForm/CommentForm'
import HcCommentList from '~/components/CommentList/CommentList'
import { postMenuModalsData, deletePostMutation } from '~/components/utils/PostHelpers'
import PostQuery from '~/graphql/PostQuery'
import HcEmotions from '~/components/Emotions/Emotions'

View File

@ -91,7 +91,7 @@ export default {
slug
contentExcerpt
shoutedCount
commentsCount
commentedCount
categories {
id
name
@ -105,7 +105,7 @@ export default {
contributionsCount
followedByCount
followedByCurrentUser
commentsCount
commentedCount
location {
name: name${this.$i18n.locale().toUpperCase()}
}

View File

@ -80,7 +80,7 @@ export const actions = {
about
locationName
contributionsCount
commentsCount
commentedCount
socialMedia {
id
url

View File

@ -88,7 +88,7 @@ export const actions = {
deleted
contributionsCount
shoutedCount
commentsCount
commentedCount
followedByCount
followedByCurrentUser
location {
@ -99,7 +99,6 @@ export const actions = {
icon
}
}
commentsCount
categories {
id
name

View File

@ -53,7 +53,7 @@ export const actions = {
label: title
value: title,
shoutedCount
commentsCount
commentedCount
createdAt
author {
id