From 1c8e1df1b54bf85ade9b58e24b97493e1944c742 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 22 Mar 2022 20:11:34 +0100 Subject: [PATCH] 100% test of Reset Password, better naming of variables --- frontend/src/pages/ResetPassword.spec.js | 46 ++++++++++++++++++------ frontend/src/pages/ResetPassword.vue | 12 +++---- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/frontend/src/pages/ResetPassword.spec.js b/frontend/src/pages/ResetPassword.spec.js index f5d672c99..c43f71932 100644 --- a/frontend/src/pages/ResetPassword.spec.js +++ b/frontend/src/pages/ResetPassword.spec.js @@ -54,25 +54,27 @@ describe('ResetPassword', () => { describe('mount', () => { beforeEach(() => { + jest.clearAllMocks() wrapper = Wrapper() }) - describe('No valid optin', () => { - it.skip('does not render the Reset Password form when not authenticated', () => { - expect(wrapper.find('form').exists()).toBeFalsy() + describe('no valid optin', () => { + beforeEach(() => { + jest.clearAllMocks() + apolloQueryMock.mockRejectedValue({ message: 'Your time is up!' }) + wrapper = Wrapper() }) - it.skip('toasts an error when no valid optin is given', () => { - expect(toastErrorSpy).toHaveBeenCalledWith('error') + it('toasts an error when no valid optin is given', () => { + expect(toastErrorSpy).toHaveBeenCalledWith('Your time is up!') }) - it.skip('has a message suggesting to contact the support', () => { - expect(wrapper.find('div.header').text()).toContain('settings.password.reset') - expect(wrapper.find('div.header').text()).toContain('settings.password.not-authenticated') + it('redirects to /forgot-password/resetPassword', () => { + expect(routerPushMock).toBeCalledWith('/forgot-password/resetPassword') }) }) - describe('is authenticated', () => { + describe('valid optin', () => { it('renders the Reset Password form when authenticated', () => { expect(wrapper.find('div.resetpwd-form').exists()).toBeTruthy() }) @@ -148,7 +150,6 @@ describe('ResetPassword', () => { describe('server response with error code > 10min', () => { beforeEach(async () => { - jest.clearAllMocks() apolloMutationMock.mockRejectedValue({ message: '...Code is older than 10 minutes' }) await wrapper.find('form').trigger('submit') await flushPromises() @@ -163,7 +164,7 @@ describe('ResetPassword', () => { }) }) - describe('server response with error code > 10min', () => { + describe('server response with error', () => { beforeEach(async () => { jest.clearAllMocks() apolloMutationMock.mockRejectedValueOnce({ message: 'Error' }) @@ -178,6 +179,7 @@ describe('ResetPassword', () => { describe('server response with success on /checkEmail', () => { beforeEach(async () => { + jest.clearAllMocks() mocks.$route.path.mock = 'checkEmail' apolloMutationMock.mockResolvedValue({ data: { @@ -204,6 +206,28 @@ describe('ResetPassword', () => { it('redirects to "/thx/checkEmail"', () => { expect(routerPushMock).toHaveBeenCalledWith('/thx/checkEmail') }) + + describe('with param code', () => { + beforeEach(async () => { + mocks.$route.params.code = 'the-most-secret-code-ever' + apolloMutationMock.mockResolvedValue({ + data: { + resetPassword: 'success', + }, + }) + wrapper = Wrapper() + await wrapper.findAll('input').at(0).setValue('Aa123456_') + await wrapper.findAll('input').at(1).setValue('Aa123456_') + await wrapper.find('form').trigger('submit') + await flushPromises() + }) + + it('redirects to "/thx/checkEmail/the-most-secret-code-ever"', () => { + expect(routerPushMock).toHaveBeenCalledWith( + '/thx/checkEmail/the-most-secret-code-ever', + ) + }) + }) }) describe('server response with success on /reset-password', () => { diff --git a/frontend/src/pages/ResetPassword.vue b/frontend/src/pages/ResetPassword.vue index d6fc1dd76..7771be5f6 100644 --- a/frontend/src/pages/ResetPassword.vue +++ b/frontend/src/pages/ResetPassword.vue @@ -6,11 +6,11 @@ -

{{ $t(displaySetup.authenticated) }}

+

{{ $t(displaySetup.title) }}

- {{ $t(displaySetup.notAuthenticated) }} + {{ $t(displaySetup.text) }}
@@ -53,14 +53,14 @@ import { queryOptIn } from '@/graphql/queries' const textFields = { reset: { - authenticated: 'settings.password.change-password', - notAuthenticated: 'settings.password.reset-password.text', + title: 'settings.password.change-password', + text: 'settings.password.reset-password.text', button: 'settings.password.change-password', linkTo: '/login', }, checkEmail: { - authenticated: 'settings.password.set', - notAuthenticated: 'settings.password.set-password.text', + title: 'settings.password.set', + text: 'settings.password.set-password.text', button: 'settings.password.set', linkTo: '/login', },