fix(webui): explain unmet password rules after blur
The requirement list still opens only while the new-password field is focused. After blur, unmet rules stay visible as field text, and Save can be pressed to return focus to that field.
This commit is contained in:
3 files changed
+94
-9
No files matched your search
@@ -6,6 +6,7 @@ import {
|
||||
PasswordStrength,
|
||||
type PasswordRule,
|
||||
} from '../src/components/interior/password-strength';
|
||||
import { passwordRequirementHint } from '../src/components/pages/change-password-form';
|
||||
|
||||
const RULES: readonly PasswordRule[] = [
|
||||
{ id: 'length', label: '长度不少于 10 位', test: (value) => value.length >= 10 },
|
||||
@@ -68,3 +69,54 @@ describe('password input guidance', () => {
|
||||
expect(markup).toContain('role="status"');
|
||||
});
|
||||
});
|
||||
|
||||
describe('passwordRequirementHint', () => {
|
||||
const rules = [
|
||||
{ id: 'length', label: '长度不少于 10 位', ok: false },
|
||||
{ id: 'upper', label: '包含大写字母', ok: true },
|
||||
];
|
||||
|
||||
it('hides unmet-rule copy while the animated list is open', () => {
|
||||
expect(passwordRequirementHint({
|
||||
focused: true,
|
||||
value: 'short',
|
||||
checked: true,
|
||||
valid: false,
|
||||
rules,
|
||||
checkError: '',
|
||||
})).toBeNull();
|
||||
});
|
||||
|
||||
it('lists unmet rules after the new-password field loses focus', () => {
|
||||
expect(passwordRequirementHint({
|
||||
focused: false,
|
||||
value: 'short',
|
||||
checked: true,
|
||||
valid: false,
|
||||
rules,
|
||||
checkError: '',
|
||||
})).toBe('仍需满足:长度不少于 10 位');
|
||||
});
|
||||
|
||||
it('does not invent unmet rules while strength is still being checked', () => {
|
||||
expect(passwordRequirementHint({
|
||||
focused: false,
|
||||
value: 'short',
|
||||
checked: false,
|
||||
valid: false,
|
||||
rules,
|
||||
checkError: '',
|
||||
})).toBeNull();
|
||||
});
|
||||
|
||||
it('surfaces a failed strength check after blur', () => {
|
||||
expect(passwordRequirementHint({
|
||||
focused: false,
|
||||
value: 'short',
|
||||
checked: false,
|
||||
valid: false,
|
||||
rules,
|
||||
checkError: '网络错误',
|
||||
})).toBe('密码强度校验失败:网络错误');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user