From b2e09bf9ce782de8135604ddc619c80c45c7f124 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 6 Jul 2021 15:52:39 +0200 Subject: [PATCH] test validation rules for new passworda --- .../Inputs/InputPasswordConfirmation.spec.js | 2 + .../src/views/Pages/ResetPassword.spec.js | 2 + .../UserCard_FormUserPasswort.spec.js | 51 +++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/frontend/src/components/Inputs/InputPasswordConfirmation.spec.js b/frontend/src/components/Inputs/InputPasswordConfirmation.spec.js index 633dea44a..953d0b960 100644 --- a/frontend/src/components/Inputs/InputPasswordConfirmation.spec.js +++ b/frontend/src/components/Inputs/InputPasswordConfirmation.spec.js @@ -4,6 +4,8 @@ import InputPasswordConfirmation from './InputPasswordConfirmation' const localVue = global.localVue +// validation is tested in src/views/Pages/UserProfile/UserCard_FormUserPasswort.spec.js + describe('InputPasswordConfirmation', () => { let wrapper diff --git a/frontend/src/views/Pages/ResetPassword.spec.js b/frontend/src/views/Pages/ResetPassword.spec.js index 76a010b2a..a0a86a24d 100644 --- a/frontend/src/views/Pages/ResetPassword.spec.js +++ b/frontend/src/views/Pages/ResetPassword.spec.js @@ -3,6 +3,8 @@ import loginAPI from '../../apis/loginAPI' import ResetPassword from './ResetPassword' import flushPromises from 'flush-promises' +// validation is tested in src/views/Pages/UserProfile/UserCard_FormUserPasswort.spec.js + jest.mock('../../apis/loginAPI') const localVue = global.localVue diff --git a/frontend/src/views/Pages/UserProfile/UserCard_FormUserPasswort.spec.js b/frontend/src/views/Pages/UserProfile/UserCard_FormUserPasswort.spec.js index 2d5d2a560..f00a4d2b4 100644 --- a/frontend/src/views/Pages/UserProfile/UserCard_FormUserPasswort.spec.js +++ b/frontend/src/views/Pages/UserProfile/UserCard_FormUserPasswort.spec.js @@ -105,6 +105,57 @@ describe('UserCardFormUserPasswort', () => { expect(form.find('button[type="submit"]').exists()).toBeTruthy() }) + describe('validation', () => { + it('displays all password requirements', () => { + const feedbackArray = wrapper.findAll('div.invalid-feedback').at(1).findAll('span') + expect(feedbackArray).toHaveLength(5) + expect(feedbackArray.at(0).text()).toBe('validations.messages.required') + expect(feedbackArray.at(1).text()).toBe('site.signup.lowercase') + expect(feedbackArray.at(2).text()).toBe('site.signup.uppercase') + expect(feedbackArray.at(3).text()).toBe('site.signup.one_number') + expect(feedbackArray.at(4).text()).toBe('site.signup.minimum') + }) + + it('removes first message when a character is given', async () => { + await wrapper.findAll('input').at(1).setValue('@') + await flushPromises() + const feedbackArray = wrapper.findAll('div.invalid-feedback').at(1).findAll('span') + expect(feedbackArray).toHaveLength(4) + expect(feedbackArray.at(0).text()).toBe('site.signup.lowercase') + }) + + it('removes first and second message when a lowercase character is given', async () => { + await wrapper.findAll('input').at(1).setValue('a') + await flushPromises() + const feedbackArray = wrapper.findAll('div.invalid-feedback').at(1).findAll('span') + expect(feedbackArray).toHaveLength(3) + expect(feedbackArray.at(0).text()).toBe('site.signup.uppercase') + }) + + it('removes the first three messages when a lowercase and uppercase characters are given', async () => { + await wrapper.findAll('input').at(1).setValue('Aa') + await flushPromises() + const feedbackArray = wrapper.findAll('div.invalid-feedback').at(1).findAll('span') + expect(feedbackArray).toHaveLength(2) + expect(feedbackArray.at(0).text()).toBe('site.signup.one_number') + }) + + it('removes the first four messages when a lowercase, uppercase and numeric characters are given', async () => { + await wrapper.findAll('input').at(1).setValue('Aa1') + await flushPromises() + const feedbackArray = wrapper.findAll('div.invalid-feedback').at(1).findAll('span') + expect(feedbackArray).toHaveLength(1) + expect(feedbackArray.at(0).text()).toBe('site.signup.minimum') + }) + + it('removes all messages when all rules are fulfilled', async () => { + await wrapper.findAll('input').at(1).setValue('Aa123456') + await flushPromises() + const feedbackArray = wrapper.findAll('div.invalid-feedback').at(1).findAll('span') + expect(feedbackArray).toHaveLength(0) + }) + }) + describe('submit', () => { describe('valid data', () => { beforeEach(async () => {