test: add profile validation e2e tests and fix pre-existing failures

Add 7 new e2e tests verifying profile form validation in both manage
and admin UIs: invalid phone number, phone normalization, E.164 hint
attributes, and admin-side email/phone/picture URL validation errors.

Fix 3 pre-existing test failures:
- Replace invalid seeded phone number (+1234567890) with valid E.164
  (+12025551234) that was causing profile update tests to fail
- Update email validation error assertion to match actual pydantic
  message (value_error type uses raw message, not label-prefixed)
This commit is contained in:
Johan Lundberg 2026-03-16 10:00:46 +01:00
parent 752bf87b7c
commit 2dfa3f3bff
No known key found for this signature in database
GPG key ID: A6C152738D03C7D1
3 changed files with 97 additions and 8 deletions

View file

@ -50,7 +50,7 @@ test.describe('Profile page', () => {
await expect(page.locator('#family_name')).toHaveValue('Smith');
await expect(page.locator('#preferred_username')).toHaveValue('asmith');
await expect(page.locator('#email')).toHaveValue('alice@example.com');
await expect(page.locator('#phone_number')).toHaveValue('+1234567890');
await expect(page.locator('#phone_number')).toHaveValue('+12025551234');
await expect(page.locator('#picture')).toHaveValue('https://example.com/alice.jpg');
await expect(page.locator('#locale')).toHaveValue('en');
});
@ -168,7 +168,7 @@ test.describe('Profile page', () => {
const alert = page.locator('#profile-status [role="alert"]');
await expect(alert).toBeVisible({ timeout: 5000 });
await expect(alert).toContainText('Invalid email');
await expect(alert).toContainText('valid email address');
});
test('shows error for invalid picture URL', async ({ page }) => {
@ -189,5 +189,34 @@ test.describe('Profile page', () => {
test('picture input has type="url"', async ({ page }) => {
await expect(page.locator('#picture')).toHaveAttribute('type', 'url');
});
test('shows error for invalid phone number', async ({ page }) => {
// Bypass HTML5 validation by removing pattern attribute
await page.locator('#phone_number').evaluate(el => el.removeAttribute('pattern'));
await page.fill('#phone_number', 'not-a-phone');
await page.click('button[type="submit"]');
const alert = page.locator('#profile-status [role="alert"]');
await expect(alert).toBeVisible({ timeout: 5000 });
await expect(alert).toContainText('valid phone number');
});
test('normalizes phone number with spaces on save', async ({ page }) => {
await page.fill('#phone_number', '+46 70 123 45 67');
await page.click('button[type="submit"]');
const status = page.locator('#profile-status [role="status"]');
await expect(status).toBeVisible({ timeout: 5000 });
await expect(status).toContainText('Profile updated');
await page.reload();
await expect(page.locator('#phone_number')).toHaveValue('+46701234567');
});
test('phone input has correct E.164 hint attributes', async ({ page }) => {
await expect(page.locator('#phone_number')).toHaveAttribute('type', 'tel');
await expect(page.locator('#phone_number')).toHaveAttribute('pattern', '\\+[0-9 ]+');
await expect(page.locator('#phone_number')).toHaveAttribute('title', /International format/);
});
});
});