diff --git a/frontend/src/views/Pages/Register.spec.js b/frontend/src/views/Pages/Register.spec.js index 903c5f42d..40cb9097d 100644 --- a/frontend/src/views/Pages/Register.spec.js +++ b/frontend/src/views/Pages/Register.spec.js @@ -5,6 +5,19 @@ import Register from './Register' 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() const registerUserMutationMock = jest.fn() const routerPushMock = jest.fn() @@ -21,20 +34,23 @@ describe('Register', () => { }, $apollo: { mutate: registerUserMutationMock, + query: apolloQueryMock, }, $store: { + commit: mockStoreCommit, state: { email: 'peter@lustig.de', language: 'en', community: { - name: 'Gradido Entwicklung', - url: 'http://localhost/vue/', - registerUrl: 'http://localhost/vue/register', - description: 'Die lokale Entwicklungsumgebung von Gradido.', + name: '', + description: '', }, publisherId: 12345, }, }, + $toasted: { + error: toastErrorMock, + }, } const stubs = { @@ -50,6 +66,15 @@ describe('Register', () => { 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 Register form', () => { expect(wrapper.find('div#registerform').exists()).toBeTruthy() }) @@ -60,16 +85,48 @@ describe('Register', () => { }) }) + describe('communities gives back error', () => { + beforeEach(() => { + apolloQueryMock.mockRejectedValue({ + message: 'Failed to get communities', + }) + wrapper = Wrapper() + }) + + it('toasts an error message', () => { + expect(toastErrorMock).toBeCalledWith('Failed to get communities') + }) + }) + describe('Community Data', () => { - it('has a Community name?', () => { + 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?', () => { + it('has a Community description', () => { expect(wrapper.find('.test-communitydata p').text()).toBe( 'Die lokale Entwicklungsumgebung von Gradido.', ) }) + + it('does not update community data', () => { + expect(mockStoreCommit).not.toBeCalled() + }) + + it('does not update community data', () => { + expect(mockStoreCommit).not.toBeCalled() + }) }) describe('links', () => {