From 96fcf7beece495d7d11e05950ec362527d266e2c Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Fri, 28 Mar 2025 10:20:09 +0530 Subject: [PATCH] fix: Flaky organization.spec.ts test for i.cal.com (#20421) * Fix flakiness in checjly * Fix isEmbed check --- __checks__/organization.spec.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/__checks__/organization.spec.ts b/__checks__/organization.spec.ts index 65255cffdc..95af227fe0 100644 --- a/__checks__/organization.spec.ts +++ b/__checks__/organization.spec.ts @@ -1,4 +1,3 @@ -import type { Page } from "@playwright/test"; import { test, expect } from "@playwright/test"; test.describe("Org", () => { @@ -8,14 +7,16 @@ test.describe("Org", () => { const response = await page.goto("https://i.cal.com/embed"); expect(response?.status()).toBe(200); await page.screenshot({ path: "screenshot.jpg" }); - await expectPageToBeRenderedWithEmbedSsr(page); + const body = await response?.text(); + await expectPageToBeRenderedWithEmbedSsr(body); }); test("Org User(Rick) Page should be embeddable", async ({ page }) => { const response = await page.goto("https://i.cal.com/team-rick/embed"); expect(response?.status()).toBe(200); await expect(page.locator("text=Used by Checkly")).toBeVisible(); - await expectPageToBeRenderedWithEmbedSsr(page); + const body = await response?.text(); + await expectPageToBeRenderedWithEmbedSsr(body); }); test("Org User Event(/team-rick/test-event) Page should be embeddable", async ({ page }) => { @@ -23,14 +24,16 @@ test.describe("Org", () => { expect(response?.status()).toBe(200); await expect(page.locator('[data-testid="decrementMonth"]')).toBeVisible(); await expect(page.locator('[data-testid="incrementMonth"]')).toBeVisible(); - await expectPageToBeRenderedWithEmbedSsr(page); + const body = await response?.text(); + await expectPageToBeRenderedWithEmbedSsr(body); }); test("Org Team Profile(/sales) page should be embeddable", async ({ page }) => { const response = await page.goto("https://i.cal.com/sales/embed"); expect(response?.status()).toBe(200); await expect(page.locator("text=Cal.com Sales")).toBeVisible(); - await expectPageToBeRenderedWithEmbedSsr(page); + const body = await response?.text(); + await expectPageToBeRenderedWithEmbedSsr(body); }); test("Org Team Event page(/sales/hippa) should be embeddable", async ({ page }) => { @@ -38,7 +41,8 @@ test.describe("Org", () => { expect(response?.status()).toBe(200); await expect(page.locator('[data-testid="decrementMonth"]')).toBeVisible(); await expect(page.locator('[data-testid="incrementMonth"]')).toBeVisible(); - await expectPageToBeRenderedWithEmbedSsr(page); + const body = await response?.text(); + await expectPageToBeRenderedWithEmbedSsr(body); }); }); @@ -68,7 +72,8 @@ test.describe("Org", () => { test("Organization Homepage - Has Engineering and Marketing Teams", async ({ page }) => { const response = await page.goto("https://i.cal.com"); expect(response?.status()).toBe(200); - await expect(page.locator("text=Cal.com")).toBeVisible(); + // Somehow there are two Cal.com text momentarily, but shouldn't be the concern of this check + await expect(page.locator("text=Cal.com").first()).toBeVisible(); await expect(page.locator("text=Engineering")).toBeVisible(); await expect(page.locator("text=Marketing")).toBeVisible(); }); @@ -95,11 +100,6 @@ test.describe("Org", () => { }); // This ensures that the route is actually mapped to a page that is using withEmbedSsr -async function expectPageToBeRenderedWithEmbedSsr(page: Page) { - expect( - await page.evaluate(() => { - //@ts-expect-error - __NEXT_DATA__ is a global variable defined by Next.js - return window.__NEXT_DATA__.props.pageProps.isEmbed; - }) - ).toBe(true); +async function expectPageToBeRenderedWithEmbedSsr(responseText: string | undefined) { + expect(responseText).toContain('\\"isEmbed\\":true'); }