test: Create E2E tests for a collective event type (teste2e-bookCollective) (#12565)

* refactor

* add localize / refactor

* add changes

* fix conflicts

* replace text by testId

* refactor

* Update regularBookings.ts

* fix conflicts

* fix failing check

* fix failing test

---------

Co-authored-by: gitstart-calcom <gitstart-calcom@users.noreply.github.com>
Co-authored-by: Keith Williams <keithwillcode@gmail.com>
Co-authored-by: GitStart-Cal.com <121884634+gitstart-calcom@users.noreply.github.com>
This commit is contained in:
gitstart-app[bot]
2024-01-28 20:55:17 -03:00
committed by GitHub
co-authored by gitstart-calcom Keith Williams GitStart-Cal.com
parent 4d128971bb
commit cc0ff17d97
5 changed files with 165 additions and 10 deletions
@@ -321,6 +321,7 @@ export default function Success(props: PageProps) {
<div className="-mb-4 ml-4 mt-2">
<Link
href={allRemainingBookings ? "/bookings/recurring" : "/bookings/upcoming"}
data-testid="back-to-bookings"
className="hover:bg-subtle text-subtle hover:text-default mt-2 inline-flex px-1 py-2 text-sm dark:hover:bg-transparent">
<ChevronLeft className="h-5 w-5 rtl:rotate-180" /> {t("back_to_bookings")}
</Link>
@@ -0,0 +1,54 @@
import { test } from "../../lib/fixtures";
test.describe("Collective event type", () => {
const teamEventTitle = "Test Managed Event Type";
let userId: number;
test.beforeEach(async ({ page, users, bookingPage }) => {
const userFixture = await users.create(
{ name: "testuser" },
{ hasTeam: true, schedulingType: "COLLECTIVE", teamEventTitle }
);
await userFixture.apiLogin();
userId = userFixture.id;
await page.goto("/event-types");
await bookingPage.goToEventType(teamEventTitle);
});
test("Book a Collective event type", async ({ bookingPage }) => {
const eventTypePage = await bookingPage.previewEventType();
await bookingPage.selectTimeSlot(eventTypePage);
await bookingPage.fillEmailAndName(eventTypePage);
await bookingPage.confirmBooking(eventTypePage);
await bookingPage.backToBookings(eventTypePage);
await bookingPage.assertLabelWithCorrectTeamName(eventTypePage, teamEventTitle);
await bookingPage.assertBookingWithCorrectTitleAndDescription(eventTypePage, {
profileName: "testuser",
bookingName: teamEventTitle,
teamName: `user-id-${userId}'s Team`,
});
await bookingPage.clickOnBooking(eventTypePage, teamEventTitle);
await bookingPage.rescheduleBooking(eventTypePage);
await bookingPage.assertBookingRescheduled(eventTypePage);
await bookingPage.cancelBookingWithReason(eventTypePage);
await bookingPage.assertBookingCanceled(eventTypePage);
});
test("Book a Collective event type (with added guest)", async ({ bookingPage }) => {
const eventTypePage = await bookingPage.previewEventType();
await bookingPage.selectTimeSlot(eventTypePage);
await bookingPage.fillEmailAndName(eventTypePage);
await bookingPage.addGuests(eventTypePage, { guests: ["test@example.com"] });
await bookingPage.confirmBooking(eventTypePage);
await bookingPage.backToBookings(eventTypePage);
await bookingPage.assertLabelWithCorrectTeamName(eventTypePage, teamEventTitle);
await bookingPage.assertBookingWithCorrectTitleAndDescription(eventTypePage, {
profileName: "testuser",
bookingName: teamEventTitle,
teamName: `user-id-${userId}'s Team`,
aditionalGuestEmail: "test@example.com",
});
await bookingPage.clickOnBooking(eventTypePage, teamEventTitle);
await bookingPage.rescheduleBooking(eventTypePage);
await bookingPage.assertBookingRescheduled(eventTypePage);
await bookingPage.cancelBookingWithReason(eventTypePage);
await bookingPage.assertBookingCanceled(eventTypePage);
});
});
+107 -8
View File
@@ -26,6 +26,8 @@ interface QuestionActions {
[key: string]: () => Promise<void>;
}
type teamBookingtypes = { isManagedType?: boolean; isRoundRobinType?: boolean; isCollectiveType?: boolean };
type customLocators = {
shouldChangeSelectLocator: boolean;
shouldUseLastRadioGroupLocator: boolean;
@@ -205,7 +207,12 @@ export function createBookingPageFixture(page: Page) {
goToEventType: async (eventType: string) => {
await page.getByRole("link", { name: eventType }).click();
},
goToPage: async (pageName: string, page: Page) => {
await page.getByRole("link", { name: pageName }).click();
},
backToBookings: async (page: Page) => {
await page.getByTestId("back-to-bookings").click();
},
goToTab: async (tabName: string) => {
await page.getByTestId(`vertical-tab-${tabName}`).click();
},
@@ -405,17 +412,102 @@ export function createBookingPageFixture(page: Page) {
const confirmButton = options.isReschedule ? "confirm-reschedule-button" : "confirm-book-button";
await fillAllQuestions(eventTypePage, questions, options);
await eventTypePage.getByTestId(confirmButton).click();
await eventTypePage.waitForTimeout(400);
if (await eventTypePage.getByRole("heading", { name: "Could not book the meeting." }).isVisible()) {
await eventTypePage.getByTestId("back").click();
await eventTypePage.getByTestId("time").last().click();
await fillAllQuestions(eventTypePage, questions, options);
await eventTypePage.getByTestId(confirmButton).click();
}
const scheduleSuccessfullyPage = eventTypePage.getByText(scheduleSuccessfullyText);
await scheduleSuccessfullyPage.waitFor({ state: "visible" });
await expect(scheduleSuccessfullyPage).toBeVisible();
},
addGuests: async (eventTypePage: Page, options: { guests: string[] }) => {
await eventTypePage.getByTestId("add-guests").click();
for (const guest of options.guests) {
await eventTypePage.getByPlaceholder("Email").fill(guest);
}
},
createTeam: async (name: string) => {
await page.getByTestId("teams-test").click();
await page.getByTestId("new-team-btn").click();
await page.getByPlaceholder("Acme Inc.").click();
await page.getByPlaceholder("Acme Inc.").fill(name);
await page.getByTestId("continue-button").click();
await page.getByTestId("publish-button").click();
await page.getByTestId("vertical-tab-Back").click();
},
createTeamEventType: async (name: string, options: teamBookingtypes) => {
await page.getByTestId("new-event-type").click();
await page.getByTestId("option-0").click();
// We first simulate to create a default event type to check if managed option is not available
const managedEventDescription = (await localize("en"))("managed_event_description");
const roundRobinEventDescription = (await localize("en"))("round_robin_description");
const collectiveEventDescription = (await localize("en"))("collective_description");
const quickChatText = (await localize("en"))("quick_chat");
await expect(page.locator("div").filter({ hasText: managedEventDescription })).toBeHidden();
await page.getByTestId("dialog-rejection").click();
await page.getByTestId("new-event-type").click();
await page.getByTestId("option-team-1").click();
await page.getByPlaceholder(quickChatText).fill(name);
if (options.isCollectiveType) {
await page
.locator("div")
.filter({ hasText: `Collective${collectiveEventDescription}` })
.getByRole("radio")
.first()
.click();
}
if (options.isRoundRobinType) {
await page
.locator("div")
.filter({ hasText: `Round Robin${roundRobinEventDescription}` })
.getByRole("radio")
.nth(1)
.click();
}
if (options.isManagedType) {
await page
.locator("div")
.filter({ hasText: `Managed Event${managedEventDescription}` })
.getByRole("radio")
.last()
.click();
const managedEventClarification = (await localize("en"))("managed_event_url_clarification");
await expect(page.getByText(managedEventClarification)).toBeVisible();
}
const continueText = (await localize("en"))("continue");
const toast = page.getByTestId("toast-success");
await page.getByRole("button", { name: continueText }).click();
expect(toast).toBeTruthy();
await page.getByTestId("update-eventtype").click();
},
assertLabelWithCorrectTeamName: async (page: Page, teamName: string) => {
await expect(page.getByRole("link", { name: teamName }).first()).toBeVisible();
},
assertBookingWithCorrectTitleAndDescription: async (
page: Page,
options: { profileName: string; bookingName: string; teamName: string; aditionalGuestEmail?: string }
) => {
options.aditionalGuestEmail
? await expect(
page.getByRole("link", {
name: `${options.bookingName} between ${options.teamName} and ${options.profileName} You , ${options.profileName} and ${options.aditionalGuestEmail}`,
})
).toBeVisible()
: await expect(
page.getByRole("link", {
name: `${options.bookingName} between ${options.teamName} and ${options.profileName} You and ${options.profileName}`,
})
).toBeVisible();
},
clickOnBooking: async (page: Page, teamName: string) => {
await page.getByRole("link", { name: teamName }).first().click();
},
checkField: async (question: string, options?: { isOptional: boolean }) => {
if (options?.isOptional) {
@@ -635,5 +727,12 @@ export function createBookingPageFixture(page: Page) {
await page.getByTestId("booking-item").first().getByText("Reject").click();
await page.getByTestId("rejection-confirm").click();
},
fillEmailAndName: async (eventTypePage: Page) => {
const emailLabel = (await localize("en"))("email_address");
const nameLabel = (await localize("en"))("your_name");
await eventTypePage.getByLabel(emailLabel).fill(EMAIL);
await eventTypePage.getByLabel(nameLabel).fill("testuser");
},
};
}
@@ -158,7 +158,8 @@ export const CreateANewTeamForm = () => {
color="primary"
EndIcon={ArrowRight}
type="submit"
className="w-full justify-center">
className="w-full justify-center"
data-testid="continue-button">
{t(flag.submitLabel)}
</Button>
</div>
+1 -1
View File
@@ -742,7 +742,7 @@ const NavigationItem: React.FC<{
/>
)}
{isLocaleReady ? (
<span className="hidden w-full justify-between lg:flex">
<span className="hidden w-full justify-between lg:flex" data-testid={`${item.name}-test`}>
<div className="flex">{t(item.name)}</div>
{item.badge && item.badge}
</span>