|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | + |
| 3 | +import { waitForAnimations } from "../helpers/animations"; |
| 4 | +import { installMockBridge } from "../helpers/bridge"; |
| 5 | + |
| 6 | +/** |
| 7 | + * Regression suite for the "app freezes after setting a reminder" bug. |
| 8 | + * |
| 9 | + * The app used to bundle two copies of @radix-ui/react-dismissable-layer |
| 10 | + * (react-menu resolved 1.1.11 while react-dialog resolved 1.1.15). Each copy |
| 11 | + * keeps its own module-level `originalBodyPointerEvents`, so when a *modal* |
| 12 | + * menu opened a *modal* dialog in the same React commit, the dialog's copy |
| 13 | + * saved the menu's `pointer-events: none` as the "original" body style and |
| 14 | + * restored it when the dialog closed — leaving `pointer-events: none` stuck |
| 15 | + * on <body> and deadening the whole app to the mouse. |
| 16 | + * |
| 17 | + * The inbox row context menu hit this: its "Remind me later" item opens |
| 18 | + * RemindMeLaterDialog synchronously. Fixed by deduplicating the layer via |
| 19 | + * the pnpm override in pnpm-workspace.yaml — a single copy coordinates |
| 20 | + * nested modal layers correctly, so the menu keeps its default modal |
| 21 | + * behavior. |
| 22 | + * |
| 23 | + * Each test drives one reminder entry point through a full set-reminder |
| 24 | + * cycle, then asserts <body> pointer-events is not stuck and that a real |
| 25 | + * click still lands. The inbox right-click test fails if the dismissable |
| 26 | + * layer ever duplicates again; the message-menu tests pin the already-safe |
| 27 | + * paths. |
| 28 | + */ |
| 29 | + |
| 30 | +const GENERAL_MESSAGE_ROW = "message-row"; |
| 31 | +// The default mock feed's mention row (from alice, in #general) has a |
| 32 | +// channel target, so its "Remind me later" context-menu item is enabled. |
| 33 | +const INBOX_MENTION_ROW = "home-inbox-item-mock-feed-mention"; |
| 34 | + |
| 35 | +/** |
| 36 | + * Assert the app survived the menu → dialog → close cycle. |
| 37 | + * |
| 38 | + * The stuck state is inline `pointer-events: none` left on <body>. The buggy |
| 39 | + * restore runs when the dialog's dismissable layer unmounts — after its exit |
| 40 | + * animation — so first wait for the dialog to leave the DOM, then check the |
| 41 | + * body style, then prove clicks still land by navigating via the sidebar. |
| 42 | + */ |
| 43 | +async function expectAppAliveAfterDialogClose( |
| 44 | + page: import("@playwright/test").Page, |
| 45 | +) { |
| 46 | + await expect(page.getByRole("dialog")).toHaveCount(0); |
| 47 | + await waitForAnimations(page); |
| 48 | + expect(await page.evaluate(() => document.body.style.pointerEvents)).not.toBe( |
| 49 | + "none", |
| 50 | + ); |
| 51 | + await page.getByTestId("channel-random").click(); |
| 52 | + await expect(page.getByTestId("chat-title")).toHaveText("random"); |
| 53 | +} |
| 54 | + |
| 55 | +/** Open the Remind-me-later dialog from a message row's More-actions menu. */ |
| 56 | +async function openReminderDialogFromMessageMenu( |
| 57 | + page: import("@playwright/test").Page, |
| 58 | +) { |
| 59 | + await page.goto("/"); |
| 60 | + await page.getByTestId("channel-general").click(); |
| 61 | + await expect(page.getByTestId("chat-title")).toHaveText("general"); |
| 62 | + |
| 63 | + const messageRow = page.getByTestId(GENERAL_MESSAGE_ROW).first(); |
| 64 | + await messageRow.hover(); |
| 65 | + await messageRow.getByRole("button", { name: "More actions" }).click(); |
| 66 | + |
| 67 | + const remindItem = page.getByRole("menuitem", { name: "Remind me later" }); |
| 68 | + await expect(remindItem).toBeVisible(); |
| 69 | + await waitForAnimations(page); |
| 70 | + await remindItem.click(); |
| 71 | + |
| 72 | + const dialog = page.getByRole("dialog"); |
| 73 | + await expect(dialog).toBeVisible(); |
| 74 | + await waitForAnimations(page); |
| 75 | + return dialog; |
| 76 | +} |
| 77 | + |
| 78 | +async function expectReminderSetToast(page: import("@playwright/test").Page) { |
| 79 | + await expect( |
| 80 | + page.locator("[data-sonner-toast]").filter({ hasText: "Reminder set" }), |
| 81 | + ).toBeVisible(); |
| 82 | +} |
| 83 | + |
| 84 | +test.describe("reminder set → app stays clickable", () => { |
| 85 | + test.beforeEach(async ({ page }) => { |
| 86 | + await installMockBridge(page); |
| 87 | + }); |
| 88 | + |
| 89 | + test("01 — message menu → time preset", async ({ page }) => { |
| 90 | + const dialog = await openReminderDialogFromMessageMenu(page); |
| 91 | + |
| 92 | + await dialog.getByRole("button", { name: "In 30 minutes" }).click(); |
| 93 | + |
| 94 | + await expectReminderSetToast(page); |
| 95 | + await expectAppAliveAfterDialogClose(page); |
| 96 | + }); |
| 97 | + |
| 98 | + test("02 — message menu → custom time via Set reminder footer button", async ({ |
| 99 | + page, |
| 100 | + }) => { |
| 101 | + const dialog = await openReminderDialogFromMessageMenu(page); |
| 102 | + |
| 103 | + // The custom timestamp must be strictly in the future or the Set |
| 104 | + // reminder button stays disabled — pick tomorrow at 09:00 local time. |
| 105 | + const tomorrow = new Date(Date.now() + 24 * 60 * 60 * 1000); |
| 106 | + const date = [ |
| 107 | + tomorrow.getFullYear(), |
| 108 | + String(tomorrow.getMonth() + 1).padStart(2, "0"), |
| 109 | + String(tomorrow.getDate()).padStart(2, "0"), |
| 110 | + ].join("-"); |
| 111 | + await dialog.getByLabel("Reminder date").fill(date); |
| 112 | + await dialog.getByLabel("Reminder time").fill("09:00"); |
| 113 | + await dialog.getByRole("button", { name: "Set reminder" }).click(); |
| 114 | + |
| 115 | + await expectReminderSetToast(page); |
| 116 | + await expectAppAliveAfterDialogClose(page); |
| 117 | + }); |
| 118 | + |
| 119 | + // The regression path: only the inbox right-click stacks a modal |
| 120 | + // ContextMenu under the modal dialog. Fails if two copies of the |
| 121 | + // dismissable layer are ever bundled again — body pointer-events stays |
| 122 | + // "none" after the dialog closes and the sidebar click below times out. |
| 123 | + test("03 — inbox row right-click → Remind me later", async ({ page }) => { |
| 124 | + await page.goto("/"); |
| 125 | + await expect(page.getByTestId("home-inbox")).toBeVisible(); |
| 126 | + |
| 127 | + const row = page.getByTestId(INBOX_MENTION_ROW); |
| 128 | + await expect(row).toBeVisible(); |
| 129 | + await row.click({ button: "right" }); |
| 130 | + |
| 131 | + const remindItem = page.getByRole("menuitem", { name: "Remind me later" }); |
| 132 | + await expect(remindItem).toBeVisible(); |
| 133 | + await waitForAnimations(page); |
| 134 | + await remindItem.click(); |
| 135 | + |
| 136 | + const dialog = page.getByRole("dialog"); |
| 137 | + await expect(dialog).toBeVisible(); |
| 138 | + await waitForAnimations(page); |
| 139 | + await dialog.getByRole("button", { name: "In 30 minutes" }).click(); |
| 140 | + |
| 141 | + await expectReminderSetToast(page); |
| 142 | + await expectAppAliveAfterDialogClose(page); |
| 143 | + }); |
| 144 | +}); |
0 commit comments