feat: firstAndLastName variant for name field (#8671)
* Add split full name variant * Share propsType across fieldTypes and components * Simplify Components * Add assertions for required field indicator * Fix test as name cant be used as a custom field right now * Make it disabled during reschedule * Fix UI issues in dark mode * Support adding links in boolean checkbox * Revert "Support adding links in boolean checkbox" This reverts commit 31252f8a5f445f8289a09445124109a4a9c3d33b. * Make sure getBookingFields isnt import client side * PR feedback addressed from Carina * DRY Code * Fix Dialog --------- Co-authored-by: Carina Wollendorfer <[email protected]>
This commit is contained in:
1 parent
47f65bb19f
commit
f1c981fdcf
22 files changed
+1767
-758
No files matched your search
@@ -17,7 +17,7 @@ import {
|
||||
allowDisablingHostConfirmationEmails,
|
||||
} from "@calcom/features/ee/workflows/lib/allowDisablingStandardEmails";
|
||||
import { FormBuilder } from "@calcom/features/form-builder/FormBuilder";
|
||||
import type { EditableSchema } from "@calcom/features/form-builder/FormBuilderFieldsSchema";
|
||||
import type { EditableSchema } from "@calcom/features/form-builder/schema";
|
||||
import { BookerLayoutSelector } from "@calcom/features/settings/BookerLayoutSelector";
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { APP_NAME, CAL_URL } from "@calcom/lib/constants";
|
||||
|
||||
@@ -23,9 +23,9 @@ import {
|
||||
useIsEmbed,
|
||||
} from "@calcom/embed-core/embed-iframe";
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
import { SystemField } from "@calcom/features/bookings/lib/SystemField";
|
||||
import { getBookingWithResponses } from "@calcom/features/bookings/lib/get-booking";
|
||||
import {
|
||||
SystemField,
|
||||
getBookingFieldsWithSystemFields,
|
||||
SMS_REMINDER_NUMBER_FIELD,
|
||||
} from "@calcom/features/bookings/lib/getBookingFields";
|
||||
|
||||
@@ -5,6 +5,7 @@ import { uuid } from "short-uuid";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
import { test } from "./lib/fixtures";
|
||||
import { createHttpServer, waitFor, selectFirstAvailableTimeSlotNextMonth } from "./lib/testUtils";
|
||||
@@ -40,6 +41,101 @@ test.describe("Manage Booking Questions", () => {
|
||||
|
||||
await runTestStepsCommonForTeamAndUserEventType(page, context, webhookReceiver);
|
||||
});
|
||||
|
||||
test("Split 'Full name' into 'First name' and 'Last name'", async ({
|
||||
page,
|
||||
users,
|
||||
context,
|
||||
}, testInfo) => {
|
||||
// Considering there are many steps in it, it would need more than default test timeout
|
||||
test.setTimeout(testInfo.timeout * 3);
|
||||
const user = await createAndLoginUserWithEventTypes({ page, users });
|
||||
const webhookReceiver = await addWebhook(user);
|
||||
await test.step("Go to first EventType Page ", async () => {
|
||||
const $eventTypes = page.locator("[data-testid=event-types] > li a");
|
||||
const firstEventTypeElement = $eventTypes.first();
|
||||
|
||||
await firstEventTypeElement.click();
|
||||
});
|
||||
|
||||
await test.step("Open the 'Name' field dialog", async () => {
|
||||
await page.click('[href$="tabName=advanced"]');
|
||||
await page.locator('[data-testid="field-name"] [data-testid="edit-field-action"]').click();
|
||||
});
|
||||
|
||||
await test.step("Toggle on the variant toggle and save Event Type", async () => {
|
||||
await page.click('[data-testid="variant-toggle"]');
|
||||
await page.click("[data-testid=field-add-save]");
|
||||
await saveEventType(page);
|
||||
});
|
||||
|
||||
await test.step("Book a time slot with firstName and lastName provided separately", async () => {
|
||||
await doOnFreshPreview(page, context, async (page) => {
|
||||
await expectSystemFieldsToBeThereOnBookingPage({ page, isFirstAndLastNameVariant: true });
|
||||
await bookTimeSlot({
|
||||
page,
|
||||
name: { firstName: "John", lastName: "Doe" },
|
||||
email: "[email protected]",
|
||||
});
|
||||
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
|
||||
expect(await page.locator('[data-testid="attendee-name-John Doe"]').nth(0).textContent()).toBe(
|
||||
"John Doe"
|
||||
);
|
||||
await expectWebhookToBeCalled(webhookReceiver, {
|
||||
triggerEvent: WebhookTriggerEvents.BOOKING_CREATED,
|
||||
payload: {
|
||||
attendees: [
|
||||
{
|
||||
// It would have full Name only
|
||||
name: "John Doe",
|
||||
email: "[email protected]",
|
||||
},
|
||||
],
|
||||
responses: {
|
||||
name: {
|
||||
label: "your_name",
|
||||
value: {
|
||||
firstName: "John",
|
||||
lastName: "Doe",
|
||||
},
|
||||
},
|
||||
email: {
|
||||
label: "email_address",
|
||||
value: "[email protected]",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
await test.step("Verify that we can prefill name and other fields correctly", async () => {
|
||||
await doOnFreshPreview(page, context, async (page) => {
|
||||
const url = page.url();
|
||||
const prefillUrl = new URL(url);
|
||||
prefillUrl.searchParams.append("name", "John Johny Janardan");
|
||||
prefillUrl.searchParams.append("email", "[email protected]");
|
||||
prefillUrl.searchParams.append("guests", "[email protected]");
|
||||
prefillUrl.searchParams.append("guests", "[email protected]");
|
||||
prefillUrl.searchParams.append("notes", "This is an additional note");
|
||||
await page.goto(prefillUrl.toString());
|
||||
await bookTimeSlot({ page, skipSubmission: true });
|
||||
await expectSystemFieldsToBeThereOnBookingPage({
|
||||
page,
|
||||
isFirstAndLastNameVariant: true,
|
||||
values: {
|
||||
name: {
|
||||
firstName: "John",
|
||||
lastName: "Johny Janardan",
|
||||
},
|
||||
email: "[email protected]",
|
||||
guests: ["[email protected]", "[email protected]"],
|
||||
notes: "This is an additional note",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("For Team EventType", () => {
|
||||
@@ -91,12 +187,23 @@ async function runTestStepsCommonForTeamAndUserEventType(
|
||||
}
|
||||
) {
|
||||
await page.click('[href$="tabName=advanced"]');
|
||||
|
||||
await test.step("Check that all the system questions are shown in the list", async () => {
|
||||
await page.locator("[data-testid=field-name]").isVisible();
|
||||
await page.locator("[data-testid=field-email]").isVisible();
|
||||
await page.locator("[data-testid=field-notes]").isVisible();
|
||||
await page.locator("[data-testid=field-guests]").isVisible();
|
||||
await page.locator("[data-testid=field-rescheduleReason]").isVisible();
|
||||
// It is conditional
|
||||
// await page.locator("data-testid=field-location").isVisible();
|
||||
});
|
||||
|
||||
await test.step("Add Question and see that it's shown on Booking Page at appropriate position", async () => {
|
||||
await addQuestionAndSave({
|
||||
page,
|
||||
question: {
|
||||
name: "how_are_you",
|
||||
type: "Name",
|
||||
type: "Address",
|
||||
label: "How are you?",
|
||||
placeholder: "I'm fine, thanks",
|
||||
required: true,
|
||||
@@ -104,13 +211,13 @@ async function runTestStepsCommonForTeamAndUserEventType(
|
||||
});
|
||||
|
||||
await doOnFreshPreview(page, context, async (page) => {
|
||||
const allFieldsLocator = await expectSystemFieldsToBeThere(page);
|
||||
const allFieldsLocator = await expectSystemFieldsToBeThereOnBookingPage({ page });
|
||||
const userFieldLocator = allFieldsLocator.nth(5);
|
||||
|
||||
await expect(userFieldLocator.locator('[name="how_are_you"]')).toBeVisible();
|
||||
// There are 2 labels right now. Will be one in future. The second one is hidden
|
||||
expect(await getLabelText(userFieldLocator)).toBe("How are you?");
|
||||
await expect(userFieldLocator.locator("input[type=text]")).toBeVisible();
|
||||
await expect(userFieldLocator.locator("input")).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -217,7 +324,24 @@ async function runTestStepsCommonForTeamAndUserEventType(
|
||||
});
|
||||
}
|
||||
|
||||
async function expectSystemFieldsToBeThere(page: Page) {
|
||||
async function expectSystemFieldsToBeThereOnBookingPage({
|
||||
page,
|
||||
isFirstAndLastNameVariant,
|
||||
values,
|
||||
}: {
|
||||
page: Page;
|
||||
isFirstAndLastNameVariant?: boolean;
|
||||
values?: Partial<{
|
||||
name: {
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
fullName?: string;
|
||||
};
|
||||
email: string;
|
||||
notes: string;
|
||||
guests: string[];
|
||||
}>;
|
||||
}) {
|
||||
const allFieldsLocator = page.locator("[data-fob-field-name]:not(.hidden)");
|
||||
const nameLocator = allFieldsLocator.nth(0);
|
||||
const emailLocator = allFieldsLocator.nth(1);
|
||||
@@ -226,11 +350,44 @@ async function expectSystemFieldsToBeThere(page: Page) {
|
||||
const additionalNotes = allFieldsLocator.nth(3);
|
||||
const guestsLocator = allFieldsLocator.nth(4);
|
||||
|
||||
await expect(nameLocator.locator('[name="name"]')).toBeVisible();
|
||||
await expect(emailLocator.locator('[name="email"]')).toBeVisible();
|
||||
if (isFirstAndLastNameVariant) {
|
||||
if (values?.name) {
|
||||
await expect(nameLocator.locator('[name="firstName"]')).toHaveValue(values?.name?.firstName || "");
|
||||
await expect(nameLocator.locator('[name="lastName"]')).toHaveValue(values?.name?.lastName || "");
|
||||
expect(await nameLocator.locator(".testid-firstName > label").innerText()).toContain("*");
|
||||
} else {
|
||||
await expect(nameLocator.locator('[name="firstName"]')).toBeVisible();
|
||||
await expect(nameLocator.locator('[name="lastName"]')).toBeVisible();
|
||||
}
|
||||
} else {
|
||||
if (values?.name) {
|
||||
await expect(nameLocator.locator('[name="name"]')).toHaveValue(values?.name?.fullName || "");
|
||||
}
|
||||
await expect(nameLocator.locator('[name="name"]')).toBeVisible();
|
||||
expect(await nameLocator.locator("label").innerText()).toContain("*");
|
||||
}
|
||||
|
||||
await expect(additionalNotes.locator('[name="notes"]')).toBeVisible();
|
||||
await expect(guestsLocator.locator("button")).toBeVisible();
|
||||
if (values?.email) {
|
||||
await expect(emailLocator.locator('[name="email"]')).toHaveValue(values?.email || "");
|
||||
} else {
|
||||
await expect(emailLocator.locator('[name="email"]')).toBeVisible();
|
||||
}
|
||||
|
||||
if (values?.notes) {
|
||||
await expect(additionalNotes.locator('[name="notes"]')).toHaveValue(values?.notes);
|
||||
} else {
|
||||
await expect(additionalNotes.locator('[name="notes"]')).toBeVisible();
|
||||
}
|
||||
|
||||
if (values?.guests) {
|
||||
const allGuestsLocators = guestsLocator.locator('[type="email"]');
|
||||
for (let i = 0; i < values.guests.length; i++) {
|
||||
await expect(allGuestsLocators.nth(i)).toHaveValue(values.guests[i] || "");
|
||||
}
|
||||
await expect(guestsLocator.locator("[data-testid='add-another-guest']")).toBeVisible();
|
||||
} else {
|
||||
await expect(guestsLocator.locator("[data-testid='add-guests']")).toBeVisible();
|
||||
}
|
||||
return allFieldsLocator;
|
||||
}
|
||||
|
||||
@@ -238,11 +395,33 @@ async function expectSystemFieldsToBeThere(page: Page) {
|
||||
// Verify webhook is sent with the correct data, DB is correct (including metadata)
|
||||
|
||||
//TODO: Verify that prefill works
|
||||
async function bookTimeSlot({ page, name, email }: { page: Page; name: string; email: string }) {
|
||||
// --- fill form
|
||||
await page.fill('[name="name"]', name);
|
||||
await page.fill('[name="email"]', email);
|
||||
await page.press('[name="email"]', "Enter");
|
||||
async function bookTimeSlot({
|
||||
page,
|
||||
name,
|
||||
email,
|
||||
skipSubmission = false,
|
||||
}: {
|
||||
page: Page;
|
||||
name?: string | { firstName: string; lastName?: string };
|
||||
email?: string;
|
||||
skipSubmission?: boolean;
|
||||
}) {
|
||||
if (name) {
|
||||
if (typeof name === "string") {
|
||||
await page.fill('[name="name"]', name);
|
||||
} else {
|
||||
await page.fill('[name="firstName"]', name.firstName);
|
||||
if (name.lastName) {
|
||||
await page.fill('[name="lastName"]', name.lastName);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (email) {
|
||||
await page.fill('[name="email"]', email);
|
||||
}
|
||||
if (!skipSubmission) {
|
||||
await page.press('[name="email"]', "Enter");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -424,3 +603,22 @@ async function addWebhook(
|
||||
|
||||
return webhookReceiver;
|
||||
}
|
||||
|
||||
async function expectWebhookToBeCalled(
|
||||
webhookReceiver: Awaited<ReturnType<typeof addWebhook>>,
|
||||
expectedBody: {
|
||||
triggerEvent: WebhookTriggerEvents;
|
||||
payload: Omit<Partial<CalendarEvent>, "attendees"> & {
|
||||
attendees: Partial<CalendarEvent["attendees"][number]>[];
|
||||
};
|
||||
}
|
||||
) {
|
||||
await waitFor(() => {
|
||||
expect(webhookReceiver.requestList.length).toBe(1);
|
||||
});
|
||||
const [request] = webhookReceiver.requestList;
|
||||
|
||||
const body = request.body;
|
||||
|
||||
expect(body).toMatchObject(expectedBody);
|
||||
}
|
||||
@@ -1870,6 +1870,9 @@
|
||||
"open_dialog_with_element_click": "Open your Cal dialog when someone clicks an element.",
|
||||
"need_help_embedding": "Need help? See our guides for embedding Cal on Wix, Squarespace, or WordPress, check our common questions, or explore advanced embed options.",
|
||||
"book_my_cal": "Book my Cal",
|
||||
"first_name": "First name",
|
||||
"last_name": "Last name",
|
||||
"first_last_name": "First name, Last name",
|
||||
"invite_as": "Invite as",
|
||||
"form_updated_successfully": "Form updated successfully.",
|
||||
"disable_attendees_confirmation_emails": "Disable default confirmation emails for attendees",
|
||||
|
||||
Reference in new issue
Block a user