diff --git a/frontend/src/components/Message/Message.vue b/frontend/src/components/Message/Message.vue index d9afbd480..cc3bb90a3 100644 --- a/frontend/src/components/Message/Message.vue +++ b/frontend/src/components/Message/Message.vue @@ -1,6 +1,5 @@ diff --git a/frontend/src/pages/ForgotPassword.spec.js b/frontend/src/pages/ForgotPassword.spec.js index a7b2b5393..c6c798e22 100644 --- a/frontend/src/pages/ForgotPassword.spec.js +++ b/frontend/src/pages/ForgotPassword.spec.js @@ -1,5 +1,6 @@ import { mount, RouterLinkStub } from '@vue/test-utils' import flushPromises from 'flush-promises' +import { toastErrorSpy } from '@test/testSetup' import ForgotPassword from './ForgotPassword' const mockAPIcall = jest.fn() @@ -132,6 +133,10 @@ describe('ForgotPassword', () => { // await wrapper.vm.$nextTick() expect(mockRouterPush).toBeCalledWith('/login') }) + + it('toasts a standard error message', () => { + expect(toastErrorSpy).toBeCalledWith('error.email-already-sent') + }) }) describe('success', () => { diff --git a/frontend/src/pages/ForgotPassword.vue b/frontend/src/pages/ForgotPassword.vue index 1778c638c..eea54427a 100644 --- a/frontend/src/pages/ForgotPassword.vue +++ b/frontend/src/pages/ForgotPassword.vue @@ -89,9 +89,9 @@ export default { this.success = true }) .catch(() => { - this.toastError(this.$t('error.email-already-sent')) this.showPageMessage = true this.success = false + this.toastError(this.$t('error.email-already-sent')) }) }, }, diff --git a/frontend/src/pages/Login.spec.js b/frontend/src/pages/Login.spec.js index b03f24fb2..36c293451 100644 --- a/frontend/src/pages/Login.spec.js +++ b/frontend/src/pages/Login.spec.js @@ -1,8 +1,7 @@ import { RouterLinkStub, mount } from '@vue/test-utils' import flushPromises from 'flush-promises' -import Login from './Login' - import { toastErrorSpy } from '@test/testSetup' +import Login from './Login' const localVue = global.localVue @@ -205,32 +204,10 @@ describe('Login', () => { }) describe('login fails', () => { - beforeEach(async () => { - jest.clearAllMocks() - await wrapper.find('input[placeholder="Email"]').setValue('user@example.org') - await wrapper.find('input[placeholder="form.password"]').setValue('1234') - await flushPromises() - apolloQueryMock.mockRejectedValue({ - message: '...No user with this credentials', - }) - await wrapper.find('form').trigger('submit') - await flushPromises() - }) - - it('hides the spinner', () => { - expect(spinnerHideMock).toBeCalled() - }) - - it('toasts an error message', () => { - expect(toastErrorSpy).toBeCalledWith( - 'error.unknown-error...No user with this credentials', - ) - }) - describe('login fails with "User email not validated"', () => { beforeEach(async () => { apolloQueryMock.mockRejectedValue({ - message: 'User email not validated', + message: 'GraphQL error: User email not validated', }) wrapper = Wrapper() jest.clearAllMocks() @@ -241,6 +218,10 @@ describe('Login', () => { await flushPromises() }) + it('hides the spinner', () => { + expect(spinnerHideMock).toBeCalled() + }) + it('shows error title, subtitle, login button', () => { expect(wrapper.vm.showPageMessage).toBeTruthy() expect(wrapper.find('.test-message-headline').text()).toBe('site.thx.errorTitle') @@ -255,12 +236,16 @@ describe('Login', () => { it.skip('click redirects to "/forgot-password"', () => { // expect(mockRouterPush).toBeCalledWith('/thx/login') }) + + it('toasts the error message', () => { + expect(toastErrorSpy).toBeCalledWith('error.no-account') + }) }) describe('login fails with "User has no password set yet"', () => { beforeEach(async () => { apolloQueryMock.mockRejectedValue({ - message: 'User has no password set yet', + message: 'GraphQL error: User has no password set yet', }) wrapper = Wrapper() jest.clearAllMocks() @@ -287,6 +272,10 @@ describe('Login', () => { it.skip('click redirects to "/reset-password/login"', () => { // expect(mockRouterPush).toBeCalledWith('/reset-password/login') }) + + it('toasts the error message', () => { + expect(toastErrorSpy).toBeCalledWith('error.no-account') + }) }) }) }) diff --git a/frontend/src/pages/Login.vue b/frontend/src/pages/Login.vue index 0bbfe6afc..4cfd62e69 100755 --- a/frontend/src/pages/Login.vue +++ b/frontend/src/pages/Login.vue @@ -125,22 +125,22 @@ export default { }) .catch((error) => { if (error.message.includes('User email not validated')) { - this.toastError(this.$t('error.no-account')) this.showPageMessage = true this.errorSubtitle = this.$t('site.thx.activateEmail') this.errorLinkTo = '/forgot-password' - } else if (error.message.includes('User has no password set yet')) { this.toastError(this.$t('error.no-account')) + } else if (error.message.includes('User has no password set yet')) { this.showPageMessage = true this.errorSubtitle = this.$t('site.thx.unsetPassword') this.errorLinkTo = '/reset-password/login' + this.toastError(this.$t('error.no-account')) } else { // appeared errors: 'GraphQL error: No user with this credentials' const errorMessage = this.$t('error.unknown-error') + error.message - this.toastError(errorMessage) this.showPageMessage = true this.errorSubtitle = errorMessage this.errorLinkTo = '/forgot-password' + this.toastError(errorMessage) } loader.hide() }) diff --git a/frontend/src/pages/Register.spec.js b/frontend/src/pages/Register.spec.js index 35ed534c2..49984c008 100644 --- a/frontend/src/pages/Register.spec.js +++ b/frontend/src/pages/Register.spec.js @@ -1,5 +1,6 @@ import { mount, RouterLinkStub } from '@vue/test-utils' import flushPromises from 'flush-promises' +import { toastErrorSpy } from '@test/testSetup' import Register from './Register' const localVue = global.localVue @@ -237,6 +238,10 @@ describe('Register', () => { ) }) + it('toasts the error message', () => { + expect(toastErrorSpy).toBeCalledWith('error.user-already-exists') + }) + it('click calls "solveError"', async () => { wrapper.find('.test-message-button').trigger('click') await wrapper.vm.$nextTick()