Files
TREK/client/src/components/shared/PasswordChecklist.test.tsx
T
Maurice 542a57b74e feat(auth): password rules checked while typing, with the server's own policy
The password policy moves to @trek/shared, where the server keeps enforcing it unchanged and every form that sets a password now runs it before sending: the forced change after the first login, registration, the reset link, the account settings on desktop and phone, and creating or editing a user in admin. Under each new password a checklist ticks off length, upper and lower case, a number and a special character, and a refusal names the actual reason, a too common or too repetitive password included. (#1200)
2026-10-01 10:17:28 +02:00

38 lines
1.8 KiB
TypeScript

// FE-SHARED-PWCHECK-001 to FE-SHARED-PWCHECK-004
import { describe, expect, it } from 'vitest'
import { render, screen } from '../../../tests/helpers/render'
import PasswordChecklist from './PasswordChecklist'
import { passwordErrorKey } from '../../utils/passwordError'
describe('PasswordChecklist (#1200)', () => {
it('FE-SHARED-PWCHECK-001: stays out of the way until something is typed', () => {
const { container } = render(<PasswordChecklist password="" />)
expect(container).toBeEmptyDOMElement()
})
it('FE-SHARED-PWCHECK-002: ticks off each rule the password meets', () => {
render(<PasswordChecklist password="abcdefg1" />)
const list = screen.getByRole('list', { name: 'Password requirements' })
const met = Array.from(list.querySelectorAll('li[data-met]')).map(li => li.textContent)
expect(met).toEqual(['At least 8 characters', 'A lowercase letter', 'A number'])
expect(list.querySelectorAll('li')).toHaveLength(5)
})
it('FE-SHARED-PWCHECK-003: the always-light sign-in card keeps fixed colours', () => {
render(<PasswordChecklist password="A" tone="light" />)
const upper = screen.getByText('An uppercase letter').closest('li') as HTMLElement
expect(upper.getAttribute('data-met')).toBe('true')
expect(upper.style.background).not.toBe('')
})
})
describe('passwordErrorKey (#1200)', () => {
it('FE-SHARED-PWCHECK-004: names the problem the server would answer with, or nothing', () => {
expect(passwordErrorKey('Ab1!')).toBe('settings.passwordTooShort')
expect(passwordErrorKey('zzzzzzzzzz')).toBe('settings.passwordRepetitive')
expect(passwordErrorKey('Password')).toBe('settings.passwordCommon')
expect(passwordErrorKey('longenough1')).toBe('settings.passwordWeak')
expect(passwordErrorKey('Longenough1!')).toBeNull()
})
})