fix: optional email validation (#27329)
* fix: validate optional email fields when input is provided #27299 * fix: validate optional email fields when input is provided * fix: validate optional email fields when input is provided * refactor: move empty value handling out of zod-utils * fix: remove PII from error logs * test: verify optional email allows empty submission * test: e2e validation for optional email using url state --------- Co-authored-by: Eunjae Lee <[email protected]> Co-authored-by: Romit <[email protected]> Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
4 files changed
+297
-59
No files matched your search
@@ -920,3 +920,56 @@ test.describe("Past booking cancellation", () => {
|
||||
await expect(page.locator('[data-testid="cancel"]')).toBeHidden();
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Optional Email Field Validation", () => {
|
||||
test("should validate format if input is provided, but allow empty submission", async ({ page, users }) => {
|
||||
|
||||
const user = await users.create({
|
||||
eventTypes: [
|
||||
{
|
||||
title: "Test Event",
|
||||
slug: "test-event",
|
||||
length: 30,
|
||||
bookingFields: [
|
||||
{ name: "name", type: "name", required: true },
|
||||
{ name: "email", type: "email", required: true },
|
||||
{
|
||||
name: "altEmail",
|
||||
type: "email",
|
||||
required: false,
|
||||
label: "Alternate Email"
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await page.goto(`/${user.username}/test-event`);
|
||||
await selectFirstAvailableTimeSlotNextMonth(page);
|
||||
|
||||
await page.locator('input[name="name"]').fill('Test Booker');
|
||||
await page.locator('input[name="email"]').fill('[email protected]');
|
||||
|
||||
const optionalField = page.getByLabel(/Alternate Email/i);
|
||||
|
||||
// Visibility
|
||||
await expect(optionalField).toBeVisible();
|
||||
|
||||
// Trigger validation error
|
||||
await optionalField.fill('not-an-email');
|
||||
await page.click('[data-testid="confirm-book-button"]');
|
||||
|
||||
// Verify form didn't submit
|
||||
await expect(page).not.toHaveURL(/.*isSuccessBookingPage=true.*/);
|
||||
|
||||
// Verify empty submission is allowed
|
||||
await optionalField.fill('');
|
||||
|
||||
// Click the button to submit
|
||||
await page.click('[data-testid="confirm-book-button"]');
|
||||
|
||||
// Verify it reached the end
|
||||
await expect(page).toHaveURL(/.*isSuccessBookingPage=true.*/, { timeout: 15000 });
|
||||
await expect(page.getByTestId('success-page')).toBeVisible();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user