Add testing of toasters and cleanup

This commit is contained in:
Wolfgang Huß 2022-04-29 12:39:32 +02:00
parent f95c11e29a
commit a382385a68
6 changed files with 29 additions and 32 deletions

View File

@ -1,6 +1,5 @@
<template>
<div>
<!-- Header -->
<div class="header py-lg-6">
<b-container class="w-50">
<div class="header-body text-center mb-7">
@ -18,7 +17,6 @@
</div>
</b-container>
</div>
<!-- Page content -->
</div>
</template>

View File

@ -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', () => {

View File

@ -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'))
})
},
},

View File

@ -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')
})
})
})
})

View File

@ -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()
})

View File

@ -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()