feat: First-Start Create Admin Modal 1.04
This commit is contained in:
@@ -2,6 +2,11 @@ import {
|
||||
passwordMatchValidator,
|
||||
PasswordMatchGroupLike,
|
||||
} from '../../frontend/src/app/features/setup/setup-create-admin.validators';
|
||||
import {
|
||||
usernameError,
|
||||
passwordError,
|
||||
confirmError,
|
||||
} from '../../frontend/src/app/features/setup/setup-create-admin.field-errors';
|
||||
|
||||
function makeGroup(password: string | null | undefined, confirm: string | null | undefined): PasswordMatchGroupLike {
|
||||
return {
|
||||
@@ -111,3 +116,58 @@ describe('Composed submit gate (mirrors SetupCreateAdminComponent.submit)', () =
|
||||
expect(isFormReadyForSubmit('first.admin', 'Sup3rSecret!Pass', 'Sup3rSecret!Pass')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Field-error helpers (mirror the template render)', () => {
|
||||
it('usernameError returns "Username is required" when touched + required', () => {
|
||||
expect(
|
||||
usernameError({ value: '', touched: true, errors: { required: true } }),
|
||||
).toBe('Username is required');
|
||||
});
|
||||
|
||||
it('usernameError returns the minlength message when too short', () => {
|
||||
expect(
|
||||
usernameError({ value: 'ab', touched: true, errors: { minlength: true } }),
|
||||
).toBe('Username must be at least 3 characters');
|
||||
});
|
||||
|
||||
it('usernameError returns null when not touched even if errors are present', () => {
|
||||
expect(
|
||||
usernameError({ value: '', touched: false, errors: { required: true } }),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it('passwordError returns "Password is required" when touched + required', () => {
|
||||
expect(
|
||||
passwordError({ value: '', touched: true, errors: { required: true } }),
|
||||
).toBe('Password is required');
|
||||
});
|
||||
|
||||
it('passwordError returns null when touched with no errors (policy is server-side)', () => {
|
||||
expect(
|
||||
passwordError({ value: 'x', touched: true, errors: null }),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it('confirmError returns "Please confirm your password" when touched + required', () => {
|
||||
expect(
|
||||
confirmError({ value: '', touched: true, errors: { required: true } }),
|
||||
).toBe('Please confirm your password');
|
||||
});
|
||||
|
||||
it('confirmError returns "Passwords do not match" when group mismatch is set', () => {
|
||||
expect(
|
||||
confirmError({
|
||||
value: 'a',
|
||||
touched: true,
|
||||
errors: null,
|
||||
groupMismatch: true,
|
||||
}),
|
||||
).toBe('Passwords do not match');
|
||||
});
|
||||
|
||||
it('confirmError returns null when not touched and no group mismatch', () => {
|
||||
expect(
|
||||
confirmError({ value: 'a', touched: false, errors: null }),
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user