Test that the community calls are working properly.

This commit is contained in:
elweyn 2021-10-29 14:05:19 +02:00
parent fb3daf6e4c
commit c70038ec8f

View File

@ -3,6 +3,19 @@ import RegisterCommunity from './RegisterCommunity'
const localVue = global.localVue const localVue = global.localVue
const apolloQueryMock = jest.fn().mockResolvedValue({
data: {
getCommunityInfo: {
name: 'test12',
description: 'test community 12',
url: 'http://test12.test12/',
registerUrl: 'http://test12.test12/vue/register',
},
},
})
const toastErrorMock = jest.fn()
const mockStoreCommit = jest.fn()
describe('RegisterCommunity', () => { describe('RegisterCommunity', () => {
let wrapper let wrapper
@ -11,16 +24,21 @@ describe('RegisterCommunity', () => {
locale: 'en', locale: 'en',
}, },
$t: jest.fn((t) => t), $t: jest.fn((t) => t),
$apollo: {
query: apolloQueryMock,
},
$store: { $store: {
commit: mockStoreCommit,
state: { state: {
community: { community: {
name: 'Gradido Entwicklung', name: '',
url: 'http://localhost/vue/', description: '',
registerUrl: 'http://localhost/vue/register',
description: 'Die lokale Entwicklungsumgebung von Gradido.',
}, },
}, },
}, },
$toasted: {
error: toastErrorMock,
},
} }
const stubs = { const stubs = {
@ -36,23 +54,56 @@ describe('RegisterCommunity', () => {
wrapper = Wrapper() wrapper = Wrapper()
}) })
it('commits the community info to the store', () => {
expect(mockStoreCommit).toBeCalledWith('community', {
name: 'test12',
description: 'test community 12',
url: 'http://test12.test12/',
registerUrl: 'http://test12.test12/vue/register',
})
})
it('renders the Div Element "#register-community"', () => { it('renders the Div Element "#register-community"', () => {
expect(wrapper.find('div#register-community').exists()).toBeTruthy() expect(wrapper.find('div#register-community').exists()).toBeTruthy()
}) })
describe('Displaying the current community info', () => { describe('communities gives back error', () => {
it('has a current community name', () => { beforeEach(() => {
expect(wrapper.find('.header h1').text()).toBe('Gradido Entwicklung') apolloQueryMock.mockRejectedValue({
message: 'Failed to get communities',
})
wrapper = Wrapper()
}) })
it('has a current community description', () => { it('toasts an error message', () => {
expect(wrapper.find('.header p').text()).toBe( expect(toastErrorMock).toBeCalledWith('Failed to get communities')
})
})
describe('Community Data', () => {
beforeEach(() => {
jest.clearAllMocks()
mocks.$store.state.community = {
name: 'Gradido Entwicklung',
url: 'http://localhost/vue/',
registerUrl: 'http://localhost/vue/register',
description: 'Die lokale Entwicklungsumgebung von Gradido.',
}
wrapper = Wrapper()
})
it('has a Community name', () => {
expect(wrapper.find('.test-communitydata b').text()).toBe('Gradido Entwicklung')
})
it('has a Community description', () => {
expect(wrapper.find('.test-communitydata p').text()).toBe(
'Die lokale Entwicklungsumgebung von Gradido.', 'Die lokale Entwicklungsumgebung von Gradido.',
) )
}) })
it('has a current community location', () => { it('does not call community data update', () => {
expect(wrapper.find('.header p.community-location').text()).toBe('http://localhost/vue/') expect(apolloQueryMock).not.toBeCalled()
}) })
}) })