fix: Whitespace in Password Shows Validation Error

This commit is contained in:
Moriz Wahl 2021-09-27 23:07:02 +02:00
parent 16ec10948d
commit 3d2e87470c
2 changed files with 10 additions and 3 deletions

View File

@ -114,14 +114,14 @@ export const loadAllRules = (i18nCallback) => {
extend('atLeastOneSpecialCharater', {
validate(value) {
return !!value.match(/[^a-zA-Z0-9]/)
return !!value.match(/[^a-zA-Z0-9 \t\n\r]/)
},
message: (_, values) => i18nCallback.t('site.signup.special-char', values),
})
extend('noWhitespaceCharacters', {
validate(value) {
return !!value.match(/[^ \t\n\r]/)
return !value.match(/[ \t\n\r]+/)
},
message: (_, values) => i18nCallback.t('site.signup.no-whitespace', values),
})

View File

@ -105,13 +105,20 @@ describe('UserCard_FormUserPasswort', () => {
describe('validation', () => {
it('displays all password requirements', () => {
const feedbackArray = wrapper.findAll('div.invalid-feedback').at(1).findAll('span')
expect(feedbackArray).toHaveLength(7)
expect(feedbackArray).toHaveLength(6)
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')
expect(feedbackArray.at(5).text()).toBe('site.signup.special-char')
})
it('displays no whitespace error when a space character is entered', async () => {
await wrapper.findAll('input').at(1).setValue(' ')
await flushPromises()
const feedbackArray = wrapper.findAll('div.invalid-feedback').at(1).findAll('span')
expect(feedbackArray).toHaveLength(7)
expect(feedbackArray.at(6).text()).toBe('site.signup.no-whitespace')
})