diff --git a/apps/web/src/components/settings/AddCodexAccountDialog.browser.test.tsx b/apps/web/src/components/settings/AddCodexAccountDialog.browser.test.tsx index c7c223c656e37..8d574f3da7b36 100644 --- a/apps/web/src/components/settings/AddCodexAccountDialog.browser.test.tsx +++ b/apps/web/src/components/settings/AddCodexAccountDialog.browser.test.tsx @@ -13,7 +13,7 @@ import { act, render } from "../../../test/render"; import { AppAtomRegistryProvider, appAtomRegistry as registry } from "../../rpc/atomRegistry"; const setup = vi.hoisted(() => ({ - update: vi.fn(async () => ({ _tag: "Success" as const })), + update: vi.fn(async (): Promise<{ _tag: "Success" | "Failure" }> => ({ _tag: "Success" })), })); const providersAtom = vi.hoisted(() => ({ current: null as unknown })); @@ -96,7 +96,34 @@ function Owner({ } describe("AddCodexAccountDialog", () => { + it("hides the header Close button only while saving the account", async () => { + providersAtom.current = Atom.make | null>([]); + const save = Promise.withResolvers>>(); + setup.update.mockImplementationOnce(() => save.promise); + await using _screen = await render( + + {}} onAccountCreated={() => {}} /> + , + ); + + const close = page.getByRole("button", { name: "Close", exact: true }); + try { + await userEvent.click(page.getByRole("button", { name: "Continue" })); + await expect.element(page.getByRole("button", { name: "Adding account…" })).toBeDisabled(); + expect(close.query()).toBeNull(); + await userEvent.keyboard("{Escape}"); + await expect.element(page.getByRole("dialog")).toBeVisible(); + } finally { + await act(() => save.resolve({ _tag: "Failure" })); + } + + await expect.element(close).toBeVisible(); + await userEvent.keyboard("{Escape}"); + await expect.element(page.getByRole("dialog")).not.toBeInTheDocument(); + }); + it("plays its close animation before the owner unmounts it once the account connects", async () => { + setup.update.mockClear(); const atom = Atom.make | null>([]).pipe(Atom.keepAlive); providersAtom.current = atom; const onClose = vi.fn(); diff --git a/apps/web/src/components/settings/AddCodexAccountDialog.tsx b/apps/web/src/components/settings/AddCodexAccountDialog.tsx index 5eb3c749540c4..0dd255b902fad 100644 --- a/apps/web/src/components/settings/AddCodexAccountDialog.tsx +++ b/apps/web/src/components/settings/AddCodexAccountDialog.tsx @@ -86,13 +86,13 @@ export function AddCodexAccountDialog({ { - if (!open) onClose(); + if (!open && !pending) onClose(); }} onOpenChangeComplete={(open) => { if (!open && connected) onClose(); }} > - + +import { expect } from "e2e"; + +import { test, WEB } from "./t3.ts"; + +declare global { + interface Window { + chatGptAccountSave?: { + readonly started: Promise; + readonly release: () => void; + }; + } +} + +test( + "Escape leaves ChatGPT account setup open while the account is being added", + WEB, + async ({ t3, app, browser, screen }) => { + await t3.project("demo"); + await browser.addInitScript(() => { + const gate = Promise.withResolvers(); + const started = Promise.withResolvers(); + window.chatGptAccountSave = { started: started.promise, release: gate.resolve }; + const send = WebSocket.prototype.send; + WebSocket.prototype.send = function (data) { + if (typeof data !== "string") return send.call(this, data); + const parsed = JSON.parse(data); + const messages = [parsed].flat(); + const accountSave = (message: { + _tag?: string; + tag?: string; + payload?: { patch?: { providerInstances?: Record } }; + }) => + message?._tag === "Request" && + message.tag === "server.updateSettings" && + Object.values(message.payload?.patch?.providerInstances ?? {}).some( + (instance) => instance.displayName === "ChatGPT - Slow account", + ); + const saves = messages.filter(accountSave); + if (saves.length === 0) return send.call(this, data); + const other = messages.filter((message) => !saves.includes(message)); + if (other.length > 0) send.call(this, JSON.stringify(other)); + started.resolve(); + void gate.promise.then(() => + send.call(this, Array.isArray(parsed) ? JSON.stringify(saves) : data), + ); + }; + }); + await t3.open("/settings/providers?instanceId=codex"); + await screen.getByRole("button", "Add provider", { exact: true }).first().tap(); + const addProvider = screen.getByRole("dialog", "Add provider", { exact: true }); + await addProvider.getByRole("radio", "Codex", { exact: true }).tap(); + await addProvider.getByRole("button", "Continue with ChatGPT", { exact: true }).tap(); + + const setup = screen.getByRole("dialog", "Add ChatGPT account", { exact: true }); + await setup.getByRole("textbox", "Account name", { exact: true }).fill("Slow account"); + try { + await setup.getByRole("button", "Continue", { exact: true }).tap(); + const adding = browser + .locator('[data-slot="dialog-popup"][data-open]') + .getByRole("button", "Adding account…", { exact: true }); + await adding.waitFor(); + await browser.evaluate(async () => { + await window.chatGptAccountSave!.started; + return null; + }); + await browser.keyboard.press("Escape"); + await app.screenshot("escape-during-account-creation"); + expect( + await adding.isVisible(), + "ChatGPT account setup stays open while adding the account", + ).toBe(true); + } finally { + await browser.evaluate(() => { + window.chatGptAccountSave?.release(); + return null; + }); + } + }, +);