Files
upstream-yaak/apps/yaak-client/lib/confirmWebProxy.test.tsx
upstream-mirror 906fb231cc
Some checks failed
Lint and Test / Lint/Test (push) Has been cancelled
Generate Sponsors README / deploy (push) Has been skipped
snapshot of https://github.com/mountain-loop/yaak.git (main, 2026-09-23; blobs > 131072B omitted)
2026-09-23 17:39:41 +05:00

65 lines
2.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { renderToStaticMarkup } from "react-dom/server";
import { afterEach, beforeEach, describe, expect, test, vi } from "vite-plus/test";
import type { DialogInstance } from "../components/Dialogs";
const mocks = vi.hoisted(() => ({
platform: { httpProxyUrl: "https://web.yaak.app" },
showDialog: vi.fn<(dialog: DialogInstance) => void>(),
}));
vi.mock("@yaakapp-internal/platform", () => ({ platform: mocks.platform }));
vi.mock("./appInfo", () => ({ appInfo: { identifier: "app.yaak.web" } }));
vi.mock("./dialog", () => ({ showDialog: mocks.showDialog }));
vi.mock("../hooks/useHotKey", () => ({
useHotKey: vi.fn(),
useFormattedHotkey: () => null,
}));
describe("proxy consent disclosure", () => {
beforeEach(() => {
vi.resetModules();
vi.clearAllMocks();
vi.stubGlobal("localStorage", { getItem: () => null });
});
afterEach(() => vi.unstubAllGlobals());
test.each([
["Yaak-hosted", "https://web.yaak.app"],
["self-hosted", "https://yaak.example.com"],
["local", "http://localhost:8080"],
["split deployment", "https://send.example.com/relay"],
])("identifies the %s proxy and requires an explicit decision", async (_, proxyUrl) => {
mocks.platform.httpProxyUrl = proxyUrl;
const { confirmWebProxy } = await import("./confirmWebProxy");
void confirmWebProxy();
const dialog = mocks.showDialog.mock.calls[0]?.[0];
expect(dialog).toMatchObject({
id: "web-proxy-consent",
title: "Requests in Yaak Web use a proxy",
size: "sm",
disableClose: true,
});
if (dialog == null) throw new Error("Expected the proxy consent dialog");
const disclosure = renderToStaticMarkup(<>{dialog.description}</>);
expect(disclosure).toContain(`>${proxyUrl}</code>`);
expect(disclosure).toMatch(/request and response data/i);
expect(disclosure).toContain("credentials");
expect(disclosure).toContain("server shown below");
expect(disclosure).not.toContain("Yaak’s servers");
expect(disclosure).toContain(
'href="https://yaak.app/docs/getting-started/web-proxy?ref=app.yaak.web"',
);
expect(disclosure).toContain('target="_blank"');
expect(disclosure).toContain("how the proxy works");
const Actions = dialog.render;
const actions = renderToStaticMarkup(<Actions hide={vi.fn()} />);
expect(actions).toMatch(/<button[^>]*type="submit"/);
expect(actions).toContain(">Send via Proxy<");
expect(actions).toContain(">Cancel<");
});
});