From fbf88d6d5bd4c6f3be754b3b7ffa53b97c89b255 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 11 Jan 2022 09:56:45 +0100 Subject: [PATCH 1/5] fix: Pass Language to Admin Interface --- admin/src/graphql/verifyLogin.js | 1 + admin/src/main.js | 2 +- admin/src/router/guards.js | 3 ++- admin/src/router/guards.test.js | 24 +++++++++++++++++------- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/admin/src/graphql/verifyLogin.js b/admin/src/graphql/verifyLogin.js index 553557f3c..ea08bb5b1 100644 --- a/admin/src/graphql/verifyLogin.js +++ b/admin/src/graphql/verifyLogin.js @@ -7,6 +7,7 @@ export const verifyLogin = gql` lastName isAdmin id + language } } ` diff --git a/admin/src/main.js b/admin/src/main.js index 2743e0f9a..c0004beca 100644 --- a/admin/src/main.js +++ b/admin/src/main.js @@ -42,7 +42,7 @@ Vue.use(Toasted, { }, }) -addNavigationGuards(router, store, apolloProvider.defaultClient) +addNavigationGuards(router, store, apolloProvider.defaultClient, i18n) new Vue({ moment, diff --git a/admin/src/router/guards.js b/admin/src/router/guards.js index 4ed6c8516..dd61e8657 100644 --- a/admin/src/router/guards.js +++ b/admin/src/router/guards.js @@ -1,7 +1,7 @@ import { verifyLogin } from '../graphql/verifyLogin' import CONFIG from '../config' -const addNavigationGuards = (router, store, apollo) => { +const addNavigationGuards = (router, store, apollo, i18n) => { // store token on `authenticate` router.beforeEach(async (to, from, next) => { if (to.path === '/authenticate' && to.query && to.query.token) { @@ -14,6 +14,7 @@ const addNavigationGuards = (router, store, apollo) => { .then((result) => { const moderator = result.data.verifyLogin if (moderator.isAdmin) { + i18n.locale = moderator.language store.commit('moderator', moderator) next({ path: '/' }) } else { diff --git a/admin/src/router/guards.test.js b/admin/src/router/guards.test.js index cd5b33e68..da4dd5969 100644 --- a/admin/src/router/guards.test.js +++ b/admin/src/router/guards.test.js @@ -6,9 +6,11 @@ const apolloQueryMock = jest.fn().mockResolvedValue({ data: { verifyLogin: { isAdmin: true, + language: 'de', }, }, }) +const i18nLocaleMock = jest.fn() const store = { commit: storeCommitMock, @@ -21,7 +23,11 @@ const apollo = { query: apolloQueryMock, } -addNavigationGuards(router, store, apollo) +const i18n = { + locale: i18nLocaleMock, +} + +addNavigationGuards(router, store, apollo, i18n) describe('navigation guards', () => { beforeEach(() => { @@ -33,19 +39,23 @@ describe('navigation guards', () => { const next = jest.fn() describe('with valid token and as admin', () => { - beforeEach(() => { - navGuard({ path: '/authenticate', query: { token: 'valid-token' } }, {}, next) + beforeEach(async () => { + await navGuard({ path: '/authenticate', query: { token: 'valid-token' } }, {}, next) }) - it('commits the token to the store', async () => { + it('commits the token to the store', () => { expect(storeCommitMock).toBeCalledWith('token', 'valid-token') }) - it('commits the moderator to the store', () => { - expect(storeCommitMock).toBeCalledWith('moderator', { isAdmin: true }) + it.skip('sets the locale', () => { + expect(i18nLocaleMock).toBeCalledWith('de') }) - it('redirects to /', async () => { + it('commits the moderator to the store', () => { + expect(storeCommitMock).toBeCalledWith('moderator', { isAdmin: true, language: 'de' }) + }) + + it('redirects to /', () => { expect(next).toBeCalledWith({ path: '/' }) }) }) From 370994b35323c7f8b1879bd88844476643e27b12 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 10 Jan 2022 13:45:38 +0100 Subject: [PATCH 2/5] get the tests running --- .../components/CreationTransactionListFormular.spec.js | 4 +--- admin/src/components/UserTable.spec.js | 9 +++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/admin/src/components/CreationTransactionListFormular.spec.js b/admin/src/components/CreationTransactionListFormular.spec.js index 9817d6b8f..1c7b81c25 100644 --- a/admin/src/components/CreationTransactionListFormular.spec.js +++ b/admin/src/components/CreationTransactionListFormular.spec.js @@ -58,9 +58,7 @@ const mocks = { query: apolloQueryMock, }, $toasted: { - global: { - error: toastedErrorMock, - }, + error: toastedErrorMock, }, } diff --git a/admin/src/components/UserTable.spec.js b/admin/src/components/UserTable.spec.js index 80bdf6047..e26a548cc 100644 --- a/admin/src/components/UserTable.spec.js +++ b/admin/src/components/UserTable.spec.js @@ -3,6 +3,9 @@ import UserTable from './UserTable.vue' const localVue = global.localVue +const apolloQueryMock = jest.fn() +apolloQueryMock.mockResolvedValue() + describe('UserTable', () => { let wrapper @@ -114,6 +117,12 @@ describe('UserTable', () => { }), } }), + $apollo: { + query: apolloQueryMock, + }, + $store: { + commit: jest.fn(), + }, } const Wrapper = (propsData) => { From a679b9042513a3630d0855a897faf4578afcec75 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 11 Jan 2022 10:03:57 +0100 Subject: [PATCH 3/5] get the user table test up again --- admin/src/components/CreationTransactionListFormular.spec.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/admin/src/components/CreationTransactionListFormular.spec.js b/admin/src/components/CreationTransactionListFormular.spec.js index 1c7b81c25..9817d6b8f 100644 --- a/admin/src/components/CreationTransactionListFormular.spec.js +++ b/admin/src/components/CreationTransactionListFormular.spec.js @@ -58,7 +58,9 @@ const mocks = { query: apolloQueryMock, }, $toasted: { - error: toastedErrorMock, + global: { + error: toastedErrorMock, + }, }, } From b244f31a533476221e38443e638a5f14f00eee10 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 11 Jan 2022 10:06:40 +0100 Subject: [PATCH 4/5] catch language when comming back from admin interface --- frontend/src/main.js | 2 +- frontend/src/routes/guards.js | 3 ++- frontend/src/routes/guards.test.js | 6 +++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/src/main.js b/frontend/src/main.js index edc9e575e..544dff66d 100755 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -28,7 +28,7 @@ Vue.toasted.register( loadAllRules(i18n) -addNavigationGuards(router, store, apolloProvider.defaultClient) +addNavigationGuards(router, store, apolloProvider.defaultClient, i18n) if (!store) { setTimeout( diff --git a/frontend/src/routes/guards.js b/frontend/src/routes/guards.js index 1838fa0fc..15d1eb5a1 100644 --- a/frontend/src/routes/guards.js +++ b/frontend/src/routes/guards.js @@ -1,6 +1,6 @@ import { verifyLogin } from '../graphql/queries' -const addNavigationGuards = (router, store, apollo) => { +const addNavigationGuards = (router, store, apollo, i18n) => { // handle publisherId router.beforeEach((to, from, next) => { const publisherId = to.query.pid @@ -21,6 +21,7 @@ const addNavigationGuards = (router, store, apollo) => { fetchPolicy: 'network-only', }) .then((result) => { + i18n.locale = result.data.verifyLogin.language store.dispatch('login', result.data.verifyLogin) next({ path: '/overview' }) }) diff --git a/frontend/src/routes/guards.test.js b/frontend/src/routes/guards.test.js index fa9f60f56..d4d2869d4 100644 --- a/frontend/src/routes/guards.test.js +++ b/frontend/src/routes/guards.test.js @@ -23,7 +23,11 @@ const apollo = { query: apolloQueryMock, } -addNavigationGuards(router, store, apollo) +const i18n = { + locale: jest.fn(), +} + +addNavigationGuards(router, store, apollo, i18n) describe('navigation guards', () => { beforeEach(() => { From dc8d838e004571009cbbd466eaeaabf1c0fb603d Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 11 Jan 2022 10:07:25 +0100 Subject: [PATCH 5/5] coverage admin interface 77% --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 15a736630..51f8e49b0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -470,7 +470,7 @@ jobs: report_name: Coverage Admin Interface type: lcov result_path: ./coverage/lcov.info - min_coverage: 76 + min_coverage: 77 token: ${{ github.token }} ##############################################################################