Skip to content

Commit f54e64c

Browse files
Fix validation tests to use correct Angular Material MDC error selectors
Replace all instances of '.mat-error, .error' class selector with 'mat-error, .mat-mdc-form-field-error, .mat-error' element selector. This matches the pattern established in other validation tests. Result: 5/11 passing (was 3/11 before fix). Remaining failures are due to application validation behavior (some validators may not be configured in the Angular form).
1 parent a2acc5a commit f54e64c

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

tests/validation/form-validation.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test.describe('Form Validation Edge Cases', () => {
3838

3939
// Either truncated or validation error shown
4040
const actualValue = await firstNameInput.inputValue();
41-
const hasError = await page.locator('.mat-error, .error').filter({ hasText: /length|max|characters/i }).isVisible({ timeout: 1000 }).catch(() => false);
41+
const hasError = await page.locator('mat-error, .mat-mdc-form-field-error, .mat-error').filter({ hasText: /length|max|characters/i }).isVisible({ timeout: 1000 }).catch(() => false);
4242

4343
expect(actualValue.length <= 150 || hasError).toBe(true);
4444
});
@@ -76,7 +76,7 @@ test.describe('Form Validation Edge Cases', () => {
7676
await page.waitForTimeout(500);
7777

7878
// Check for validation errors
79-
const hasError = await page.locator('.mat-error, .error').isVisible({ timeout: 1000 }).catch(() => false);
79+
const hasError = await page.locator('mat-error, .mat-mdc-form-field-error, .mat-error').isVisible({ timeout: 1000 }).catch(() => false);
8080

8181
if (!testCase.valid) {
8282
expect(hasError).toBe(true);
@@ -111,7 +111,7 @@ test.describe('Form Validation Edge Cases', () => {
111111
await emailInput.blur();
112112
await page.waitForTimeout(500);
113113

114-
const hasError = await page.locator('.mat-error, .error').filter({ hasText: /email|valid|format/i }).isVisible({ timeout: 1000 }).catch(() => false);
114+
const hasError = await page.locator('mat-error, .mat-mdc-form-field-error, .mat-error').filter({ hasText: /email|valid|format/i }).isVisible({ timeout: 1000 }).catch(() => false);
115115
expect(hasError).toBe(true);
116116
}
117117

@@ -129,7 +129,7 @@ test.describe('Form Validation Edge Cases', () => {
129129
await emailInput.blur();
130130
await page.waitForTimeout(500);
131131

132-
const hasError = await page.locator('.mat-error, .error').filter({ hasText: /email|valid|format/i }).isVisible({ timeout: 1000 }).catch(() => false);
132+
const hasError = await page.locator('mat-error, .mat-mdc-form-field-error, .mat-error').filter({ hasText: /email|valid|format/i }).isVisible({ timeout: 1000 }).catch(() => false);
133133
expect(hasError).toBe(false);
134134
}
135135
});
@@ -149,7 +149,7 @@ test.describe('Form Validation Edge Cases', () => {
149149
await salaryInput.blur();
150150
await page.waitForTimeout(500);
151151

152-
const hasError = await page.locator('.mat-error, .error').filter({ hasText: /positive|negative|greater|invalid/i }).isVisible({ timeout: 1000 }).catch(() => false);
152+
const hasError = await page.locator('mat-error, .mat-mdc-form-field-error, .mat-error').filter({ hasText: /positive|negative|greater|invalid/i }).isVisible({ timeout: 1000 }).catch(() => false);
153153
const submitButton = page.locator('button[type="submit"]');
154154
const isDisabled = await submitButton.isDisabled().catch(() => false);
155155

@@ -172,7 +172,7 @@ test.describe('Form Validation Edge Cases', () => {
172172
await salaryInput.blur();
173173
await page.waitForTimeout(500);
174174

175-
const hasError = await page.locator('.mat-error, .error').filter({ hasText: /greater|zero|positive/i }).isVisible({ timeout: 1000 }).catch(() => false);
175+
const hasError = await page.locator('mat-error, .mat-mdc-form-field-error, .mat-error').filter({ hasText: /greater|zero|positive/i }).isVisible({ timeout: 1000 }).catch(() => false);
176176

177177
expect(hasError || true).toBe(true);
178178
}
@@ -194,7 +194,7 @@ test.describe('Form Validation Edge Cases', () => {
194194
await salaryInput.blur();
195195
await page.waitForTimeout(500);
196196

197-
const hasError = await page.locator('.mat-error, .error').filter({ hasText: /max|large|limit/i }).isVisible({ timeout: 1000 }).catch(() => false);
197+
const hasError = await page.locator('mat-error, .mat-mdc-form-field-error, .mat-error').filter({ hasText: /max|large|limit/i }).isVisible({ timeout: 1000 }).catch(() => false);
198198
const actualValue = await salaryInput.inputValue();
199199

200200
// Either shows error or truncates/limits the value
@@ -233,7 +233,7 @@ test.describe('Form Validation Edge Cases', () => {
233233

234234
// Should either reject or sanitize
235235
const actualValue = await firstNameInput.inputValue();
236-
const hasError = await page.locator('.mat-error, .error').isVisible({ timeout: 1000 }).catch(() => false);
236+
const hasError = await page.locator('mat-error, .mat-mdc-form-field-error, .mat-error').isVisible({ timeout: 1000 }).catch(() => false);
237237

238238
// Value should be sanitized or show error
239239
expect(actualValue !== injection || hasError).toBe(true);
@@ -301,7 +301,7 @@ test.describe('Form Validation Edge Cases', () => {
301301
await firstNameInput.blur();
302302
await page.waitForTimeout(500);
303303

304-
const hasError = await page.locator('.mat-error, .error').filter({ hasText: /required|empty|invalid/i }).isVisible({ timeout: 1000 }).catch(() => false);
304+
const hasError = await page.locator('mat-error, .mat-mdc-form-field-error, .mat-error').filter({ hasText: /required|empty|invalid/i }).isVisible({ timeout: 1000 }).catch(() => false);
305305
const submitButton = page.locator('button[type="submit"]');
306306
const isDisabled = await submitButton.isDisabled().catch(() => false);
307307

@@ -330,7 +330,7 @@ test.describe('Form Validation Edge Cases', () => {
330330
await page.waitForTimeout(2000);
331331

332332
// Should either trim automatically or show validation error
333-
const hasError = await page.locator('.mat-error, .error').isVisible({ timeout: 1000 }).catch(() => false);
333+
const hasError = await page.locator('mat-error, .mat-mdc-form-field-error, .mat-error').isVisible({ timeout: 1000 }).catch(() => false);
334334
const submitted = !page.url().includes('create');
335335

336336
expect(!hasError || submitted).toBe(true);
@@ -358,7 +358,7 @@ test.describe('Form Validation Edge Cases', () => {
358358
await page.waitForTimeout(500);
359359

360360
// Should show multiple errors
361-
const errors = page.locator('.mat-error, .error');
361+
const errors = page.locator('mat-error, .mat-mdc-form-field-error, .mat-error');
362362
const errorCount = await errors.count();
363363

364364
expect(errorCount).toBeGreaterThanOrEqual(1);

0 commit comments

Comments
 (0)