fix: Flakyness on pages that use a hard refresh (#16752)

* fix: Flakyness on pages that use a hard refres

Signed-off-by: zomars <[email protected]>

* Update Shell.tsx

---------

Signed-off-by: zomars <[email protected]>
This commit is contained in:
Omar López authored and GitHub committed 2024-09-21 03:41:10 +00:00
1 parent 1a60afad7a
commit 6dd8812a19
9 files changed
+21 -16

No files matched your search

@@ -2,12 +2,11 @@ import { useCallback, useState } from "react";
import { sdkActionManager } from "@calcom/embed-core/embed-iframe";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { useRefreshData } from "@calcom/lib/hooks/useRefreshData";
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry";
import type { RecurringEvent } from "@calcom/types/Calendar";
import { Button, Icon, TextArea } from "@calcom/ui";
import { useRefreshData } from "@lib/hooks/useRefreshData";
type Props = {
booking: {
title?: string;
-12
View File
@@ -1,12 +0,0 @@
import { usePathname, useSearchParams } from "next/navigation";
import { useMemo } from "react";
export function useAsPath() {
const pathname = usePathname();
const searchParams = useSearchParams();
const asPath = useMemo(
() => `${pathname}${searchParams ? `?${searchParams.toString()}` : ""}`,
[pathname, searchParams]
);
return asPath;
}
-13
View File
@@ -1,13 +0,0 @@
import { useRouter } from "next/navigation";
import { useAsPath } from "./useAsPath";
/** @see https://www.joshwcomeau.com/nextjs/refreshing-server-side-props/ */
export function useRefreshData() {
const router = useRouter();
const asPath = useAsPath();
const refreshData = () => {
router.replace(asPath);
};
return refreshData;
}
+9 -1
View File
@@ -1,4 +1,4 @@
import type { Page, WorkerInfo } from "@playwright/test";
import type { Browser, Page, WorkerInfo } from "@playwright/test";
import { expect } from "@playwright/test";
import type Prisma from "@prisma/client";
import type { Team } from "@prisma/client";
@@ -732,6 +732,14 @@ const createUserFixture = (user: UserWithIncludes, page: Page) => {
self,
apiLogin: async (password?: string) =>
apiLogin({ ...(await self()), password: password || user.username }, store.page),
/** Don't forget to close context at the end */
apiLoginOnNewBrowser: async (browser: Browser, password?: string) => {
const newContext = await browser.newContext();
const newPage = await newContext.newPage();
await apiLogin({ ...(await self()), password: password || user.username }, newPage);
// Don't forget to: newContext.close();
return [newContext, newPage] as const;
},
/**
* @deprecated use apiLogin instead
*/
@@ -185,10 +185,7 @@ test.describe("Managed Event Types", () => {
await saveAndWaitForResponse(memberPage);
// We edit the managed event as original owner
const adminContext = await browser.newContext();
const adminPage = await adminContext.newPage();
const adminUserSnapshot = await adminUser.self();
await apiLogin({ ...adminUserSnapshot, password: adminUserSnapshot.username }, adminPage);
const [adminContext, adminPage] = await adminUser.apiLoginOnNewBrowser(browser);
await adminPage.goto("/event-types");
await adminPage.getByTestId("event-types").locator(`a[title="${teamEventTitle}"]`).click();
await adminPage.waitForURL("event-types/**");
@@ -542,9 +542,9 @@ test.describe("Bookings", () => {
const usernameOutsideOrg = userOutsideOrganization.username;
// Before invite is accepted the booking page isn't available
await expectPageToBeNotFound({ page, url: `/${usernameInOrg}` });
await userOutsideOrganization.apiLogin();
await acceptTeamOrOrgInvite(page);
await userOutsideOrganization.logout();
const [newContext, newPage] = await userOutsideOrganization.apiLoginOnNewBrowser(browser);
await acceptTeamOrOrgInvite(newPage);
await newContext.close();
await test.step("Book through new link", async () => {
await doOnOrgDomain(
{
+1 -4
View File
@@ -287,10 +287,7 @@ test.describe("Reschedule Tests", async () => {
const eventType = user.eventTypes.find((e) => e.slug === "opt-in")!;
const confirmBooking = async (bookingId: number) => {
const authedContext = await browser.newContext();
const authedPage = await authedContext.newPage();
const userSnapshot = await user.self();
await apiLogin({ ...userSnapshot, password: userSnapshot.username }, authedPage);
const [authedContext, authedPage] = await user.apiLoginOnNewBrowser(browser);
await authedPage.goto("/bookings/upcoming");
await submitAndWaitForResponse(authedPage, "/api/trpc/bookings/confirm?batch=1", {
action: () => authedPage.locator(`[data-bookingid="${bookingId}"][data-testid="confirm"]`).click(),