From e2d2798138a4ae85bc281fa8ccaad037f2fe1f9b Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 1 Jul 2021 15:43:06 +0200 Subject: [PATCH] fixed tests --- frontend/src/main.js | 3 +- .../src/views/Pages/ResetPassword.spec.js | 52 ++++++++++++------- frontend/src/views/Pages/ResetPassword.vue | 8 +-- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/frontend/src/main.js b/frontend/src/main.js index 731fc896a..0e6fd0ef2 100755 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -2,8 +2,7 @@ import Vue from 'vue' import DashboardPlugin from './plugins/dashboard-plugin' import App from './App.vue' import i18n from './i18n.js' -// eslint-disable-next-line no-unused-vars -import validationRules from './validation-rules' +import './validation-rules' import { store } from './store/store' diff --git a/frontend/src/views/Pages/ResetPassword.spec.js b/frontend/src/views/Pages/ResetPassword.spec.js index 14038e676..11bdad1ba 100644 --- a/frontend/src/views/Pages/ResetPassword.spec.js +++ b/frontend/src/views/Pages/ResetPassword.spec.js @@ -2,6 +2,23 @@ import { mount, RouterLinkStub } from '@vue/test-utils' import loginAPI from '../../apis/loginAPI' import ResetPassword from './ResetPassword' import flushPromises from 'flush-promises' +import { extend } from 'vee-validate' + +const rules = [ + 'containsLowercaseCharacter', + 'containsUppercaseCharacter', + 'containsNumericCharacter', + 'atLeastEightCharactera', + 'samePassword', +] + +rules.forEach((rule) => { + extend(rule, { + validate(value) { + return true + }, + }) +}) jest.mock('../../apis/loginAPI') @@ -28,6 +45,7 @@ emailVerificationMock .mockReturnValueOnce({ success: false, result: { message: 'error' } }) .mockReturnValueOnce({ success: false, result: { message: 'error' } }) .mockReturnValueOnce({ success: false, result: { message: 'error' } }) + .mockReturnValueOnce({ success: false, result: { message: 'error' } }) .mockReturnValue(successResponseObject) changePasswordMock @@ -81,36 +99,39 @@ describe('ResetPassword', () => { }) it('does not render the Reset Password form when not authenticated', () => { - expect(wrapper.find('div.resetpwd-form').exists()).toBeFalsy() + expect(wrapper.find('form').exists()).toBeFalsy() }) it('toasts an error when no valid optin is given', () => { expect(toasterMock).toHaveBeenCalledWith('error') }) + it('has a message suggesting to contact the support', () => { + expect(wrapper.find('div.header').text()).toContain('reset-password.title') + expect(wrapper.find('div.header').text()).toContain('reset-password.not-authenticated') + }) + it('renders the Reset Password form when authenticated', async () => { - wrapper.setData({ authenticated: true }) - await wrapper.vm.$nextTick() + await wrapper.setData({ authenticated: true }) expect(wrapper.find('div.resetpwd-form').exists()).toBeTruthy() }) describe('Register header', () => { it('has a welcome message', () => { - expect(wrapper.find('div.header').text()).toBe('reset-password.title reset-password.text') + expect(wrapper.find('div.header').text()).toContain('reset-password.title') + expect(wrapper.find('div.header').text()).toContain('reset-password.text') }) }) - /* there is no back button, why? describe('links', () => { it('has a link "Back"', () => { expect(wrapper.findAllComponents(RouterLinkStub).at(0).text()).toEqual('back') }) it('links to /login when clicking "Back"', () => { - expect(wrapper.findAllComponents(RouterLinkStub).at(0).props().to).toBe('/login') + expect(wrapper.findAllComponents(RouterLinkStub).at(0).props().to).toBe('/Login') }) }) - */ describe('reset password form', () => { it('has a register form', () => { @@ -121,10 +142,6 @@ describe('ResetPassword', () => { expect(wrapper.findAll('input[type="password"]').length).toBe(2) }) - it('has no submit button when not completely filled', () => { - expect(wrapper.find('button[type="submit"]').exists()).toBe(false) - }) - it('toggles the first input field to text when eye icon is clicked', async () => { wrapper.findAll('button').at(0).trigger('click') await wrapper.vm.$nextTick() @@ -140,23 +157,20 @@ describe('ResetPassword', () => { describe('submit form', () => { beforeEach(async () => { - wrapper.findAll('input').at(0).setValue('Aa123456') - wrapper.findAll('input').at(1).setValue('Aa123456') - await wrapper.vm.$nextTick() + await wrapper.findAll('input').at(0).setValue('Aa123456') + await wrapper.findAll('input').at(1).setValue('Aa123456') await flushPromises() - wrapper.find('form').trigger('submit') + await wrapper.find('form').trigger('submit') }) describe('server response with error', () => { - it('toasts an error message', async () => { + it('toasts an error message', () => { expect(toasterMock).toHaveBeenCalledWith('error') }) }) describe('server response with success', () => { - it('calls the API', async () => { - await wrapper.vm.$nextTick() - await flushPromises() + it('calls the API', () => { expect(changePasswordMock).toHaveBeenCalledWith(1, 'user@example.org', 'Aa123456') }) diff --git a/frontend/src/views/Pages/ResetPassword.vue b/frontend/src/views/Pages/ResetPassword.vue index 910ad3f4e..616fa85c1 100644 --- a/frontend/src/views/Pages/ResetPassword.vue +++ b/frontend/src/views/Pages/ResetPassword.vue @@ -38,9 +38,11 @@ -
- {{ $t('back') }} -
+ + + {{ $t('back') }} + +