get tests working, define default community in store with empty name and description

This commit is contained in:
Moriz Wahl 2021-10-28 11:32:59 +02:00
parent 8a8cccd540
commit 2ac675287c
4 changed files with 59 additions and 46 deletions

View File

@ -1,20 +1,24 @@
import { communityInfo } from '../graphql/queries' import { communityInfo } from '../graphql/queries'
export const getCommunityInfo = { export const getCommunityInfoMixin = {
beforeCreate() { methods: {
if (!this.$store.state.community) { getCommunityInfo() {
this.$apollo if (this.$store.state.community.name === '') {
.query({ this.$apollo
query: communityInfo, .query({
}) query: communityInfo,
.then((result) => { })
// console.log('Got a community info: ', result.data.getCommunityInfo) .then((result) => {
this.$store.commit('community', result.data.getCommunityInfo) this.$store.commit('community', result.data.getCommunityInfo)
}) return result.data.getCommunityInfo
.catch((error) => { })
// console.log('Got a error: ', error.message) .catch((error) => {
this.$toasted.error(error.message) this.$toasted.error(error.message)
}) })
} }
},
},
created() {
this.getCommunityInfo()
}, },
} }

View File

@ -89,7 +89,10 @@ export const store = new Vuex.Store({
token: null, token: null,
coinanimation: true, coinanimation: true,
newsletterState: null, newsletterState: null,
community: null, community: {
name: '',
description: '',
},
hasElopage: false, hasElopage: false,
publisherId: null, publisherId: null,
}, },

View File

@ -1,10 +1,10 @@
import { RouterLinkStub, mount } from '@vue/test-utils' import { RouterLinkStub, mount } from '@vue/test-utils'
import flushPromises from 'flush-promises' import flushPromises from 'flush-promises'
import Login from './Login' import Login from './Login'
import { getCommunityInfo } from '../../mixin/getCommunityInfo' import { getCommunityInfoMixin } from '../../mixin/getCommunityInfo'
const localVue = global.localVue const localVue = global.localVue
localVue.mixin(getCommunityInfo) localVue.mixin(getCommunityInfoMixin)
const apolloQueryMock = jest.fn().mockResolvedValue({ const apolloQueryMock = jest.fn().mockResolvedValue({
data: { data: {
@ -19,11 +19,7 @@ const apolloQueryMock = jest.fn().mockResolvedValue({
const toastErrorMock = jest.fn() const toastErrorMock = jest.fn()
const mockStoreDispach = jest.fn() const mockStoreDispach = jest.fn()
const mockStoreCommit = jest.fn((target, community) => { const mockStoreCommit = jest.fn()
// console.log('mockStoreCommit', global.$store.state.community)
global.$store.state[target] = community
// console.log('mockStoreCommit', global.$store.state.community)
})
const mockRouterPush = jest.fn() const mockRouterPush = jest.fn()
const spinnerHideMock = jest.fn() const spinnerHideMock = jest.fn()
const spinnerMock = 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', () => { describe('Login', () => {
let wrapper let wrapper
@ -55,15 +36,29 @@ describe('Login', () => {
locale: 'en', locale: 'en',
}, },
$t: jest.fn((t) => t), $t: jest.fn((t) => t),
$store: global.$store, $store: {
dispatch: mockStoreDispach,
commit: mockStoreCommit,
state: {
community: {
name: '',
description: '',
},
publisherId: 12345,
},
},
$loading: { $loading: {
show: spinnerMock, show: spinnerMock,
}, },
$router: { $router: {
push: mockRouterPush, push: mockRouterPush,
}, },
$toasted: global.$toasted, $toasted: {
$apollo: global.$apollo, error: toastErrorMock,
},
$apollo: {
query: apolloQueryMock,
},
} }
const stubs = { const stubs = {
@ -112,12 +107,23 @@ describe('Login', () => {
}) })
describe('Community Data', () => { 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', () => { 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', () => { 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.',
)
}) })
}) })

View File

@ -63,7 +63,7 @@
import InputPassword from '../../components/Inputs/InputPassword' import InputPassword from '../../components/Inputs/InputPassword'
import InputEmail from '../../components/Inputs/InputEmail' import InputEmail from '../../components/Inputs/InputEmail'
import { login } from '../../graphql/queries' import { login } from '../../graphql/queries'
import { getCommunityInfo } from '../../mixin/getCommunityInfo' import { getCommunityInfoMixin } from '../../mixin/getCommunityInfo'
export default { export default {
name: 'login', name: 'login',
@ -71,7 +71,7 @@ export default {
InputPassword, InputPassword,
InputEmail, InputEmail,
}, },
mixins: [getCommunityInfo], mixins: [getCommunityInfoMixin],
data() { data() {
return { return {
form: { form: {