mirror of
https://github.com/hanzoai/dev-desktop.git
synced 2026-11-23 05:52:02 +00:00
The web, server, and mobile clients already signed in through Hanzo IAM behind a Clerk-shaped adapter. Remove the Clerk configuration, appearance, load-failure screens and the dead Clerk branch of the CLI OAuth config; components/clerk is components/account. Co-authored-by: Hanzo Dev <[email protected]>
71 lines
2.7 KiB
TypeScript
71 lines
2.7 KiB
TypeScript
import { describe, expect, it, vi } from "vite-plus/test";
|
|
import { page, userEvent } from "vite-plus/test/browser";
|
|
|
|
import { render } from "../../test/render";
|
|
import { useCommitOnBlur } from "../hooks/useCommitOnBlur";
|
|
import { AppRouteModal } from "./AppRouteModal";
|
|
|
|
vi.mock("./chat/GlobalVoiceInputIndicator", () => ({ GlobalVoiceInputIndicator: () => null }));
|
|
|
|
function CommitOnBlurField({ onCommit }: { onCommit: (next: string) => void }) {
|
|
return <input aria-label="Instructions" {...useCommitOnBlur("", onCommit)} />;
|
|
}
|
|
|
|
describe("AppRouteModal", () => {
|
|
it("commits a focused field when Esc closes it", async () => {
|
|
const onCommit = vi.fn();
|
|
await using _screen = await render(
|
|
<AppRouteModal label="Settings">
|
|
<CommitOnBlurField onCommit={onCommit} />
|
|
</AppRouteModal>,
|
|
{ router: "/settings/general" },
|
|
);
|
|
|
|
await page.getByRole("textbox", { name: "Instructions" }).fill("Keep titles short");
|
|
await userEvent.keyboard("{Escape}");
|
|
|
|
expect(onCommit).toHaveBeenCalledWith("Keep titles short");
|
|
});
|
|
|
|
it("returns focus to the opener when Esc closes it", async () => {
|
|
const opener = <button type="button">Open usage</button>;
|
|
await using screen = await render(opener, { router: "/" });
|
|
const openerButton = screen.getByRole("button", { name: "Open usage" });
|
|
(openerButton.element() as HTMLElement).focus();
|
|
|
|
await screen.rerender(
|
|
<>
|
|
{opener}
|
|
<AppRouteModal label="Usage">
|
|
<p>Usage</p>
|
|
</AppRouteModal>
|
|
</>,
|
|
);
|
|
await expect.element(page.getByRole("dialog", { name: "Usage" })).toHaveFocus();
|
|
await userEvent.keyboard("{Escape}");
|
|
|
|
await expect.element(page.getByRole("dialog", { name: "Usage" })).not.toBeInTheDocument();
|
|
await expect.element(openerButton).toHaveFocus();
|
|
});
|
|
|
|
it("stays open when Esc belongs to a modal outside Base UI", async () => {
|
|
await using _screen = await render(
|
|
<AppRouteModal label="Settings">
|
|
<CommitOnBlurField onCommit={() => undefined} />
|
|
</AppRouteModal>,
|
|
{ router: "/settings/general" },
|
|
);
|
|
const settings = page.getByRole("dialog", { name: "Settings" });
|
|
// Base UI takes initial focus a frame after opening; let it land before the account modal takes focus.
|
|
await expect.element(settings).toHaveFocus();
|
|
// The account modal renders in its own root and dismisses on a document Esc listener.
|
|
const foreignModal = document.body.appendChild(document.createElement("input"));
|
|
using _foreignModal = { [Symbol.dispose]: () => foreignModal.remove() };
|
|
|
|
foreignModal.focus();
|
|
await userEvent.keyboard("{Escape}");
|
|
|
|
await expect.element(settings).toHaveAttribute("data-open");
|
|
});
|
|
});
|