Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand Down Expand Up @@ -96,7 +96,34 @@ function Owner({
}

describe("AddCodexAccountDialog", () => {
it("hides the header Close button only while saving the account", async () => {
providersAtom.current = Atom.make<ReadonlyArray<ServerProvider> | null>([]);
const save = Promise.withResolvers<Awaited<ReturnType<typeof setup.update>>>();
setup.update.mockImplementationOnce(() => save.promise);
await using _screen = await render(
<AppAtomRegistryProvider>
<Owner onClose={() => {}} onAccountCreated={() => {}} />
</AppAtomRegistryProvider>,
);

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<ReadonlyArray<ServerProvider> | null>([]).pipe(Atom.keepAlive);
providersAtom.current = atom;
const onClose = vi.fn();
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/settings/AddCodexAccountDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ export function AddCodexAccountDialog({
<Dialog
open={!connected}
onOpenChange={(open) => {
if (!open) onClose();
if (!open && !pending) onClose();
}}
onOpenChangeComplete={(open) => {
if (!open && connected) onClose();
}}
>
<WizardPopup size="wide">
<WizardPopup size="wide" showCloseButton={!pending}>
<WizardHeader
title={instanceId ? displayName : gt("Add ChatGPT account")}
description={gt(
Expand Down
80 changes: 80 additions & 0 deletions scripts/scenarios/adding-chatgpt-account-keeps-setup-open.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/// <reference lib="dom" />
import { expect } from "e2e";

import { test, WEB } from "./t3.ts";

declare global {
interface Window {
chatGptAccountSave?: {
readonly started: Promise<void>;
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<void>();
const started = Promise.withResolvers<void>();
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<string, { displayName?: string }> } };
}) =>
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;
});
}
},
);
Loading