From 35b01d90107aea8ba2bd5124c9e90804d4243a4f Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 25 Oct 2021 10:53:56 +0200 Subject: [PATCH 01/21] Change the register site so that it loads community information if their is none. --- frontend/src/views/Pages/Register.vue | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/frontend/src/views/Pages/Register.vue b/frontend/src/views/Pages/Register.vue index ff83f84fc..d7909c964 100755 --- a/frontend/src/views/Pages/Register.vue +++ b/frontend/src/views/Pages/Register.vue @@ -161,6 +161,7 @@ import InputEmail from '../../components/Inputs/InputEmail.vue' import InputPasswordConfirmation from '../../components/Inputs/InputPasswordConfirmation.vue' import LanguageSwitchSelect from '../../components/LanguageSwitchSelect.vue' import { registerUser } from '../../graphql/mutations' +import { communityInfo } from '../../graphql/queries' export default { components: { InputPasswordConfirmation, InputEmail, LanguageSwitchSelect }, @@ -228,6 +229,20 @@ export default { this.form.password.passwordRepeat = '' this.language = '' }, + async onCreated() { + if (!this.$state.store.community) { + this.$apollo + .query({ + query: communityInfo, + }) + .then((result) => { + this.$store.commit('community', result.data.getCommunityInfo) + }) + .catch((error) => { + this.$toasted.error(error.message) + }) + } + }, }, computed: { namesFilled() { @@ -242,6 +257,9 @@ export default { return this.form.email !== '' }, }, + created() { + this.onCreated() + }, } From 5febfc337e09b57339aef4ff3ee6b65cd9c7ebb9 Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 25 Oct 2021 10:54:21 +0200 Subject: [PATCH 02/21] Changed the register community page so that it loads community informations if not provided. --- .../src/views/Pages/RegisterCommunity.vue | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/frontend/src/views/Pages/RegisterCommunity.vue b/frontend/src/views/Pages/RegisterCommunity.vue index 9512edd1a..94137e09c 100644 --- a/frontend/src/views/Pages/RegisterCommunity.vue +++ b/frontend/src/views/Pages/RegisterCommunity.vue @@ -49,12 +49,32 @@ From c0fc927c23f8cbb014e3434db649c772d5328cce Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 27 Oct 2021 15:37:04 +0200 Subject: [PATCH 03/21] Withdrew duplicate code and wrote a mixin for it. --- frontend/src/mixin/getCommunityInfo.js | 18 ++++++++++++++++++ frontend/src/views/Pages/Login.vue | 19 +++---------------- frontend/src/views/Pages/Register.vue | 20 ++------------------ 3 files changed, 23 insertions(+), 34 deletions(-) create mode 100644 frontend/src/mixin/getCommunityInfo.js diff --git a/frontend/src/mixin/getCommunityInfo.js b/frontend/src/mixin/getCommunityInfo.js new file mode 100644 index 000000000..b3feb1267 --- /dev/null +++ b/frontend/src/mixin/getCommunityInfo.js @@ -0,0 +1,18 @@ +import { communityInfo } from '../graphql/queries' + +export const getCommunityInfo = { + created() { + if (!this.$store.state.community) { + this.$apollo + .query({ + query: communityInfo, + }) + .then((result) => { + this.$store.commit('community', result.data.getCommunityInfo) + }) + .catch((error) => { + this.$toasted.error(error.message) + }) + } + }, +} diff --git a/frontend/src/views/Pages/Login.vue b/frontend/src/views/Pages/Login.vue index 0cdbeb942..9b50c9d71 100755 --- a/frontend/src/views/Pages/Login.vue +++ b/frontend/src/views/Pages/Login.vue @@ -62,7 +62,8 @@ diff --git a/frontend/src/views/Pages/Register.vue b/frontend/src/views/Pages/Register.vue index d7909c964..29b1f7dfb 100755 --- a/frontend/src/views/Pages/Register.vue +++ b/frontend/src/views/Pages/Register.vue @@ -161,11 +161,12 @@ import InputEmail from '../../components/Inputs/InputEmail.vue' import InputPasswordConfirmation from '../../components/Inputs/InputPasswordConfirmation.vue' import LanguageSwitchSelect from '../../components/LanguageSwitchSelect.vue' import { registerUser } from '../../graphql/mutations' -import { communityInfo } from '../../graphql/queries' +import { getCommunityInfo } from '../../mixin/getCommunityInfo' export default { components: { InputPasswordConfirmation, InputEmail, LanguageSwitchSelect }, name: 'register', + mixins: [getCommunityInfo], data() { return { form: { @@ -229,20 +230,6 @@ export default { this.form.password.passwordRepeat = '' this.language = '' }, - async onCreated() { - if (!this.$state.store.community) { - this.$apollo - .query({ - query: communityInfo, - }) - .then((result) => { - this.$store.commit('community', result.data.getCommunityInfo) - }) - .catch((error) => { - this.$toasted.error(error.message) - }) - } - }, }, computed: { namesFilled() { @@ -257,9 +244,6 @@ export default { return this.form.email !== '' }, }, - created() { - this.onCreated() - }, } From cb799ea925864d1c852db6a685b007c1a618fd5f Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 28 Oct 2021 06:50:16 +0200 Subject: [PATCH 04/21] Added mixin to the register community page. --- .../src/views/Pages/RegisterCommunity.vue | 23 +++---------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/frontend/src/views/Pages/RegisterCommunity.vue b/frontend/src/views/Pages/RegisterCommunity.vue index 94137e09c..4b4dff84c 100644 --- a/frontend/src/views/Pages/RegisterCommunity.vue +++ b/frontend/src/views/Pages/RegisterCommunity.vue @@ -49,32 +49,15 @@ From 8a8cccd540852247b4be08ecc81b83e67427ff26 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 28 Oct 2021 10:34:44 +0200 Subject: [PATCH 05/21] [WIP] Test that the mixin does the work. --- frontend/src/mixin/getCommunityInfo.js | 4 +- frontend/src/views/Pages/Login.spec.js | 61 ++++++++++++++------------ 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/frontend/src/mixin/getCommunityInfo.js b/frontend/src/mixin/getCommunityInfo.js index b3feb1267..8c45513dc 100644 --- a/frontend/src/mixin/getCommunityInfo.js +++ b/frontend/src/mixin/getCommunityInfo.js @@ -1,16 +1,18 @@ import { communityInfo } from '../graphql/queries' export const getCommunityInfo = { - created() { + beforeCreate() { if (!this.$store.state.community) { this.$apollo .query({ query: communityInfo, }) .then((result) => { + // console.log('Got a community info: ', result.data.getCommunityInfo) this.$store.commit('community', result.data.getCommunityInfo) }) .catch((error) => { + // console.log('Got a error: ', error.message) this.$toasted.error(error.message) }) } diff --git a/frontend/src/views/Pages/Login.spec.js b/frontend/src/views/Pages/Login.spec.js index 13d12df85..83558d076 100644 --- a/frontend/src/views/Pages/Login.spec.js +++ b/frontend/src/views/Pages/Login.spec.js @@ -1,8 +1,10 @@ -import { mount, RouterLinkStub } from '@vue/test-utils' +import { RouterLinkStub, mount } from '@vue/test-utils' import flushPromises from 'flush-promises' import Login from './Login' +import { getCommunityInfo } from '../../mixin/getCommunityInfo' const localVue = global.localVue +localVue.mixin(getCommunityInfo) const apolloQueryMock = jest.fn().mockResolvedValue({ data: { @@ -17,7 +19,11 @@ const apolloQueryMock = jest.fn().mockResolvedValue({ const toastErrorMock = jest.fn() const mockStoreDispach = jest.fn() -const mockStoreCommit = jest.fn() +const mockStoreCommit = jest.fn((target, community) => { + // console.log('mockStoreCommit', global.$store.state.community) + global.$store.state[target] = community + // console.log('mockStoreCommit', global.$store.state.community) +}) const mockRouterPush = jest.fn() const spinnerHideMock = jest.fn() const spinnerMock = jest.fn(() => { @@ -26,6 +32,21 @@ const spinnerMock = jest.fn(() => { } }) +global.$store = { + dispatch: mockStoreDispach, + commit: mockStoreCommit, + state: { + community: null, + publisherId: 12345, + }, +} +global.$toasted = { + error: toastErrorMock, +} +global.$apollo = { + query: apolloQueryMock, +} + describe('Login', () => { let wrapper @@ -34,31 +55,15 @@ describe('Login', () => { locale: 'en', }, $t: jest.fn((t) => t), - $store: { - dispatch: mockStoreDispach, - commit: mockStoreCommit, - state: { - community: { - name: 'Gradido Entwicklung', - url: 'http://localhost/vue/', - registerUrl: 'http://localhost/vue/register', - description: 'Die lokale Entwicklungsumgebung von Gradido.', - }, - publisherId: 12345, - }, - }, + $store: global.$store, $loading: { show: spinnerMock, }, $router: { push: mockRouterPush, }, - $toasted: { - error: toastErrorMock, - }, - $apollo: { - query: apolloQueryMock, - }, + $toasted: global.$toasted, + $apollo: global.$apollo, } const stubs = { @@ -74,10 +79,6 @@ describe('Login', () => { wrapper = Wrapper() }) - it('renders the Login form', () => { - expect(wrapper.find('div.login-form').exists()).toBeTruthy() - }) - it('commits the community info to the store', () => { expect(mockStoreCommit).toBeCalledWith('community', { name: 'test12', @@ -87,6 +88,10 @@ describe('Login', () => { }) }) + it('renders the Login form', () => { + expect(wrapper.find('div.login-form').exists()).toBeTruthy() + }) + describe('communities gives back error', () => { beforeEach(() => { apolloQueryMock.mockRejectedValue({ @@ -108,13 +113,11 @@ describe('Login', () => { describe('Community Data', () => { it('has a Community name', () => { - expect(wrapper.find('.test-communitydata b').text()).toBe('Gradido Entwicklung') + expect(wrapper.find('.test-communitydata b').text()).toBe('test12') }) it('has a Community description', () => { - expect(wrapper.find('.test-communitydata p').text()).toBe( - 'Die lokale Entwicklungsumgebung von Gradido.', - ) + expect(wrapper.find('.test-communitydata p').text()).toBe('test community 12') }) }) From 2ac675287c8cee8d99b2bbd96fea29bfba1a269b Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 28 Oct 2021 11:32:59 +0200 Subject: [PATCH 06/21] get tests working, define default community in store with empty name and description --- frontend/src/mixin/getCommunityInfo.js | 36 +++++++++------- frontend/src/store/store.js | 5 ++- frontend/src/views/Pages/Login.spec.js | 60 ++++++++++++++------------ frontend/src/views/Pages/Login.vue | 4 +- 4 files changed, 59 insertions(+), 46 deletions(-) diff --git a/frontend/src/mixin/getCommunityInfo.js b/frontend/src/mixin/getCommunityInfo.js index 8c45513dc..f8fda6e45 100644 --- a/frontend/src/mixin/getCommunityInfo.js +++ b/frontend/src/mixin/getCommunityInfo.js @@ -1,20 +1,24 @@ import { communityInfo } from '../graphql/queries' -export const getCommunityInfo = { - beforeCreate() { - if (!this.$store.state.community) { - this.$apollo - .query({ - query: communityInfo, - }) - .then((result) => { - // console.log('Got a community info: ', result.data.getCommunityInfo) - this.$store.commit('community', result.data.getCommunityInfo) - }) - .catch((error) => { - // console.log('Got a error: ', error.message) - this.$toasted.error(error.message) - }) - } +export const getCommunityInfoMixin = { + methods: { + getCommunityInfo() { + if (this.$store.state.community.name === '') { + this.$apollo + .query({ + query: communityInfo, + }) + .then((result) => { + this.$store.commit('community', result.data.getCommunityInfo) + return result.data.getCommunityInfo + }) + .catch((error) => { + this.$toasted.error(error.message) + }) + } + }, + }, + created() { + this.getCommunityInfo() }, } diff --git a/frontend/src/store/store.js b/frontend/src/store/store.js index 9f87f0398..6a229c161 100644 --- a/frontend/src/store/store.js +++ b/frontend/src/store/store.js @@ -89,7 +89,10 @@ export const store = new Vuex.Store({ token: null, coinanimation: true, newsletterState: null, - community: null, + community: { + name: '', + description: '', + }, hasElopage: false, publisherId: null, }, diff --git a/frontend/src/views/Pages/Login.spec.js b/frontend/src/views/Pages/Login.spec.js index 83558d076..60abf8821 100644 --- a/frontend/src/views/Pages/Login.spec.js +++ b/frontend/src/views/Pages/Login.spec.js @@ -1,10 +1,10 @@ import { RouterLinkStub, mount } from '@vue/test-utils' import flushPromises from 'flush-promises' import Login from './Login' -import { getCommunityInfo } from '../../mixin/getCommunityInfo' +import { getCommunityInfoMixin } from '../../mixin/getCommunityInfo' const localVue = global.localVue -localVue.mixin(getCommunityInfo) +localVue.mixin(getCommunityInfoMixin) const apolloQueryMock = jest.fn().mockResolvedValue({ data: { @@ -19,11 +19,7 @@ const apolloQueryMock = jest.fn().mockResolvedValue({ const toastErrorMock = jest.fn() const mockStoreDispach = jest.fn() -const mockStoreCommit = jest.fn((target, community) => { - // console.log('mockStoreCommit', global.$store.state.community) - global.$store.state[target] = community - // console.log('mockStoreCommit', global.$store.state.community) -}) +const mockStoreCommit = jest.fn() const mockRouterPush = jest.fn() const spinnerHideMock = jest.fn() const spinnerMock = jest.fn(() => { @@ -32,21 +28,6 @@ const spinnerMock = jest.fn(() => { } }) -global.$store = { - dispatch: mockStoreDispach, - commit: mockStoreCommit, - state: { - community: null, - publisherId: 12345, - }, -} -global.$toasted = { - error: toastErrorMock, -} -global.$apollo = { - query: apolloQueryMock, -} - describe('Login', () => { let wrapper @@ -55,15 +36,29 @@ describe('Login', () => { locale: 'en', }, $t: jest.fn((t) => t), - $store: global.$store, + $store: { + dispatch: mockStoreDispach, + commit: mockStoreCommit, + state: { + community: { + name: '', + description: '', + }, + publisherId: 12345, + }, + }, $loading: { show: spinnerMock, }, $router: { push: mockRouterPush, }, - $toasted: global.$toasted, - $apollo: global.$apollo, + $toasted: { + error: toastErrorMock, + }, + $apollo: { + query: apolloQueryMock, + }, } const stubs = { @@ -112,12 +107,23 @@ describe('Login', () => { }) describe('Community Data', () => { + beforeEach(() => { + mocks.$store.state.community = { + name: 'Gradido Entwicklung', + url: 'http://localhost/vue/', + registerUrl: 'http://localhost/vue/register', + description: 'Die lokale Entwicklungsumgebung von Gradido.', + } + }) + it('has a Community name', () => { - expect(wrapper.find('.test-communitydata b').text()).toBe('test12') + expect(wrapper.find('.test-communitydata b').text()).toBe('Gradido Entwicklung') }) it('has a Community description', () => { - expect(wrapper.find('.test-communitydata p').text()).toBe('test community 12') + expect(wrapper.find('.test-communitydata p').text()).toBe( + 'Die lokale Entwicklungsumgebung von Gradido.', + ) }) }) diff --git a/frontend/src/views/Pages/Login.vue b/frontend/src/views/Pages/Login.vue index 9b50c9d71..0bb904983 100755 --- a/frontend/src/views/Pages/Login.vue +++ b/frontend/src/views/Pages/Login.vue @@ -63,7 +63,7 @@ import InputPassword from '../../components/Inputs/InputPassword' import InputEmail from '../../components/Inputs/InputEmail' import { login } from '../../graphql/queries' -import { getCommunityInfo } from '../../mixin/getCommunityInfo' +import { getCommunityInfoMixin } from '../../mixin/getCommunityInfo' export default { name: 'login', @@ -71,7 +71,7 @@ export default { InputPassword, InputEmail, }, - mixins: [getCommunityInfo], + mixins: [getCommunityInfoMixin], data() { return { form: { From 36374b968f71c073979e0dfc41202afa2a460e72 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 28 Oct 2021 11:39:07 +0200 Subject: [PATCH 07/21] apply get community info mixin in all Register Components --- frontend/src/views/Pages/Register.vue | 4 ++-- frontend/src/views/Pages/RegisterCommunity.vue | 8 ++------ frontend/src/views/Pages/RegisterSelectCommunity.vue | 2 ++ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/frontend/src/views/Pages/Register.vue b/frontend/src/views/Pages/Register.vue index 29b1f7dfb..6655cfa7d 100755 --- a/frontend/src/views/Pages/Register.vue +++ b/frontend/src/views/Pages/Register.vue @@ -161,12 +161,12 @@ import InputEmail from '../../components/Inputs/InputEmail.vue' import InputPasswordConfirmation from '../../components/Inputs/InputPasswordConfirmation.vue' import LanguageSwitchSelect from '../../components/LanguageSwitchSelect.vue' import { registerUser } from '../../graphql/mutations' -import { getCommunityInfo } from '../../mixin/getCommunityInfo' +import { getCommunityInfoMixin } from '../../mixin/getCommunityInfo' export default { components: { InputPasswordConfirmation, InputEmail, LanguageSwitchSelect }, name: 'register', - mixins: [getCommunityInfo], + mixins: [getCommunityInfoMixin], data() { return { form: { diff --git a/frontend/src/views/Pages/RegisterCommunity.vue b/frontend/src/views/Pages/RegisterCommunity.vue index 4b4dff84c..19a90ca5f 100644 --- a/frontend/src/views/Pages/RegisterCommunity.vue +++ b/frontend/src/views/Pages/RegisterCommunity.vue @@ -49,15 +49,11 @@ diff --git a/frontend/src/views/Pages/RegisterSelectCommunity.vue b/frontend/src/views/Pages/RegisterSelectCommunity.vue index 0d3c25220..0a4b72462 100644 --- a/frontend/src/views/Pages/RegisterSelectCommunity.vue +++ b/frontend/src/views/Pages/RegisterSelectCommunity.vue @@ -49,6 +49,7 @@