Implement tests for Registration page

- Refactor little things.
This commit is contained in:
Wolfgang Huß 2022-04-26 15:40:34 +02:00
parent 9b536e8ba6
commit 4d87c95031
5 changed files with 58 additions and 25 deletions

View File

@ -33,7 +33,7 @@ export default {
subtitle: { type: String, required: true },
buttonText: { type: String, required: false, default: null },
linkTo: { type: String, required: false, default: null },
callback: { type: Function, required: false, default: () => {} },
callback: { type: Function, required: false, default: null },
code: { type: String, required: false, default: null }, // Wolle: to be removed by adding it directly to the "linkTo"
},
}

View File

@ -117,6 +117,7 @@ describe('ForgotPassword', () => {
})
it('shows error title, subtitle, login button', () => {
expect(wrapper.vm.showPageMessage).toBeTruthy()
expect(wrapper.find('.test-message-headline').text()).toBe('site.thx.errorTitle')
expect(wrapper.find('.test-message-subtitle').text()).toBe('error.email-already-sent')
expect(wrapper.find('.test-message-button').text()).toBe('login')
@ -127,8 +128,10 @@ describe('ForgotPassword', () => {
})
// Wolle
it.skip('click redirects to "/login"', () => {
// expect(mockRouterPush).toBeCalledWith('/login')
it.skip('click redirects to "/login"', async () => {
// wrapper.find('.test-message-button').trigger('click')
// await wrapper.vm.$nextTick()
expect(mockRouterPush).toBeCalledWith('/login')
})
})
@ -146,6 +149,7 @@ describe('ForgotPassword', () => {
})
it('shows success title, subtitle, login button', () => {
expect(wrapper.vm.showPageMessage).toBeTruthy()
expect(wrapper.find('.test-message-headline').text()).toBe('site.thx.title')
expect(wrapper.find('.test-message-subtitle').text()).toBe('site.thx.email')
expect(wrapper.find('.test-message-button').text()).toBe('login')

View File

@ -240,12 +240,13 @@ describe('Login', () => {
})
it('shows error title, subtitle, login button', () => {
expect(wrapper.vm.showPageMessage).toBeTruthy()
expect(wrapper.find('.test-message-headline').text()).toBe('site.thx.errorTitle')
expect(wrapper.find('.test-message-subtitle').text()).toBe('site.thx.activateEmail')
expect(wrapper.find('.test-message-button').text()).toBe('settings.password.reset')
})
it('button link directs to "/forgot-password', () => {
it('button link directs to "/forgot-password"', () => {
expect(wrapper.find('.test-message-button').attributes('href')).toBe('/forgot-password')
})
@ -270,12 +271,13 @@ describe('Login', () => {
})
it('shows error title, subtitle, login button', () => {
expect(wrapper.vm.showPageMessage).toBeTruthy()
expect(wrapper.find('.test-message-headline').text()).toBe('site.thx.errorTitle')
expect(wrapper.find('.test-message-subtitle').text()).toBe('site.thx.unsetPassword')
expect(wrapper.find('.test-message-button').text()).toBe('settings.password.reset')
})
it('button link directs to "/reset-password/login', () => {
it('button link directs to "/reset-password/login"', () => {
expect(wrapper.find('.test-message-button').attributes('href')).toBe(
'/reset-password/login',
)

View File

@ -221,41 +221,59 @@ describe('Register', () => {
describe('server sends back error', () => {
beforeEach(async () => {
registerUserMutationMock.mockRejectedValue({ message: 'Ouch!' })
registerUserMutationMock.mockRejectedValue({
message: 'GraphQL error: User already exists.',
})
await wrapper.find('form').trigger('submit')
await flushPromises()
})
it('shows error message', () => {
expect(wrapper.find('span.alert-text').exists()).toBeTruthy()
expect(wrapper.find('span.alert-text').text().length !== 0).toBeTruthy()
expect(wrapper.find('span.alert-text').text()).toContain('error.error')
expect(wrapper.find('span.alert-text').text()).toContain('Ouch!')
// Wolle: remove?
// it('shows error message', () => {
// expect(wrapper.find('span.alert-text').exists()).toBeTruthy()
// expect(wrapper.find('span.alert-text').text().length !== 0).toBeTruthy()
// expect(wrapper.find('span.alert-text').text()).toContain('error.error')
// expect(wrapper.find('span.alert-text').text()).toContain('Ouch!')
// })
// it('button to dismisses error message is present', () => {
// expect(wrapper.find('button.close').exists()).toBeTruthy()
// })
// it('dismisses error message', async () => {
// await wrapper.find('button.close').trigger('click')
// await flushPromises()
// expect(wrapper.find('span.alert-text').exists()).not.toBeTruthy()
// })
it('shows success title, subtitle, login button', () => {
expect(wrapper.vm.showPageMessage).toBeTruthy()
expect(wrapper.find('.test-message-headline').text()).toBe('site.thx.errorTitle')
expect(wrapper.find('.test-message-subtitle').text()).toBe('error.user-already-exists')
expect(wrapper.find('.test-message-button').text()).toBe(
'site.register.message-button-text',
)
})
it('button to dismisses error message is present', () => {
expect(wrapper.find('button.close').exists()).toBeTruthy()
})
it('dismisses error message', async () => {
await wrapper.find('button.close').trigger('click')
await flushPromises()
expect(wrapper.find('span.alert-text').exists()).not.toBeTruthy()
it('click calls "solveError"', async () => {
wrapper.find('.test-message-button').trigger('click')
await wrapper.vm.$nextTick()
expect(wrapper.vm.showPageMessage).not.toBeTruthy()
})
})
describe('server sends back success', () => {
beforeEach(() => {
beforeEach(async () => {
registerUserMutationMock.mockResolvedValue({
data: {
create: 'success',
},
})
})
it('routes to "/thx/register"', async () => {
await wrapper.find('form').trigger('submit')
await flushPromises()
})
it('submit sends apollo mutate', () => {
expect(registerUserMutationMock).toBeCalledWith(
expect.objectContaining({
variables: {
@ -267,7 +285,16 @@ describe('Register', () => {
},
}),
)
expect(routerPushMock).toHaveBeenCalledWith('/thx/register')
})
it('shows success title, subtitle', () => {
expect(wrapper.vm.showPageMessage).toBeTruthy()
expect(wrapper.find('.test-message-headline').text()).toBe('site.thx.title')
expect(wrapper.find('.test-message-subtitle').text()).toBe('site.thx.register')
})
it('button is not present', () => {
expect(wrapper.find('.test-message-button')).toBeTruthy()
})
})
})

View File

@ -105,6 +105,7 @@
</b-form-checkbox>
</b-col>
</b-row>
<!-- Wolle: remove this? or shall the alert or a toaster be shown? -->
<b-alert
v-if="showError"
show
@ -183,7 +184,6 @@
v-if="success"
:headline="$t('site.thx.title')"
:subtitle="$t('site.thx.register')"
:buttonText="$t('site.login.signin')"
/>
<message
v-else