mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
get tests working, define default community in store with empty name and description
This commit is contained in:
parent
8a8cccd540
commit
2ac675287c
@ -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()
|
||||
},
|
||||
}
|
||||
|
||||
@ -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,
|
||||
},
|
||||
|
||||
@ -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.',
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -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: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user