Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

SshPasswordPromptDialog.browser.test.tsx

32 lines1.3 KB

1import type { DesktopSshPasswordPromptRequest } from "@t3tools/contracts";
2import { expect, it } from "vite-plus/test";
3​
4import { render, stubGlobal } from "../../../test/render";
5import { SshPasswordPromptDialog, startSshPasswordPromptQueue } from "./SshPasswordPromptDialog";
6​
7it("shows a prompt that arrived before the dialog mounted", async () => {
8 const listeners: Array<(request: DesktopSshPasswordPromptRequest) => void> = [];
9 using _bridge = stubGlobal("desktopBridge", {
10 onSshPasswordPrompt: (listener: (request: DesktopSshPasswordPromptRequest) => void) => {
11 listeners.push(listener);
12 return () => listeners.splice(listeners.indexOf(listener), 1);
13 },
14 resolveSshPasswordPrompt: async () => undefined,
15 });
16 const stopQueue = startSshPasswordPromptQueue();
17 using _queue = { [Symbol.dispose]: stopQueue };
18​
19 // The desktop asks while the app is still on a page without the dialog (pairing, sign-in).
20 for (const listener of listeners) {
21 listener({
22 requestId: "ssh-1",
23 destination: "devbox",
24 username: "julius",
25 prompt: "julius@devbox's password:",
26 expiresAt: "2999-01-01T00:00:00.000Z",
27 });
28 }
29​
30 await using screen = await render(<SshPasswordPromptDialog />);
31 await expect.element(screen.getByText("SSH verification required")).toBeVisible();
32});