fix(web): clear the short-password complaint when the password is changed
Found in a real browser: after the complaint, typing a valid password left it on screen until the next submit. Same in the reset dialog and the add form.
This commit is contained in:
parent
52569a0f8d
commit
a39c0f7719
4 changed files with 33 additions and 2 deletions
|
|
@ -57,6 +57,17 @@ test('a password of seven characters is refused here, with no request', async ()
|
|||
expect(calls).toHaveLength(0)
|
||||
})
|
||||
|
||||
test('the complaint about a short password goes away as soon as the password is changed', async () => {
|
||||
mockFetch({})
|
||||
renderForm()
|
||||
await userEvent.type(email(), 'new@example.org')
|
||||
await userEvent.type(password(), '1234567')
|
||||
await userEvent.click(add())
|
||||
expect(await screen.findByRole('alert')).toBeInTheDocument()
|
||||
await userEvent.type(password(), '8')
|
||||
expect(screen.queryByRole('alert')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('adding sends the trimmed email, the password and the role, then empties the form', async () => {
|
||||
const { calls } = mockFetch({ 'POST /api/v1/users': created })
|
||||
renderForm()
|
||||
|
|
|
|||
|
|
@ -67,7 +67,10 @@ export default function AddUserForm() {
|
|||
type="password"
|
||||
value={password}
|
||||
autoComplete="new-password"
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
onChange={(e) => {
|
||||
setPassword(e.target.value)
|
||||
setTooShort(false)
|
||||
}}
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">{t('admin.users.passwordHint')}</p>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -107,6 +107,18 @@ test('resetting a password asks for the new one, and a short one is refused with
|
|||
expect(calledWith(calls, 'PUT /api/v1/users/2/password')).toHaveLength(0)
|
||||
})
|
||||
|
||||
test('the complaint about a short password goes away as soon as the password is changed', async () => {
|
||||
mockFetch(routes({ 'PUT /api/v1/users/2/password': none }))
|
||||
renderList()
|
||||
await userEvent.click(within(await row('ann@example.org')).getByRole('button', { name: 'Reset password for ann@example.org' }))
|
||||
const dialog = await screen.findByRole('dialog')
|
||||
await userEvent.type(within(dialog).getByLabelText('New password'), '1234567')
|
||||
await userEvent.click(within(dialog).getByRole('button', { name: 'Reset password' }))
|
||||
expect(await within(dialog).findByRole('alert')).toBeInTheDocument()
|
||||
await userEvent.type(within(dialog).getByLabelText('New password'), '8')
|
||||
expect(within(dialog).queryByRole('alert')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('a password longer than 256 bytes is refused without a request', async () => {
|
||||
const { calls } = mockFetch(routes({ 'PUT /api/v1/users/2/password': none }))
|
||||
renderList()
|
||||
|
|
|
|||
|
|
@ -84,7 +84,12 @@ function ResetDialog({ user, onClose, onDone }: { user: User; onClose: () => voi
|
|||
</DialogHeader>
|
||||
<div className="flex flex-col gap-2">
|
||||
<Label htmlFor="reset-password">{t('admin.users.newPassword')}</Label>
|
||||
<Input id="reset-password" type="password" autoComplete="new-password" value={password} onChange={(e) => setPassword(e.target.value)} />
|
||||
<Input id="reset-password" type="password" autoComplete="new-password" value={password}
|
||||
onChange={(e) => {
|
||||
setPassword(e.target.value)
|
||||
setTooShort(false)
|
||||
}}
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">{t('admin.users.passwordHint')}</p>
|
||||
</div>
|
||||
{tooShort && (
|
||||
|
|
|
|||
Loading…
Reference in a new issue