test(forms): improve test coverage for multiple pattern validators

Add comprehensive test cases to validate behavior when multiple
pattern validators are applied to the same field.

These tests clarify that multiple patterns operate with AND logic,
where each pattern is validated independently and produces its own
error when it doesn't match.

(cherry picked from commit 7fd076bdd3)
This commit is contained in:
cexbrayat
2026-01-10 10:50:19 +01:00
committed by Jessica Janiuk
parent 5ad2e1bae0
commit 8474277b49
@@ -95,6 +95,57 @@ describe('pattern validator', () => {
expect(f.name().pattern()).toEqual([/pir.*jok/, /pelmeni/]);
});
it('validates multiple patterns independently (AND logic)', () => {
const model = signal('abc123');
const f = form(
model,
(p) => {
pattern(p, /abc/); // matches
pattern(p, /\d+/); // matches
},
{injector: TestBed.inject(Injector)},
);
// Both patterns match, so no errors
expect(f().pattern()).toEqual([/abc/, /\d+/]);
expect(f().errors()).toEqual([]);
});
it('validates multiple patterns independently - partial match produces errors', () => {
const model = signal('abc');
const f = form(
model,
(p) => {
pattern(p, /abc/); // matches
pattern(p, /\d+/); // does not match
},
{injector: TestBed.inject(Injector)},
);
// Only one pattern matches, so we get an error from the non-matching one
expect(f().pattern()).toEqual([/abc/, /\d+/]);
expect(f().errors()).toEqual([patternError(/\d+/, {fieldTree: f})]);
});
it('validates multiple patterns - no match produces multiple errors', () => {
const model = signal('xyz');
const f = form(
model,
(p) => {
pattern(p, /abc/); // does not match
pattern(p, /\d+/); // does not match
},
{injector: TestBed.inject(Injector)},
);
// No patterns match, so we get errors from both
expect(f().pattern()).toEqual([/abc/, /\d+/]);
expect(f().errors()).toEqual([
patternError(/abc/, {fieldTree: f}),
patternError(/\d+/, {fieldTree: f}),
]);
});
it('PATTERN property defaults to empty list', () => {
const cat = signal({name: 'pelmeni-the-cat'});
const f = form(