Files
cal.diy/packages/embeds/embed-core/playwright/tests/action-based.e2e.ts
T
6d5d2a1c4d feat: new App install flow (#11975)
* feat(appStore): add isOAuth config

* refactor(appStore): EventTypeAppSettngsInterface

* refactor(qr_code): split EventTypeAppCardInterface and EventTypeAppSettingsInterface

* feat(appStore): redirect to onboarding for stripe and basecam

* fix(ui/ScrollableArea): overflow indicator not working

* feat(apps): new install app flow

* fix(configureStep): get disabled props for settings

* fix: getAppInstallsBySlug now use teamIds

* chore: Alby to AppSettingsInterface

* chore: Giphy to appsettings interface

* chore: GTM migration

* chore: GT4 - migration

* chore: fathom migration

* chore: paypal

* feat: basecamp migration

* feat: metapixel migration

* feat:plausable

* feat:stripe

* fix merge issues

* fix merge issues in new app install flow steps

* wip: callback to onboarding

* fix: imports

* fix: more imports

* feat: use redirect to onboarding on install flow

* feat: New app install flow 2 (#14077)

* fix: redirect to event-type after oauth flow

* When clicking on install new app button, only redirect to the new app install flow if it is an oAuth app or an app that extends the EventType feature in it's config

* code refactor, skip event-type step

* removed extra consoles

* so that no one can change the eventTypeId in url

* theme support enabled

* only pass eventTypeId instead of whole evetType obj to OmniInstallAppButton

* fix: clicking on event-type gives error and redirects to /apps

* saved appOnboardingRedirectUrl to OAuth State

* fix: a user having no team breaks the onboarding flow

* add optional chaining to appMetadata.extendsFeature and appMetadata.isOAuth;

* encode appOnboardingRedirectUrl

* fix: dark theme ui issues

* skip configure step if no-event types

if user/team does not have event-type then skip configure step and goto apps/installed/[category]

* exclude calendars from apps- onboarding flow

* Update getAppOnboardingRedirectUrl.ts

* fix: On configure step, inputs aren't showing errors

* change route from `apps/onboarding` to `apps/installation`

* fix: flow not correctly working for teams

* should only allow team ADMIN or OWER to install an app to team

* Prevent two payment apps to be enabled

* removed loading state

* Fix type error

* undo new-app-flow from OmniInstallAppButton

* remove OAuth Step, handle step numbering

* fix: redirect url

* getAppOnboardingRedirectUrl refactor

* for debugging

* Revert "for debugging"

This reverts commit b9362c1a8f47f2280e684c213d7ec08d04a8ac4c.

* fix: added toaster

* feat: added support to select multiple events (almost)

* hide button

* Move inner form outside outer form using portal

Due to limitations with nested forms in React Hook Form, moved the inner form outside the outer form using a portal to ensure proper form handling.

* submit buttons refs madness

* removed configure step

we had to use query params to manage selected event-types, between routes which was causing 2 issues:
* each time we selected or unselected an event the whole page was reloaded including getserversideprops being called again and again
* the form was reloaded causing more issues

* removed extra unwanted code

* small fix

* fix: type error

* fix: types

* implemented suggested changes

* removed step footer
* fixed error.message
* removed commented styles

* removed step footer

* fix: Display team event types instead of user's on event types step when team selected

* fix: typo

* removed shouldLockDisableProps

* refactor setUpdatedEventTypesStatus, fix type

* removed extra code

* can't delete while saving

* added translations

* fix: loading in select account step, fix handle onSelect params type

* Fix typo

---------

Co-authored-by: Joe Au-Yeung <[email protected]>

* fix: type errors

* fix: failing tests

---------

Co-authored-by: sean-brydon <[email protected]>
Co-authored-by: Keith Williams <[email protected]>
Co-authored-by: Joe Au-Yeung <[email protected]>
Co-authored-by: Somay Chauhan <[email protected]>
2024-04-10 16:24:31 +00:00

299 lines
11 KiB
TypeScript

import type { Page } from "@playwright/test";
import { expect } from "@playwright/test";
// eslint-disable-next-line no-restricted-imports
import { test } from "@calcom/web/playwright/lib/fixtures";
// eslint-disable-next-line no-restricted-imports
import type { Fixtures } from "@calcom/web/playwright/lib/fixtures";
// eslint-disable-next-line no-restricted-imports
import { selectFirstAvailableTimeSlotNextMonth } from "@calcom/web/playwright/lib/testUtils";
import {
todo,
getEmbedIframe,
bookFirstEvent,
getBooking,
deleteAllBookingsByEmail,
rescheduleEvent,
} from "../lib/testUtils";
// in parallel mode sometimes handleNewBooking endpoint throws "No available users found" error, this never happens in serial mode.
test.describe.configure({ mode: "serial" });
async function bookFirstFreeUserEventThroughEmbed({
addEmbedListeners,
page,
getActionFiredDetails,
}: {
addEmbedListeners: Fixtures["embeds"]["addEmbedListeners"];
page: Page;
getActionFiredDetails: Fixtures["embeds"]["getActionFiredDetails"];
}) {
const embedButtonLocator = page.locator('[data-cal-link="free"]').first();
await page.goto("/");
// Obtain cal namespace from the element being clicked itself, so that addEmbedListeners always listen to correct namespace
const calNamespace = (await embedButtonLocator.getAttribute("data-cal-namespace")) || "";
await addEmbedListeners(calNamespace);
// Goto / again so that initScript attached using addEmbedListeners can work now.
await page.goto("/");
await embedButtonLocator.click();
const embedIframe = await getEmbedIframe({ calNamespace, page, pathname: "/free" });
await expect(embedIframe).toBeEmbedCalLink(calNamespace, getActionFiredDetails, {
pathname: "/free",
});
if (!embedIframe) {
throw new Error("Embed iframe not found");
}
const booking = await bookFirstEvent("free", embedIframe, page);
return booking;
}
//TODO: Change these tests to use a user/eventType per embed type atleast. This is so that we can test different themes,layouts configured in App or per EventType
test.describe("Popup Tests", () => {
test.afterEach(async () => {
await deleteAllBookingsByEmail("[email protected]");
});
test("should open embed iframe on click - Configured with light theme", async ({ page, embeds }) => {
await deleteAllBookingsByEmail("[email protected]");
const calNamespace = "e2ePopupLightTheme";
await embeds.gotoPlayground({ calNamespace, url: "/" });
await page.click(`[data-cal-namespace="${calNamespace}"]`);
const embedIframe = await getEmbedIframe({ calNamespace, page, pathname: "/free" });
await expect(embedIframe).toBeEmbedCalLink(calNamespace, embeds.getActionFiredDetails, {
pathname: "/free",
});
// expect(await page.screenshot()).toMatchSnapshot("event-types-list.png");
if (!embedIframe) {
throw new Error("Embed iframe not found");
}
const { uid: bookingId } = await bookFirstEvent("free", embedIframe, page);
const booking = await getBooking(bookingId);
expect(booking.attendees.length).toBe(1);
await deleteAllBookingsByEmail("[email protected]");
});
test("should be able to reschedule", async ({
page,
embeds: { addEmbedListeners, getActionFiredDetails },
}) => {
const booking = await test.step("Create a booking", async () => {
return await bookFirstFreeUserEventThroughEmbed({
page,
addEmbedListeners,
getActionFiredDetails,
});
});
await test.step("Reschedule the booking", async () => {
await addEmbedListeners("popupReschedule");
await page.goto(`/?popupRescheduleId=${booking.uid}`);
await page.click('[data-cal-namespace="popupReschedule"]');
const calNamespace = "popupReschedule";
const embedIframe = await getEmbedIframe({ calNamespace, page, pathname: booking.eventSlug });
if (!embedIframe) {
throw new Error("Embed iframe not found");
}
await rescheduleEvent("free", embedIframe, page);
});
});
todo("Add snapshot test for embed iframe");
test("should open Routing Forms embed on click", async ({
page,
embeds: { addEmbedListeners, getActionFiredDetails },
}) => {
await deleteAllBookingsByEmail("[email protected]");
const calNamespace = "routingFormAuto";
await addEmbedListeners(calNamespace);
await page.goto("/?only=prerender-test");
let embedIframe = await getEmbedIframe({
calNamespace,
page,
pathname: "/forms/948ae412-d995-4865-875a-48302588de03",
});
expect(embedIframe).toBeFalsy();
await page.click(
`[data-cal-namespace=${calNamespace}][data-cal-link="forms/948ae412-d995-4865-875a-48302588de03"]`
);
embedIframe = await getEmbedIframe({
calNamespace,
page,
pathname: "/forms/948ae412-d995-4865-875a-48302588de03",
});
if (!embedIframe) {
throw new Error("Routing Form embed iframe not found");
}
await expect(embedIframe).toBeEmbedCalLink(calNamespace, getActionFiredDetails, {
pathname: "/forms/948ae412-d995-4865-875a-48302588de03",
});
await expect(embedIframe.locator("text=Seeded Form - Pro")).toBeVisible();
});
test.describe("Floating Button Popup", () => {
test.describe("Pro User - Configured in App with default setting of system theme", () => {
test("should open embed iframe according to system theme when no theme is configured through Embed API", async ({
page,
embeds: { addEmbedListeners, getActionFiredDetails },
}) => {
const calNamespace = "floatingButton";
await addEmbedListeners(calNamespace);
await page.goto("/?only=ns:floatingButton");
await page.click('[data-cal-namespace="floatingButton"] > button');
const embedIframe = await getEmbedIframe({ calNamespace, page, pathname: "/pro" });
await expect(embedIframe).toBeEmbedCalLink(calNamespace, getActionFiredDetails, {
pathname: "/pro",
});
if (!embedIframe) {
throw new Error("Embed iframe not found");
}
const html = embedIframe.locator("html");
// Expect "light" theme as configured in App for pro user.
await expect(html).toHaveAttribute("class", "light");
const { uid: bookingId } = await bookFirstEvent("pro", embedIframe, page);
const booking = await getBooking(bookingId);
expect(booking.attendees.length).toBe(3);
await test.step("Close the modal", async () => {
await page.locator("cal-modal-box .close").click();
await expect(page.locator("cal-modal-box")).toBeHidden();
await expect(page.locator("cal-modal-box iframe")).toBeHidden();
});
});
test("should open embed iframe according to system theme when configured with 'auto' theme using Embed API", async ({
page,
embeds: { addEmbedListeners, getActionFiredDetails },
}) => {
const calNamespace = "floatingButton";
await addEmbedListeners(calNamespace);
await page.goto("/?only=ns:floatingButton");
await page.click('[data-cal-namespace="floatingButton"] > button');
const embedIframe = await getEmbedIframe({ calNamespace, page, pathname: "/pro" });
await expect(embedIframe).toBeEmbedCalLink(calNamespace, getActionFiredDetails, {
pathname: "/pro",
});
if (!embedIframe) {
throw new Error("Embed iframe not found");
}
const html = embedIframe.locator("html");
const prefersDarkScheme = await page.evaluate(() => {
return window.matchMedia("(prefers-color-scheme: dark)").matches;
});
// Detect browser preference and expect accordingly
await expect(html).toHaveAttribute("class", prefersDarkScheme ? "dark" : "light");
});
test("should open embed iframe(Booker Profile Page) with dark theme when configured with dark theme using Embed API", async ({
page,
embeds: { addEmbedListeners, getActionFiredDetails },
}) => {
const calNamespace = "floatingButton";
await addEmbedListeners(calNamespace);
await page.goto("/?only=ns:floatingButton&theme=dark");
await page.click('[data-cal-namespace="floatingButton"] > button');
const embedIframe = await getEmbedIframe({ calNamespace, page, pathname: "/pro" });
await expect(embedIframe).toBeEmbedCalLink(calNamespace, getActionFiredDetails, {
pathname: "/pro",
});
if (!embedIframe) {
throw new Error("Embed iframe not found");
}
const html = embedIframe.locator("html");
await expect(html).toHaveAttribute("class", "dark");
});
test("should open embed iframe(Event Booking Page) with dark theme when configured with dark theme using Embed API", async ({
page,
embeds: { addEmbedListeners, getActionFiredDetails },
}) => {
const calNamespace = "floatingButton";
await addEmbedListeners(calNamespace);
await page.goto("/?only=ns:floatingButton&cal-link=pro/30min&theme=dark");
await page.click('[data-cal-namespace="floatingButton"] > button');
const embedIframe = await getEmbedIframe({ calNamespace, page, pathname: "/pro/30min" });
await expect(embedIframe).toBeEmbedCalLink(calNamespace, getActionFiredDetails, {
pathname: "/pro/30min",
});
if (!embedIframe) {
throw new Error("Embed iframe not found");
}
const html = embedIframe.locator("html");
await expect(html).toHaveAttribute("class", "dark");
});
});
});
test("prendered embed should be loaded and apply the config given to it", async ({ page, embeds }) => {
const calNamespace = "e2ePrerenderLightTheme";
const calLink = "/free/30min";
await embeds.gotoPlayground({ calNamespace, url: "/?only=prerender-test" });
await expectPrerenderedIframe({ calNamespace, calLink, embeds, page });
await page.click(`[data-cal-namespace="${calNamespace}"]`);
const embedIframe = await getEmbedIframe({ calNamespace, page, pathname: calLink });
// eslint-disable-next-line playwright/no-conditional-in-test
if (!embedIframe) {
throw new Error("Embed iframe not found");
}
await selectFirstAvailableTimeSlotNextMonth(embedIframe);
await expect(embedIframe.locator('[name="name"]')).toHaveValue("Preloaded Prefilled");
await expect(embedIframe.locator('[name="email"]')).toHaveValue("[email protected]");
await expect(embedIframe).toBeEmbedCalLink(calNamespace, embeds.getActionFiredDetails, {
pathname: calLink,
});
});
});
async function expectPrerenderedIframe({
page,
calNamespace,
calLink,
embeds,
}: {
page: Page;
calNamespace: string;
calLink: string;
embeds: Fixtures["embeds"];
}) {
const prerenderedIframe = await getEmbedIframe({ calNamespace, page, pathname: calLink });
if (!prerenderedIframe) {
throw new Error("Prerendered iframe not found");
}
await expect(prerenderedIframe).toBeEmbedCalLink(
calNamespace,
embeds.getActionFiredDetails,
{
pathname: calLink,
},
true
);
}