From 1acf109dbac117d08b845aec6fa803acb50379e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Wed, 15 May 2019 16:48:50 +0200 Subject: [PATCH 01/38] Implemented Menus, Unit Tests and created and refactored localisations --- webapp/components/ContentMenu.vue | 20 ++++-- webapp/components/Modal/DeleteModal.spec.js | 73 +++++++++++++++++---- webapp/components/Modal/DeleteModal.vue | 42 ++++++++---- webapp/locales/de.json | 40 +++++++---- webapp/locales/en.json | 46 ++++++++----- 5 files changed, 163 insertions(+), 58 deletions(-) diff --git a/webapp/components/ContentMenu.vue b/webapp/components/ContentMenu.vue index 29473d6b2..effc801ea 100644 --- a/webapp/components/ContentMenu.vue +++ b/webapp/components/ContentMenu.vue @@ -68,7 +68,7 @@ export default { if (this.isOwner && this.resourceType === 'contribution') { routes.push({ - name: this.$t(`contribution.edit`), + name: this.$t(`post.menu.edit`), path: this.$router.resolve({ name: 'post-edit-id', params: { @@ -78,21 +78,29 @@ export default { icon: 'edit' }) routes.push({ - name: this.$t(`post.delete.title`), + name: this.$t(`post.menu.delete`), callback: () => { this.openModal('delete') }, icon: 'trash' }) } + if (this.isOwner && this.resourceType === 'comment') { + // routes.push({ + // name: this.$t(`comment.menu.edit`), + // callback: () => { + // /* eslint-disable-next-line no-console */ + // console.log('EDIT COMMENT') + // }, + // icon: 'edit' + // }) routes.push({ - name: this.$t(`comment.edit`), + name: this.$t(`comment.menu.delete`), callback: () => { - /* eslint-disable-next-line no-console */ - console.log('EDIT COMMENT') + this.openModal('delete') }, - icon: 'edit' + icon: 'trash' }) } diff --git a/webapp/components/Modal/DeleteModal.spec.js b/webapp/components/Modal/DeleteModal.spec.js index e52c252ca..6127607a9 100644 --- a/webapp/components/Modal/DeleteModal.spec.js +++ b/webapp/components/Modal/DeleteModal.spec.js @@ -22,7 +22,7 @@ describe('DeleteModal.vue', () => { beforeEach(() => { propsData = { type: 'contribution', - id: 'c300' + id: 'p23' } mocks = { $t: jest.fn(), @@ -40,7 +40,7 @@ describe('DeleteModal.vue', () => { }) describe('shallowMount', () => { - const Wrapper = () => { + Wrapper = () => { return shallowMount(DeleteModal, { propsData, mocks, localVue, router }) } @@ -57,8 +57,8 @@ describe('DeleteModal.vue', () => { describe('given a post', () => { beforeEach(() => { propsData = { + type: 'contribution', id: 'p23', - type: 'post', name: 'It is a post' } }) @@ -66,14 +66,35 @@ describe('DeleteModal.vue', () => { it('mentions post title', () => { Wrapper() const calls = mocks.$t.mock.calls - const expected = [['post.delete.message', { name: 'It is a post' }]] + const expected = [ + ['delete.contribution.message', { name: 'It is a post' }] + ] + expect(calls).toEqual(expect.arrayContaining(expected)) + }) + }) + + describe('given a comment', () => { + beforeEach(() => { + propsData = { + type: 'comment', + id: 'c3', + name: 'It is the user of the comment' + } + }) + + it('mentions comments user name', () => { + Wrapper() + const calls = mocks.$t.mock.calls + const expected = [ + ['delete.comment.message', { name: 'It is the user of the comment' }] + ] expect(calls).toEqual(expect.arrayContaining(expected)) }) }) }) describe('mount', () => { - const Wrapper = () => { + Wrapper = () => { return mount(DeleteModal, { propsData, mocks, localVue, router }) } @@ -83,16 +104,16 @@ describe('DeleteModal.vue', () => { expect(Wrapper().is('div')).toBe(true) }) - describe('given id', () => { + describe('given post id', () => { beforeEach(() => { propsData = { - type: 'user', - id: 'u3' + type: 'contribution', + id: 'p23' } wrapper = Wrapper() }) - describe('click cancel button', () => { + describe('click cancel button and do not delete the post', () => { beforeEach(() => { wrapper = Wrapper() wrapper.find('button.cancel').trigger('click') @@ -115,7 +136,7 @@ describe('DeleteModal.vue', () => { }) }) - describe('click confirm button', () => { + describe('click confirm button and delete the post', () => { beforeEach(() => { wrapper.find('button.confirm').trigger('click') }) @@ -130,7 +151,7 @@ describe('DeleteModal.vue', () => { it('displays a success message', () => { const calls = mocks.$t.mock.calls - const expected = [['post.delete.success']] + const expected = [['delete.contribution.success']] expect(calls).toEqual(expect.arrayContaining(expected)) }) @@ -151,5 +172,35 @@ describe('DeleteModal.vue', () => { }) }) }) + + describe('given comment id', () => { + beforeEach(() => { + propsData = { + type: 'comment', + id: 'c3' + } + wrapper = Wrapper() + }) + + describe('click confirm button and delete the comment', () => { + beforeEach(() => { + wrapper.find('button.confirm').trigger('click') + }) + + it('calls delete mutation', () => { + expect(mocks.$apollo.mutate).toHaveBeenCalled() + }) + + it('sets success', () => { + expect(wrapper.vm.success).toBe(true) + }) + + it('displays a success message', () => { + const calls = mocks.$t.mock.calls + const expected = [['delete.comment.success']] + expect(calls).toEqual(expect.arrayContaining(expected)) + }) + }) + }) }) }) diff --git a/webapp/components/Modal/DeleteModal.vue b/webapp/components/Modal/DeleteModal.vue index 0f9fc0d7b..8154937db 100644 --- a/webapp/components/Modal/DeleteModal.vue +++ b/webapp/components/Modal/DeleteModal.vue @@ -25,7 +25,7 @@ icon="close" @click="cancel" > - {{ $t('post.delete.cancel') }} + {{ $t(`delete.cancel`) }} - {{ $t('post.delete.submit') }} + {{ $t(`delete.submit`) }} @@ -64,11 +64,11 @@ export default { }, computed: { title() { - return this.$t(`post.delete.title`) + return this.$t(`delete.${this.type}.title`) }, message() { const name = this.$filters.truncate(this.name, 30) - return this.$t(`post.delete.message`, { name }) + return this.$t(`delete.${this.type}.message`, { name }) } }, methods: { @@ -79,22 +79,40 @@ export default { }, 1000) }, async confirm() { + var gqlMutation + this.loading = true try { - await this.$apollo.mutate({ - mutation: gql` - mutation($id: ID!) { - DeletePost(id: $id) { - id + switch (this.type) { + case 'contribution': + gqlMutation = gql` + mutation($id: ID!) { + DeletePost(id: $id) { + id + } } - } - `, + ` + break + case 'comment': + // XXX Make custom mutation and tests in the Backend !!! + gqlMutation = gql` + mutation($id: ID!) { + DeleteComment(id: $id) { + id + } + } + ` + break + } + await this.$apollo.mutate({ + mutation: gqlMutation, variables: { id: this.id } }) this.success = true - this.$toast.success(this.$t('post.delete.success')) + this.$toast.success(this.$t(`delete.${this.type}.success`)) setTimeout(() => { this.isOpen = false + // XXX For comment just reload the page !!! setTimeout(() => { this.success = false this.$emit('close') diff --git a/webapp/locales/de.json b/webapp/locales/de.json index 96f87cd9d..8b20f763f 100644 --- a/webapp/locales/de.json +++ b/webapp/locales/de.json @@ -135,11 +135,24 @@ "takeAction": { "name": "Aktiv werden" }, + "menu": { + "edit": "Beitrag bearbeiten", + "delete": "Beitrag löschen" + }, "comment": { "submit": "Kommentiere", "submitted": "Kommentar Gesendet" } }, + "comment": { + "content": { + "unavailable-placeholder": "...dieser Kommentar ist nicht mehr verfügbar" + }, + "menu": { + "edit": "Kommentar bearbeiten", + "delete": "Kommentar löschen" + } + }, "quotes": { "african": { "quote": "Viele kleine Leute an vielen kleinen Orten, die viele kleine Dinge tun, werden das Antlitz dieser Welt verändern.", @@ -202,6 +215,22 @@ "message": "Bist du sicher, dass du den Kommentar \"{name}\" deaktivieren möchtest?" } }, + "delete": { + "submit": "Löschen", + "cancel": "Abbrechen", + "contribution": { + "title": "Lösche Beitrag", + "type": "Contribution", + "message": "Bist du sicher, dass du den Beitrag \"{name}\" löschen möchtest?", + "success": "Beitrag erfolgreich gelöscht!" + }, + "comment": { + "title": "Lösche Kommentar", + "type": "Comment", + "message": "Bist du sicher, dass du den Kommentar von \"{name}\" löschen möchtest?", + "success": "Kommentar erfolgreich gelöscht!" + } + }, "report": { "submit": "Melden", "cancel": "Abbrechen", @@ -222,17 +251,6 @@ "message": "Bist du sicher, dass du den Kommentar von \"{name}\" melden möchtest?" } }, - "contribution": { - "edit": "Beitrag bearbeiten", - "delete": "Beitrag löschen" - }, - "comment": { - "edit": "Kommentar bearbeiten", - "delete": "Kommentar löschen", - "content": { - "unavailable-placeholder": "...dieser Kommentar ist nicht mehr verfügbar" - } - }, "followButton": { "follow": "Folgen", "following": "Folge Ich" diff --git a/webapp/locales/en.json b/webapp/locales/en.json index 186b31d41..c043905d0 100644 --- a/webapp/locales/en.json +++ b/webapp/locales/en.json @@ -135,19 +135,24 @@ "takeAction": { "name": "Take action" }, - "delete": { - "submit": "Delete", - "cancel": "Cancel", - "success": "Post deleted successfully", - "title": "Delete Post", - "type": "Contribution", - "message": "Do you really want to delete the post \"{name}\"?" + "menu": { + "edit": "Edit Post", + "delete": "Delete Post" }, "comment": { "submit": "Comment", "submitted": "Comment Submitted" } }, + "comment": { + "content": { + "unavailable-placeholder": "...this comment is not available anymore" + }, + "menu": { + "edit": "Edit Comment", + "delete": "Delete Comment" + } + }, "quotes": { "african": { "quote": "Many small people in many small places do many small things, that can alter the face of the world.", @@ -210,6 +215,22 @@ "message": "Do you really want to disable the comment from \"{name}\"?" } }, + "delete": { + "submit": "Delete", + "cancel": "Cancel", + "contribution": { + "title": "Delete Post", + "type": "Contribution", + "message": "Do you really want to delete the post \"{name}\"?", + "success": "Post successfully deleted!" + }, + "comment": { + "title": "Delete Comment", + "type": "Comment", + "message": "Do you really want to delete the comment from \"{name}\"?", + "success": "Comment successfully deleted!" + } + }, "report": { "submit": "Report", "cancel": "Cancel", @@ -230,17 +251,6 @@ "message": "Do you really want to report the comment from \"{name}\"?" } }, - "contribution": { - "edit": "Edit Contribution", - "delete": "Delete Contribution" - }, - "comment": { - "edit": "Edit Comment", - "delete": "Delete Comment", - "content": { - "unavailable-placeholder": "...this comment is not available anymore" - } - }, "followButton": { "follow": "Follow", "following": "Following" From 8033556145474aa6f1013406b5a41453113a9238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Sat, 18 May 2019 07:35:45 +0200 Subject: [PATCH 02/38] Investigation how to update the Comments List intelligent --- webapp/components/Comment.vue | 4 +++ webapp/components/Modal.vue | 5 ++++ webapp/components/Modal/DeleteModal.vue | 25 ++++++++++++++----- .../components/comments/CommentList/index.vue | 14 ++++++++++- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/webapp/components/Comment.vue b/webapp/components/Comment.vue index 13edc9c0d..5e9c4faca 100644 --- a/webapp/components/Comment.vue +++ b/webapp/components/Comment.vue @@ -19,6 +19,7 @@ @@ -37,6 +38,10 @@ export default { ReportModal, DeleteModal }, + props: { + deleteCallback: { type: Function, required: true }, + cancelCallback: { type: Function, default: null } + }, computed: { ...mapGetters({ data: 'modal/data', diff --git a/webapp/components/Modal/DeleteModal.vue b/webapp/components/Modal/DeleteModal.vue index 8154937db..5a145008d 100644 --- a/webapp/components/Modal/DeleteModal.vue +++ b/webapp/components/Modal/DeleteModal.vue @@ -53,6 +53,8 @@ export default { props: { name: { type: String, default: '' }, type: { type: String, required: true }, + deleteCallback: { type: Function, required: true }, + cancelCallback: { type: Function, default: null }, id: { type: String, required: true } }, data() { @@ -116,12 +118,23 @@ export default { setTimeout(() => { this.success = false this.$emit('close') - if (this.$router.history.current.name === 'post-id-slug') { - // redirect to index - this.$router.history.push('/') - } else { - // reload the page (when deleting from profile or index) - window.location.assign(window.location.href) + switch (this.type) { + case 'contribution': + if (this.$router.history.current.name === 'post-id-slug') { + // redirect to index + this.$router.history.push('/') + } else { + // reload the page (when deleting from profile or index) + window.location.assign(window.location.href) + } + break + case 'comment': + // reload the page + // window.location.assign(window.location.href) + console.log('Remove comment emit !!!') + // this.$parent.$parent.$emit('deleteComment') + this.deleteCallback() + break } }, 500) }, 1500) diff --git a/webapp/components/comments/CommentList/index.vue b/webapp/components/comments/CommentList/index.vue index 57b720087..b77a4cf12 100644 --- a/webapp/components/comments/CommentList/index.vue +++ b/webapp/components/comments/CommentList/index.vue @@ -19,10 +19,18 @@ class="comments" > + Date: Sat, 18 May 2019 12:58:51 +0200 Subject: [PATCH 03/38] Refactored handling of DeleteModal in Comments and Posts --- webapp/components/Comment.vue | 26 ++++++++++-- webapp/components/ContentMenu.vue | 6 ++- webapp/components/Modal.vue | 7 +--- webapp/components/Modal/DeleteModal.vue | 56 +++++++++++-------------- webapp/components/PostCard/index.vue | 3 ++ webapp/mixins/Post.js | 25 +++++++++++ webapp/pages/post/_id/_slug/index.vue | 3 ++ webapp/pages/profile/_id/_slug.vue | 3 ++ 8 files changed, 88 insertions(+), 41 deletions(-) create mode 100644 webapp/mixins/Post.js diff --git a/webapp/components/Comment.vue b/webapp/components/Comment.vue index 5e9c4faca..1d52db082 100644 --- a/webapp/components/Comment.vue +++ b/webapp/components/Comment.vue @@ -19,8 +19,8 @@ @@ -37,6 +37,7 @@ diff --git a/webapp/components/ContentMenu.vue b/webapp/components/ContentMenu.vue index bee5ca011..a8b4db02f 100644 --- a/webapp/components/ContentMenu.vue +++ b/webapp/components/ContentMenu.vue @@ -59,7 +59,7 @@ export default { required: true, validator: value => { return value.match(/(contribution|comment|organization|user)/) - } + }, }, callbacks: { type: Object, required: true }, }, @@ -101,7 +101,7 @@ export default { callback: () => { this.openModal('delete') }, - icon: 'trash' + icon: 'trash', }) } @@ -153,8 +153,8 @@ export default { data: { type: this.resourceType, resource: this.resource, - callbacks: this.callbacks - } + callbacks: this.callbacks, + }, }) }, }, diff --git a/webapp/components/Modal/DeleteModal.spec.js b/webapp/components/Modal/DeleteModal.spec.js index 0b01c3647..8fd250e19 100644 --- a/webapp/components/Modal/DeleteModal.spec.js +++ b/webapp/components/Modal/DeleteModal.spec.js @@ -24,7 +24,7 @@ describe('DeleteModal.vue', () => { id: 'p23', callbacks: { confirm: () => Post.methods.deletePostCallback('list'), - cancel: null + cancel: null, }, } mocks = { @@ -65,7 +65,7 @@ describe('DeleteModal.vue', () => { name: 'It is a post', callbacks: { confirm: () => Post.methods.deletePostCallback('list'), - cancel: null + cancel: null, }, } }) @@ -73,9 +73,7 @@ describe('DeleteModal.vue', () => { it('mentions post title', () => { Wrapper() const calls = mocks.$t.mock.calls - const expected = [ - ['delete.contribution.message', { name: 'It is a post' }] - ] + const expected = [['delete.contribution.message', { name: 'It is a post' }]] expect(calls).toEqual(expect.arrayContaining(expected)) }) }) @@ -88,17 +86,15 @@ describe('DeleteModal.vue', () => { name: 'It is the user of the comment', callbacks: { confirm: () => Post.methods.deletePostCallback('list'), - cancel: null - } + cancel: null, + }, } }) it('mentions comments user name', () => { Wrapper() const calls = mocks.$t.mock.calls - const expected = [ - ['delete.comment.message', { name: 'It is the user of the comment' }] - ] + const expected = [['delete.comment.message', { name: 'It is the user of the comment' }]] expect(calls).toEqual(expect.arrayContaining(expected)) }) }) @@ -122,7 +118,7 @@ describe('DeleteModal.vue', () => { id: 'p23', callbacks: { confirm: () => Post.methods.deletePostCallback('list'), - cancel: null + cancel: null, }, } wrapper = Wrapper() @@ -195,8 +191,8 @@ describe('DeleteModal.vue', () => { id: 'c3', callbacks: { confirm: () => Post.methods.deletePostCallback('list'), - cancel: null - } + cancel: null, + }, } wrapper = Wrapper() }) diff --git a/webapp/components/Modal/DeleteModal.vue b/webapp/components/Modal/DeleteModal.vue index 883dc28d8..ef542973b 100644 --- a/webapp/components/Modal/DeleteModal.vue +++ b/webapp/components/Modal/DeleteModal.vue @@ -74,7 +74,7 @@ export default { }, methods: { async cancel() { - if (!!this.callbacks.cancel) { + if (this.callbacks.cancel) { await this.callbacks.cancel() } this.isOpen = false @@ -85,7 +85,7 @@ export default { async confirm() { this.loading = true try { - if (!!this.callbacks.confirm) { + if (this.callbacks.confirm) { await this.callbacks.confirm() } this.success = true diff --git a/webapp/components/Modal/DisableModal.vue b/webapp/components/Modal/DisableModal.vue index c2d3d64a4..fe9921511 100644 --- a/webapp/components/Modal/DisableModal.vue +++ b/webapp/components/Modal/DisableModal.vue @@ -55,7 +55,7 @@ export default { }, methods: { async cancel() { - if (!!this.callbacks.cancel) { + if (this.callbacks.cancel) { await this.callbacks.cancel() } this.isOpen = false @@ -65,7 +65,7 @@ export default { }, async confirm() { try { - if (!!this.callbacks.confirm) { + if (this.callbacks.confirm) { await this.callbacks.confirm() } await this.$apollo.mutate({ diff --git a/webapp/components/Modal/ReportModal.vue b/webapp/components/Modal/ReportModal.vue index 2fa85967f..1d99bead1 100644 --- a/webapp/components/Modal/ReportModal.vue +++ b/webapp/components/Modal/ReportModal.vue @@ -74,7 +74,7 @@ export default { }, methods: { async cancel() { - if (!!this.callbacks.cancel) { + if (this.callbacks.cancel) { await this.callbacks.cancel() } this.isOpen = false @@ -85,7 +85,7 @@ export default { async confirm() { this.loading = true try { - if (!!this.callbacks.confirm) { + if (this.callbacks.confirm) { await this.callbacks.confirm() } await this.$apollo.mutate({ diff --git a/webapp/components/PostCard/index.vue b/webapp/components/PostCard/index.vue index b5f7e5e9b..7a6f5da89 100644 --- a/webapp/components/PostCard/index.vue +++ b/webapp/components/PostCard/index.vue @@ -1,16 +1,16 @@ - + From 19771a342e42af26afc434393bf39d9c5e64cfb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Wed, 29 May 2019 12:19:51 +0200 Subject: [PATCH 14/38] First approach to test '_slug.spec.js' --- webapp/components/Modal/DeleteModal.spec.js | 43 +-- webapp/mixins/PostMutationHelpers.js | 12 +- webapp/mixins/PostMutationHelpers.spec.js | 12 +- webapp/pages/profile/_id/_slug.spec.js | 284 +++++++++----------- 4 files changed, 157 insertions(+), 194 deletions(-) diff --git a/webapp/components/Modal/DeleteModal.spec.js b/webapp/components/Modal/DeleteModal.spec.js index 664a0bdd6..704c3d832 100644 --- a/webapp/components/Modal/DeleteModal.spec.js +++ b/webapp/components/Modal/DeleteModal.spec.js @@ -1,5 +1,5 @@ import { shallowMount, mount, createLocalVue } from '@vue/test-utils' -import PostMutationHelpers from '~/mixins/PostMutationHelpers' +// import PostMutationHelpers from '~/mixins/PostMutationHelpers' import DeleteModal from './DeleteModal.vue' import Vuex from 'vuex' import Styleguide from '@human-connection/styleguide' @@ -20,6 +20,7 @@ localVue.use(Styleguide) localVue.use(VueRouter) describe('DeleteModal.vue', () => { + let Wrapper let wrapper let propsData let mocks @@ -28,10 +29,10 @@ describe('DeleteModal.vue', () => { propsData = { type: 'contribution', id: 'p23', - callbacks: { - confirm: () => Post.methods.deletePostCallback('list'), - cancel: null, - }, + // callbacks: { + // confirm: () => Post.methods.deletePostCallback('list'), + // cancel: null, + // }, } mocks = { $t: jest.fn(), @@ -74,10 +75,10 @@ describe('DeleteModal.vue', () => { type: 'contribution', id: 'p23', name: 'It is a post', - callbacks: { - confirm: () => Post.methods.deletePostCallback('list'), - cancel: null, - }, + // callbacks: { + // confirm: () => Post.methods.deletePostCallback('list'), + // cancel: null, + // }, } }) @@ -102,10 +103,10 @@ describe('DeleteModal.vue', () => { type: 'comment', id: 'c3', name: 'It is the user of the comment', - callbacks: { - confirm: () => Post.methods.deletePostCallback('list'), - cancel: null, - }, + // callbacks: { + // confirm: () => Post.methods.deletePostCallback('list'), + // cancel: null, + // }, } }) @@ -146,10 +147,10 @@ describe('DeleteModal.vue', () => { propsData = { type: 'contribution', id: 'p23', - callbacks: { - confirm: () => Post.methods.deletePostCallback('list'), - cancel: null, - }, + // callbacks: { + // confirm: () => Post.methods.deletePostCallback('list'), + // cancel: null, + // }, } wrapper = Wrapper() }) @@ -219,10 +220,10 @@ describe('DeleteModal.vue', () => { propsData = { type: 'comment', id: 'c3', - callbacks: { - confirm: () => Post.methods.deletePostCallback('list'), - cancel: null, - }, + // callbacks: { + // confirm: () => Post.methods.deletePostCallback('list'), + // cancel: null, + // }, } wrapper = Wrapper() }) diff --git a/webapp/mixins/PostMutationHelpers.js b/webapp/mixins/PostMutationHelpers.js index a19ee4949..0c0729def 100644 --- a/webapp/mixins/PostMutationHelpers.js +++ b/webapp/mixins/PostMutationHelpers.js @@ -3,7 +3,7 @@ import gql from 'graphql-tag' export default { methods: { async deletePostCallback(postDisplayType = 'list') { - console.log('inside "deletePostCallback" !!! ', this.post) + // console.log('inside "deletePostCallback" !!! ', this.post) try { var gqlMutation = gql` mutation($id: ID!) { @@ -14,16 +14,20 @@ export default { ` await this.$apollo.mutate({ mutation: gqlMutation, - variables: { id: this.post.id }, + variables: { + id: this.post.id, + }, }) - this.$toast.success(this.$t(`delete.contribution.success`)) + this.$toast.success(this.$t('delete.contribution.success')) + // console.log('called "this.$t" !!!') switch (postDisplayType) { case 'list': this.$emit('deletePost') - console.log('emitted "deletePost" !!!') + // console.log('emitted "deletePost" !!!') break default: // case 'page' + console.log('called "this.$router.history.push" !!!') this.$router.history.push('/') // Single page type: Redirect to index break } diff --git a/webapp/mixins/PostMutationHelpers.spec.js b/webapp/mixins/PostMutationHelpers.spec.js index a99e644a2..59e9d7b5e 100644 --- a/webapp/mixins/PostMutationHelpers.spec.js +++ b/webapp/mixins/PostMutationHelpers.spec.js @@ -1,4 +1,4 @@ -import { shallowMount, mount, createLocalVue } from '@vue/test-utils' +// import { shallowMount, mount, createLocalVue } from '@vue/test-utils' import Methods from '~/mixins/PostMutationHelpers' const { @@ -7,13 +7,13 @@ const { // console.log(deletePostCallback()) describe('PostMutationHelpers.js', () => { - let post + // let post let mocks beforeEach(() => { - post = { - id: 'p23', - } + // post = { + // id: 'p23', + // } mocks = { $t: jest.fn(), $filters: { @@ -64,7 +64,7 @@ describe('PostMutationHelpers.js', () => { describe('delete Post displayed on post page', () => { it('routs to index (main page) on post page', () => { deletePostCallback('page') - expect($router.history.push).toHaveBeenCalled() + // expect($router.history.push).toHaveBeenCalled() }) }) }) diff --git a/webapp/pages/profile/_id/_slug.spec.js b/webapp/pages/profile/_id/_slug.spec.js index 8fb8b4a14..b7109d3f3 100644 --- a/webapp/pages/profile/_id/_slug.spec.js +++ b/webapp/pages/profile/_id/_slug.spec.js @@ -1,13 +1,20 @@ -import { shallowMount, mount, createLocalVue } from '@vue/test-utils' +// import { shallowMount, mount, createLocalVue } from '@vue/test-utils' +import { mount, createLocalVue } from '@vue/test-utils' // import PostMutationHelpers from '~/mixins/PostMutationHelpers' import PostSlug from './_slug.vue' -import Vue from 'vue' +// import Vue from 'vue' import Vuex from 'vuex' import Styleguide from '@human-connection/styleguide' import VueRouter from 'vue-router' -const routes = [{ path: '/' }] -const router = new VueRouter({ routes }) +const routes = [ + { + path: '/', + }, +] +const router = new VueRouter({ + routes, +}) const localVue = createLocalVue() localVue.use(Vuex) @@ -30,6 +37,11 @@ describe('PostSlug', () => { // $filters: { // truncate: a => a // }, + // $router: { + // history: { + // push: jest.fn(), + // }, + // }, $toast: { success: () => {}, error: () => {}, @@ -40,72 +52,85 @@ describe('PostSlug', () => { } }) - // describe('shallowMount', () => { - // Wrapper = () => { - // return shallowMount(PostSlug, { propsData, mocks, localVue, router }) - // } - - // describe('defaults', () => { - // it('success false', () => { - // console.log(Wrapper().vm) - // expect(Wrapper().vm.success).toBe(false) - // }) - - // it('loading false', () => { - // expect(Wrapper().vm.loading).toBe(false) - // }) + // describe('shallowMount', () => { + // Wrapper = () => { + // return shallowMount(PostSlug, { + // propsData, + // mocks, + // localVue, + // router, + // }) + // } + // describe('given a post', () => { + // beforeEach(() => { + // // propsData = { + // // type: 'contribution', + // // id: 'p23', + // // name: 'It is a post', + // // // callbacks: { + // // // confirm: () => Post.methods.deletePostCallback('list'), + // // // cancel: null + // // // } + // // } + // mocks = { + // ...mocks, + // post: { + // id: 'p23', + // name: 'It is a post', + // }, + // } // }) - // describe('given a post', () => { - // beforeEach(() => { - // propsData = { - // type: 'contribution', - // id: 'p23', - // name: 'It is a post' - // // callbacks: { - // // confirm: () => Post.methods.deletePostCallback('list'), - // // cancel: null - // // } - // } + // it('mentions post title', () => { + // wrapper = Wrapper() + // wrapper.vm.deletePostCallback('list') + + // console.log('mocks.$t: ', mocks.$t) + // const calls = mocks.$t.mock.calls + // const expected = [ + // [ + // 'delete.contribution.message', + // { + // name: 'It is a post', + // }, + // ], + // ] + // expect(calls).toEqual(expect.arrayContaining(expected)) + // }) // }) - // it('mentions post title', () => { - // Wrapper() - // const calls = mocks.$t.mock.calls - // const expected = [ - // ['delete.contribution.message', { name: 'It is a post' }] - // ] - // expect(calls).toEqual(expect.arrayContaining(expected)) - // }) + // // describe('given a comment', () => { + // // beforeEach(() => { + // // propsData = { + // // type: 'comment', + // // id: 'c3', + // // name: 'It is the user of the comment' + // // // callbacks: { + // // // confirm: () => Post.methods.deletePostCallback('list'), + // // // cancel: null + // // // } + // // } + // // }) + + // // it('mentions comments user name', () => { + // // Wrapper() + // // const calls = mocks.$t.mock.calls + // // const expected = [ + // // ['delete.comment.message', { name: 'It is the user of the comment' }] + // // ] + // // expect(calls).toEqual(expect.arrayContaining(expected)) + // // }) + // // }) // }) - // describe('given a comment', () => { - // beforeEach(() => { - // propsData = { - // type: 'comment', - // id: 'c3', - // name: 'It is the user of the comment' - // // callbacks: { - // // confirm: () => Post.methods.deletePostCallback('list'), - // // cancel: null - // // } - // } - // }) - - // it('mentions comments user name', () => { - // Wrapper() - // const calls = mocks.$t.mock.calls - // const expected = [ - // ['delete.comment.message', { name: 'It is the user of the comment' }] - // ] - // expect(calls).toEqual(expect.arrayContaining(expected)) - // }) - // }) - // }) - describe('mount', () => { Wrapper = () => { - return mount(PostSlug, { propsData, mocks, localVue, router }) + return mount(PostSlug, { + propsData, + mocks, + localVue, + router, + }) } beforeEach(jest.useFakeTimers) @@ -115,20 +140,40 @@ describe('PostSlug', () => { expect(Wrapper().is('div')).toBe(true) }) - describe('given post id', () => { + describe('test mixin "PostMutationHelpers"', () => { beforeEach(() => { - // post = { - // id: 'p23' - // } wrapper = Wrapper() }) - describe('confirm deletion of Post from List by invoking "deletePostCallback"', () => { + describe('deletion of Post from List by invoking "deletePostCallback(`list`)"', () => { beforeEach(() => { - wrapper = Wrapper() wrapper.vm.deletePostCallback('list') }) + describe('after timeout', () => { + beforeEach(jest.runAllTimers) + + it('emits "deletePost"', () => { + expect(wrapper.emitted().deletePost).toBeTruthy() + }) + + it.todo('does not go to index (main) page') + // it('does not go to index (main) page', () => { + // expect(mocks.$router.history.push).not.toHaveBeenCalled() + // }) + + it('does call mutation', () => { + expect(mocks.$apollo.mutate).toHaveBeenCalledTimes(1) + // expect(mocks.$toast.success).toHaveBeenCalledTimes(1) + }) + }) + }) + + describe('deletion of Post from Page by invoking "deletePostCallback(`page`)"', () => { + beforeEach(() => { + wrapper.vm.deletePostCallback('page') + }) + describe('after timeout', () => { beforeEach(jest.runAllTimers) @@ -136,108 +181,21 @@ describe('PostSlug', () => { // expect(wrapper.vm.isOpen).toBe(false) // }) - it('emits "deletePost"', () => { - expect(wrapper.emitted().deletePost).toBeTruthy() + it('not emits "deletePost"', () => { + expect(wrapper.emitted().deletePost).toBeFalsy() }) + it.todo('does go to index (main) page') + // it('does go to index (main) page', () => { + // expect(mocks.$router.history.push).toHaveBeenCalled() + // }) + it('does call mutation', () => { expect(mocks.$apollo.mutate).toHaveBeenCalled() + // expect(mocks.$toast.success).toHaveBeenCalledTimes(1) }) }) }) - - // describe('click cancel button and do not delete the post', () => { - // beforeEach(() => { - // wrapper = Wrapper() - // wrapper.find('button.cancel').trigger('click') - // }) - - // describe('after timeout', () => { - // beforeEach(jest.runAllTimers) - - // it('fades away', () => { - // expect(wrapper.vm.isOpen).toBe(false) - // }) - - // it('emits "close"', () => { - // expect(wrapper.emitted().close).toBeTruthy() - // }) - - // it('does not call mutation', () => { - // expect(mocks.$apollo.mutate).not.toHaveBeenCalled() - // }) - // }) - // }) - - // describe('click confirm button and delete the post', () => { - // beforeEach(() => { - // wrapper.find('button.confirm').trigger('click') - // }) - - // it('calls delete mutation', () => { - // expect(mocks.$apollo.mutate).toHaveBeenCalled() - // }) - - // it('sets success', () => { - // expect(wrapper.vm.success).toBe(true) - // }) - - // it('displays a success message', () => { - // const calls = mocks.$t.mock.calls - // const expected = [['delete.contribution.success']] - // expect(calls).toEqual(expect.arrayContaining(expected)) - // }) - - // describe('after timeout', () => { - // beforeEach(jest.runAllTimers) - - // it('fades away', () => { - // expect(wrapper.vm.isOpen).toBe(false) - // }) - - // it('emits close', () => { - // expect(wrapper.emitted().close).toBeTruthy() - // }) - - // it('resets success', () => { - // expect(wrapper.vm.success).toBe(false) - // }) - // }) - // }) }) - - // describe('given comment id', () => { - // beforeEach(() => { - // propsData = { - // type: 'comment', - // id: 'c3' - // // callbacks: { - // // confirm: () => Post.methods.deletePostCallback('list'), - // // cancel: null - // // } - // } - // wrapper = Wrapper() - // }) - - // describe('click confirm button and delete the comment', () => { - // beforeEach(() => { - // wrapper.find('button.confirm').trigger('click') - // }) - - // it('calls delete mutation', () => { - // expect(mocks.$apollo.mutate).toHaveBeenCalled() - // }) - - // it('sets success', () => { - // expect(wrapper.vm.success).toBe(true) - // }) - - // it('displays a success message', () => { - // const calls = mocks.$t.mock.calls - // const expected = [['delete.comment.success']] - // expect(calls).toEqual(expect.arrayContaining(expected)) - // }) - // }) - // }) }) }) From ec1a24cbd31c29a5bd617519056f2aa2f18689cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Wed, 29 May 2019 13:18:18 +0200 Subject: [PATCH 15/38] Fix update incompatibility It seems that prettier supports vue in version `v1.15` and above. See: https://github.com/prettier/prettier/releases/tag/1.15.0 So I guess that interferes with the old vue linter rules in place. I graduated the vlue rule from `recommended` to `essential` and now running `yarn run lint --fix` is doing fine. --- webapp/.eslintrc.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/webapp/.eslintrc.js b/webapp/.eslintrc.js index 0400fe5f2..f5aa82c81 100644 --- a/webapp/.eslintrc.js +++ b/webapp/.eslintrc.js @@ -10,7 +10,7 @@ module.exports = { }, extends: [ 'standard', - 'plugin:vue/recommended', + 'plugin:vue/essential', 'plugin:prettier/recommended' ], // required to lint *.vue files @@ -25,7 +25,9 @@ module.exports = { 'no-console': ['error'], 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', 'vue/component-name-in-template-casing': ['error', 'kebab-case'], - 'prettier/prettier': ['error'], + 'prettier/prettier': ['error', { + htmlWhitespaceSensitivity: 'ignore' + }], // 'newline-per-chained-call': [2] } } From da0a4eabfc137056a18f6d972d0264d9c5d235fb Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" Date: Wed, 29 May 2019 11:30:33 +0000 Subject: [PATCH 16/38] Bump prettier from 1.14.3 to 1.17.1 in /webapp Bumps [prettier](https://github.com/prettier/prettier) from 1.14.3 to 1.17.1. - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md) - [Commits](https://github.com/prettier/prettier/compare/1.14.3...1.17.1) Signed-off-by: dependabot[bot] --- webapp/package.json | 2 +- webapp/yarn.lock | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/webapp/package.json b/webapp/package.json index b73b5cb3b..e2b151638 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -106,7 +106,7 @@ "jest": "~24.8.0", "node-sass": "~4.12.0", "nodemon": "~1.19.1", - "prettier": "~1.14.3", + "prettier": "~1.17.1", "sass-loader": "~7.1.0", "tippy.js": "^4.3.1", "vue-jest": "~3.0.4", diff --git a/webapp/yarn.lock b/webapp/yarn.lock index f2e45260c..3c6ad8347 100644 --- a/webapp/yarn.lock +++ b/webapp/yarn.lock @@ -8797,15 +8797,10 @@ prettier@1.16.3: resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.16.3.tgz#8c62168453badef702f34b45b6ee899574a6a65d" integrity sha512-kn/GU6SMRYPxUakNXhpP0EedT/KmaPzr0H5lIsDogrykbaxOpOfAFfk5XA7DZrJyMAv1wlMV3CPcZruGXVVUZw== -prettier@^1.15.2: - version "1.17.0" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.17.0.tgz#53b303676eed22cc14a9f0cec09b477b3026c008" - integrity sha512-sXe5lSt2WQlCbydGETgfm1YBShgOX4HxQkFPvbxkcwgDvGDeqVau8h+12+lmSVlP3rHPz0oavfddSZg/q+Szjw== - -prettier@~1.14.3: - version "1.14.3" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.14.3.tgz#90238dd4c0684b7edce5f83b0fb7328e48bd0895" - integrity sha512-qZDVnCrnpsRJJq5nSsiHCE3BYMED2OtsI+cmzIzF1QIfqm5ALf8tEJcO27zV1gKNKRPdhjO0dNWnrzssDQ1tFg== +prettier@^1.15.2, prettier@~1.17.1: + version "1.17.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.17.1.tgz#ed64b4e93e370cb8a25b9ef7fef3e4fd1c0995db" + integrity sha512-TzGRNvuUSmPgwivDqkZ9tM/qTGW9hqDKWOE9YHiyQdixlKbv7kvEqsmDPrcHJTKwthU774TQwZXVtaQ/mMsvjg== pretty-bytes@^5.2.0: version "5.2.0" From ff0b4b6867228d30e6f1c8281549b21f7b94150c Mon Sep 17 00:00:00 2001 From: Matt Rider Date: Wed, 29 May 2019 09:47:24 -0300 Subject: [PATCH 17/38] Fix lint --- webapp/components/Badges.vue | 19 +- webapp/components/Category/index.vue | 5 +- webapp/components/Comment.vue | 15 +- webapp/components/ContentMenu.vue | 29 +-- webapp/components/ContributionForm/index.vue | 32 +--- webapp/components/CountTo.vue | 5 +- webapp/components/Dropdown.vue | 13 +- webapp/components/Editor/index.vue | 16 +- webapp/components/Empty.vue | 15 +- webapp/components/Image/index.vue | 5 +- webapp/components/LoadMore.vue | 12 +- webapp/components/LocaleSwitch.vue | 22 +-- webapp/components/Modal/DeleteModal.vue | 30 +-- webapp/components/Modal/DisableModal.vue | 18 +- webapp/components/Modal/ReportModal.vue | 22 +-- webapp/components/Password/Change.vue | 6 +- webapp/components/Password/Strength.vue | 10 +- webapp/components/PostCard/index.vue | 33 +--- webapp/components/SearchInput.vue | 39 ++-- webapp/components/ShoutButton.vue | 18 +- webapp/components/User/index.vue | 73 ++----- .../components/comments/CommentForm/index.vue | 19 +- .../components/comments/CommentList/index.vue | 23 +-- .../notifications/Notification/index.vue | 22 +-- .../notifications/NotificationMenu/index.vue | 32 +--- webapp/layouts/default.vue | 60 ++---- webapp/nuxt.config.js | 36 ++-- webapp/pages/admin.vue | 10 +- webapp/pages/admin/categories.vue | 11 +- webapp/pages/admin/index.vue | 80 ++------ webapp/pages/admin/notifications.vue | 5 +- webapp/pages/admin/organizations.vue | 5 +- webapp/pages/admin/pages.vue | 5 +- webapp/pages/admin/settings.vue | 5 +- webapp/pages/admin/tags.vue | 11 +- webapp/pages/admin/users.vue | 5 +- webapp/pages/index.vue | 14 +- webapp/pages/login.vue | 42 ++-- webapp/pages/logout.vue | 30 +-- webapp/pages/moderation.vue | 5 +- webapp/pages/moderation/index.vue | 85 ++++----- webapp/pages/post/_id.vue | 10 +- webapp/pages/post/_id/_slug/index.vue | 35 +--- webapp/pages/post/_id/_slug/more-info.vue | 35 ++-- webapp/pages/post/_id/_slug/take-action.vue | 5 +- webapp/pages/post/create.vue | 5 +- webapp/pages/post/edit/_id.vue | 5 +- webapp/pages/profile/_id/_slug.vue | 180 ++++-------------- webapp/pages/settings.vue | 10 +- webapp/pages/settings/data-download.vue | 5 +- webapp/pages/settings/delete-account.vue | 5 +- webapp/pages/settings/index.vue | 13 +- webapp/pages/settings/invites.vue | 5 +- webapp/pages/settings/languages.vue | 5 +- webapp/pages/settings/my-organizations.vue | 5 +- webapp/pages/settings/my-social-media.vue | 36 +--- 56 files changed, 316 insertions(+), 985 deletions(-) diff --git a/webapp/components/Badges.vue b/webapp/components/Badges.vue index ff8a2bd35..40d323b2d 100644 --- a/webapp/components/Badges.vue +++ b/webapp/components/Badges.vue @@ -1,20 +1,7 @@ diff --git a/webapp/components/Category/index.vue b/webapp/components/Category/index.vue index 31c1aa97b..acc35772a 100644 --- a/webapp/components/Category/index.vue +++ b/webapp/components/Category/index.vue @@ -1,9 +1,6 @@ diff --git a/webapp/components/Comment.vue b/webapp/components/Comment.vue index dcad2a2ac..751a11f02 100644 --- a/webapp/components/Comment.vue +++ b/webapp/components/Comment.vue @@ -1,17 +1,11 @@ diff --git a/webapp/components/ContentMenu.vue b/webapp/components/ContentMenu.vue index a2e73b8af..6e5bca4c0 100644 --- a/webapp/components/ContentMenu.vue +++ b/webapp/components/ContentMenu.vue @@ -1,32 +1,13 @@