Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✅ Add cross-timezone Playwright tests for invite and event pages (#2542)
Luke Vella7c221677273d
diff --git a/apps/web/.env.test b/apps/web/.env.testindex ec040f418..f104dd61d 100644--- a/apps/web/.env.test+++ b/apps/web/.env.test@@ -6,6 +6,7 @@ NODE_ENV=testPORT=3002QUICK_CREATE_ENABLED=trueRATE_LIMIT_ENABLED=false+SCHEDULED_EVENTS_ENABLED=trueSECRET_PASSWORD=abcdef1234567890abcdef1234567890SMTP_HOST=0.0.0.0SMTP_PORT=1025diff --git a/apps/web/src/app/[locale]/e/[id]/components/event-detail.tsx b/apps/web/src/app/[locale]/e/[id]/components/event-detail.tsxindex 342e0e2f7..9f270c585 100644--- a/apps/web/src/app/[locale]/e/[id]/components/event-detail.tsx+++ b/apps/web/src/app/[locale]/e/[id]/components/event-detail.tsx@@ -60,12 +60,13 @@ export function EventDetailContent({export function EventDetailTitle({children,className,-}: {- children: React.ReactNode;- className?: string;-}) {+ ...props+}: React.ComponentProps<"div">) {return (- <div className={cn("font-medium text-base text-foreground", className)}>+ <div+ className={cn("font-medium text-base text-foreground", className)}+ {...props}+ >{children}</div>);@@ -74,12 +75,10 @@ export function EventDetailTitle({export function EventDetailDescription({children,className,-}: {- children: React.ReactNode;- className?: string;-}) {+ ...props+}: React.ComponentProps<"div">) {return (- <div className={cn("text-muted-foreground text-sm", className)}>+ <div className={cn("text-muted-foreground text-sm", className)} {...props}>{children}</div>);diff --git a/apps/web/src/app/[locale]/e/[id]/page.tsx b/apps/web/src/app/[locale]/e/[id]/page.tsxindex 881c02c94..27963f2e1 100644--- a/apps/web/src/app/[locale]/e/[id]/page.tsx+++ b/apps/web/src/app/[locale]/e/[id]/page.tsx@@ -167,23 +167,23 @@ export default async function EventPage({<EventCalendarCardstart={event.start}allDay={event.allDay}- timeZone={event.displayTimeZone}+ timeZone={event.timeZone}/><EventDetailContent>- <EventDetailTitle>+ <EventDetailTitle data-testid="event-start-date"><EventDatevalue={event.start}preset="weekdayMonthDay"allDay={event.allDay}- timeZone={event.displayTimeZone}+ timeZone={event.timeZone}/></EventDetailTitle>- <EventDetailDescription>+ <EventDetailDescription data-testid="event-time-range"><EventTimeRangestart={event.start}end={event.end}allDay={event.allDay}- timeZone={event.displayTimeZone}+ timeZone={event.timeZone}showTimeZone={true}/></EventDetailDescription>diff --git a/apps/web/src/components/poll/desktop-poll/poll-header.tsx b/apps/web/src/components/poll/desktop-poll/poll-header.tsxindex 2a37a3d1d..adbef18c6 100644--- a/apps/web/src/components/poll/desktop-poll/poll-header.tsx+++ b/apps/web/src/components/poll/desktop-poll/poll-header.tsx@@ -24,7 +24,7 @@ const TimeRange: React.FunctionComponent<{className,)}>- <span>{start}</span>+ <span data-testid="option-start-time">{start}</span><Tooltip delayDuration={0}><TooltipTrigger className="flex items-center gap-x-1 opacity-50"><ClockIcon className="size-3" />@@ -119,7 +119,7 @@ const PollHeader = () => {)}><div className="sticky right-0 left-[236px] inline-flex h-5 gap-1 px-2 py-0.5 font-medium text-xs uppercase">- <span>{group.month}</span>+ <span data-testid="option-month">{group.month}</span><span className="text-muted-foreground">{group.year}</span></div></th>@@ -141,7 +141,9 @@ const PollHeader = () => {<div className="font-normal text-muted-foreground text-xs">{group.dow}</div>- <div className="font-medium text-sm">{group.day}</div>+ <div data-testid="option-day" className="font-medium text-sm">+ {group.day}+ </div></div></th>))}diff --git a/apps/web/src/features/scheduled-event/constants.ts b/apps/web/src/features/scheduled-event/constants.tsindex 5b1c08736..d44e41ea3 100644--- a/apps/web/src/features/scheduled-event/constants.ts+++ b/apps/web/src/features/scheduled-event/constants.ts@@ -1,3 +1,5 @@-export const isScheduledEventEnabled = process.env.NODE_ENV === "development";+export const isScheduledEventEnabled =+ process.env.NODE_ENV === "development" ||+ process.env.SCHEDULED_EVENTS_ENABLED === "true";export const scheduledEventTag = (id: string) => `scheduled-event:${id}`;diff --git a/apps/web/src/features/scheduled-event/data.ts b/apps/web/src/features/scheduled-event/data.tsindex 35628cbf7..e95ec0cb2 100644--- a/apps/web/src/features/scheduled-event/data.ts+++ b/apps/web/src/features/scheduled-event/data.ts@@ -93,35 +93,6 @@ export function getEventRegistration({});}-// Legacy fallback used when neither location nor conferencing is populated.-// Inverts the stored timeZone: stored null = "everyone sees UTC"; stored set = "viewer's TZ".-function legacyDisplayTimeZone(timeZone: string | null): string | null {- return timeZone === null ? "UTC" : null;-}--// Derives the timezone the public page should render the event in, per the population table:-// in-person (location set, conferencing null) -> timeZone (venue TZ)-// remote (location null, conferencing set) -> null (viewer's TZ)-// hybrid (both set) -> timeZone (venue TZ; viewer toggle in UI)-// unspecified (neither set) -> legacy rule-export function deriveDisplayTimeZone({- timeZone,- hasLocation,- hasConferencing,-}: {- timeZone: string | null;- hasLocation: boolean;- hasConferencing: boolean;-}): string | null {- if (hasLocation) {- return timeZone;- }- if (hasConferencing) {- return null;- }- return legacyDisplayTimeZone(timeZone);-}-export type ScheduledEventDTO = {id: string;title: string;@@ -132,7 +103,6 @@ export type ScheduledEventDTO = {end: Date;allDay: boolean;timeZone: string | null;- displayTimeZone: string | null;status: ScheduledEventStatus;};@@ -165,11 +135,6 @@ export function createScheduledEventDTO(event: {allDay: event.allDay,timeZone: event.timeZone,status: event.status,- displayTimeZone: deriveDisplayTimeZone({- timeZone: event.timeZone,- hasLocation: location !== null,- hasConferencing: conferencing !== null,- }),};}diff --git a/apps/web/tests/cross-timezone.spec.ts b/apps/web/tests/cross-timezone.spec.tsnew file mode 100644index 000000000..2906084c9--- /dev/null+++ b/apps/web/tests/cross-timezone.spec.ts@@ -0,0 +1,345 @@+import type { BrowserContext, Page } from "@playwright/test";+import { expect, test } from "@playwright/test";+import { prisma } from "@rallly/database";++/**+ * Cross-timezone rendering guarantees for the poll invite page and the+ * public event page:+ *+ * - Polls/events with a time zone are fixed instants: displayed times must+ * shift between viewers in different zones.+ * - Floating (no zone) and all-day polls/events are wall times: displayed+ * dates and times must be identical for every viewer.+ *+ * Both zones are deliberately non-whole-hour offsets (UTC+5:45 and UTC-2:30+ * in September) and neither matches a CI runner's zone, so a value that+ * leaks through the wrong zone can't accidentally format to the same string.+ */+const ZONE_A = "Asia/Kathmandu";+const ZONE_B = "America/St_Johns";++const HOST_EMAIL = "[email protected]";++const ZONED_POLL_ID = "cross-tz-zoned-poll";+const FLOATING_POLL_ID = "cross-tz-floating-poll";+const DATE_POLL_ID = "cross-tz-date-poll";+const FIXED_EVENT_ID = "cross-tz-fixed-event";+const ALL_DAY_EVENT_ID = "cross-tz-all-day-event";++// Always next year so the fixtures stay in the future. September avoids DST+// transitions in both zones (Kathmandu has none; St. John's is on NDT).+const YEAR = new Date().getFullYear() + 1;++// 16:00Z: 21:45 in Kathmandu, 13:30 in St. John's (same day in both, so only+// the time of day shifts).+const ZONED_POLL_START = new Date(`${YEAR}-09-10T16:00:00.000Z`);+// Stored wall time 00:30. A viewer west of UTC would see the previous day if+// this were wrongly treated as an instant.+const FLOATING_POLL_START = new Date(`${YEAR}-09-10T00:30:00.000Z`);+const DATE_POLL_START = new Date(`${YEAR}-09-10T00:00:00.000Z`);+// 20:00Z: already September 11 in Kathmandu, still September 10 in+// St. John's, so both the date and the time must shift.+const FIXED_EVENT_START = new Date(`${YEAR}-09-10T20:00:00.000Z`);+const FIXED_EVENT_END = new Date(`${YEAR}-09-10T21:00:00.000Z`);+const ALL_DAY_EVENT_START = new Date(`${YEAR}-09-10T00:00:00.000Z`);+const ALL_DAY_EVENT_END = new Date(`${YEAR}-09-11T00:00:00.000Z`);++function watchForHydrationErrors(page: Page) {+ const errors: string[] = [];+ const isHydrationError = (text: string) =>+ /hydrat/i.test(text) || /minified react error #(418|423|425)/i.test(text);++ page.on("console", (message) => {+ if (message.type() === "error" && isHydrationError(message.text())) {+ errors.push(message.text());+ }+ });+ page.on("pageerror", (error) => {+ if (isHydrationError(error.message)) {+ errors.push(error.message);+ }+ });+ return errors;+}++async function readWhenHydrated(page: Page, testId: string) {+ const locator = page.getByTestId(testId).first();+ // Datetime components render blank until hydration, when the viewer's+ // zone is known.+ await expect(locator).not.toHaveText(/^[\s ]*$/);+ const text = await locator.textContent();+ return text?.trim() ?? "";+}++/**+ * Formats an instant with the page's own Intl engine (matching the app's+ * "time" preset) in the context's zone, or a fixed zone when given.+ */+function formatTimeInPage(page: Page, iso: string, timeZone?: string) {+ return page.evaluate(+ ([value, zone]) =>+ new Intl.DateTimeFormat("en", {+ hour: "numeric",+ minute: "2-digit",+ timeZone: zone,+ }).format(new Date(value)),+ [iso, timeZone] as const,+ );+}++async function seed() {+ await cleanup();++ const user = await prisma.user.create({+ data: {+ email: HOST_EMAIL,+ name: "Cross TZ Host",+ locale: "en",+ timeZone: "Europe/London",+ emailVerified: true,+ },+ });++ const space = await prisma.space.create({+ data: {+ name: "Cross TZ Space",+ ownerId: user.id,+ tier: "hobby",+ },+ });++ await prisma.poll.create({+ data: {+ id: ZONED_POLL_ID,+ title: "Cross TZ Zoned Poll",+ participantUrlId: `${ZONED_POLL_ID}-participant`,+ adminUrlId: `${ZONED_POLL_ID}-admin`,+ kind: "time",+ timeZone: "Europe/London",+ options: {+ create: { startTime: ZONED_POLL_START, duration: 60 },+ },+ },+ });++ await prisma.poll.create({+ data: {+ id: FLOATING_POLL_ID,+ title: "Cross TZ Floating Poll",+ participantUrlId: `${FLOATING_POLL_ID}-participant`,+ adminUrlId: `${FLOATING_POLL_ID}-admin`,+ kind: "time",+ timeZone: null,+ options: {+ create: { startTime: FLOATING_POLL_START, duration: 60 },+ },+ },+ });++ await prisma.poll.create({+ data: {+ id: DATE_POLL_ID,+ title: "Cross TZ Date Poll",+ participantUrlId: `${DATE_POLL_ID}-participant`,+ adminUrlId: `${DATE_POLL_ID}-admin`,+ kind: "date",+ timeZone: null,+ options: {+ create: { startTime: DATE_POLL_START, duration: 0 },+ },+ },+ });++ await prisma.scheduledEvent.create({+ data: {+ id: FIXED_EVENT_ID,+ uid: `${FIXED_EVENT_ID}-uid`,+ userId: user.id,+ spaceId: space.id,+ title: "Cross TZ Fixed Event",+ timeZone: "Europe/London",+ start: FIXED_EVENT_START,+ end: FIXED_EVENT_END,+ allDay: false,+ },+ });++ await prisma.scheduledEvent.create({+ data: {+ id: ALL_DAY_EVENT_ID,+ uid: `${ALL_DAY_EVENT_ID}-uid`,+ userId: user.id,+ spaceId: space.id,+ title: "Cross TZ All Day Event",+ timeZone: null,+ start: ALL_DAY_EVENT_START,+ end: ALL_DAY_EVENT_END,+ allDay: true,+ },+ });+}++async function cleanup() {+ await prisma.poll.deleteMany({+ where: { id: { in: [ZONED_POLL_ID, FLOATING_POLL_ID, DATE_POLL_ID] } },+ });+ await prisma.scheduledEvent.deleteMany({+ where: { id: { in: [FIXED_EVENT_ID, ALL_DAY_EVENT_ID] } },+ });+ await prisma.user.deleteMany({ where: { email: HOST_EMAIL } });+}++test.describe("cross-timezone rendering", () => {+ let contextA: BrowserContext;+ let contextB: BrowserContext;++ test.beforeAll(async ({ browser }) => {+ await seed();+ contextA = await browser.newContext({+ timezoneId: ZONE_A,+ locale: "en-US",+ });+ contextB = await browser.newContext({+ timezoneId: ZONE_B,+ locale: "en-US",+ });+ });++ test.afterAll(async () => {+ await contextA?.close();+ await contextB?.close();+ await cleanup();+ });++ async function openInBothZones(path: string) {+ const pageA = await contextA.newPage();+ const pageB = await contextB.newPage();+ const errorsA = watchForHydrationErrors(pageA);+ const errorsB = watchForHydrationErrors(pageB);+ await Promise.all([pageA.goto(path), pageB.goto(path)]);+ return {+ pageA,+ pageB,+ expectNoHydrationErrors: () => {+ expect(errorsA).toEqual([]);+ expect(errorsB).toEqual([]);+ },+ close: async () => {+ await pageA.close();+ await pageB.close();+ },+ };+ }++ test("poll with a time zone shifts slot times between viewers", async () => {+ const { pageA, pageB, expectNoHydrationErrors, close } =+ await openInBothZones(`/invite/${ZONED_POLL_ID}`);++ const startIso = ZONED_POLL_START.toISOString();+ const [timeA, timeB] = await Promise.all([+ readWhenHydrated(pageA, "option-start-time"),+ readWhenHydrated(pageB, "option-start-time"),+ ]);++ expect(timeA).toBe(await formatTimeInPage(pageA, startIso)); // 9:45 PM+ expect(timeB).toBe(await formatTimeInPage(pageB, startIso)); // 1:30 PM+ expect(timeA).not.toBe(timeB);++ expectNoHydrationErrors();+ await close();+ });++ test("floating time poll shows identical times to every viewer", async () => {+ const { pageA, pageB, expectNoHydrationErrors, close } =+ await openInBothZones(`/invite/${FLOATING_POLL_ID}`);++ const [timeA, timeB, dayA, dayB] = await Promise.all([+ readWhenHydrated(pageA, "option-start-time"),+ readWhenHydrated(pageB, "option-start-time"),+ readWhenHydrated(pageA, "option-day"),+ readWhenHydrated(pageB, "option-day"),+ ]);++ // Floating wall times are stored as UTC and must render unshifted.+ const expected = await formatTimeInPage(+ pageA,+ FLOATING_POLL_START.toISOString(),+ "UTC",+ ); // 12:30 AM+ expect(timeA).toBe(expected);+ expect(timeB).toBe(expected);+ // A viewer west of UTC must not see the previous day.+ expect(dayA).toBe("10");+ expect(dayB).toBe("10");++ expectNoHydrationErrors();+ await close();+ });++ test("all-day date poll shows the same date to every viewer", async () => {+ const { pageA, pageB, expectNoHydrationErrors, close } =+ await openInBothZones(`/invite/${DATE_POLL_ID}`);++ const [dayA, dayB, monthA, monthB] = await Promise.all([+ readWhenHydrated(pageA, "option-day"),+ readWhenHydrated(pageB, "option-day"),+ readWhenHydrated(pageA, "option-month"),+ readWhenHydrated(pageB, "option-month"),+ ]);++ expect(dayA).toBe("10");+ expect(dayB).toBe("10");+ expect(monthA).toBe("Sep");+ expect(monthB).toBe("Sep");++ expectNoHydrationErrors();+ await close();+ });++ test("event with a time zone shifts date and time between viewers", async () => {+ const { pageA, pageB, expectNoHydrationErrors, close } =+ await openInBothZones(`/e/${FIXED_EVENT_ID}`);++ const startIso = FIXED_EVENT_START.toISOString();+ const [dateA, dateB, rangeA, rangeB] = await Promise.all([+ readWhenHydrated(pageA, "event-start-date"),+ readWhenHydrated(pageB, "event-start-date"),+ readWhenHydrated(pageA, "event-time-range"),+ readWhenHydrated(pageB, "event-time-range"),+ ]);++ // 20:00 UTC is already the 11th in Kathmandu and still the 10th in+ // St. John's.+ expect(dateA).toContain("September 11");+ expect(dateB).toContain("September 10");++ const expectedStartA = await formatTimeInPage(pageA, startIso); // 1:45 AM+ const expectedStartB = await formatTimeInPage(pageB, startIso); // 5:30 PM+ expect(rangeA).toContain(expectedStartA.split(/\s/)[0]);+ expect(rangeB).toContain(expectedStartB.split(/\s/)[0]);+ expect(rangeA).not.toBe(rangeB);++ expectNoHydrationErrors();+ await close();+ });++ test("all-day event shows the same date to every viewer", async () => {+ const { pageA, pageB, expectNoHydrationErrors, close } =+ await openInBothZones(`/e/${ALL_DAY_EVENT_ID}`);++ const [dateA, dateB, rangeA, rangeB] = await Promise.all([+ readWhenHydrated(pageA, "event-start-date"),+ readWhenHydrated(pageB, "event-start-date"),+ readWhenHydrated(pageA, "event-time-range"),+ readWhenHydrated(pageB, "event-time-range"),+ ]);++ expect(dateA).toContain("September 10");+ expect(dateB).toBe(dateA);+ expect(rangeA).toBe("All day");+ expect(rangeB).toBe("All day");++ expectNoHydrationErrors();+ await close();+ });+});