mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-11-13 12:13:42 +01:00
The actions row moves out of the code editor into ActionsBar, a plain component a wrapper places over its content. FormatAction reformats an editor through its ref, and BodyViewModeSwitch names its first state for the body's format (Pretty, Table, Parts, Preview, Form) next to Raw. Yaak Proxy's request and response body tabs now share one viewer choice, with the switch in each tab's bar beside the text viewer's filter. The choice is remembered for both panes; bodies over the large size open raw. "Response (Raw)" leaves the proxy's tab menu, while Yaak's response pane keeps it until the remaining sites move. SegmentedControl moves from the client into packages/ui. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
81 lines
3.3 KiB
TypeScript
81 lines
3.3 KiB
TypeScript
import { describe, expect, test, vi } from "vite-plus/test";
|
|
import { flowPrettyView, shownViewMode } from "./FlowBodyViewer";
|
|
|
|
// The package's index reaches for the window as it loads; the view rule is all this needs.
|
|
vi.mock("@yaakapp-internal/ui", async () => {
|
|
const { prettyViewFor } = await vi.importActual<
|
|
typeof import("../../../packages/ui/src/components/http/BodyViewModeSwitch")
|
|
>("../../../packages/ui/src/components/http/BodyViewModeSwitch");
|
|
return { prettyViewFor, LARGE_BODY_BYTES: 2_000_000 };
|
|
});
|
|
|
|
const text = (mime: string, language: string | null, which: "request" | "response" = "response") =>
|
|
flowPrettyView({
|
|
which,
|
|
mime,
|
|
text: "x",
|
|
binary: false,
|
|
language: language as never,
|
|
hasForm: false,
|
|
});
|
|
|
|
describe("flowPrettyView", () => {
|
|
test("names the formatted view per format, the same on both halves", () => {
|
|
for (const which of ["request", "response"] as const) {
|
|
expect(text("application/json", "json", which)).toBe("formatted");
|
|
expect(text("text/csv", "text", which)).toBe("table");
|
|
expect(text("image/svg+xml", "xml", which)).toBe("preview");
|
|
}
|
|
expect(text("text/plain", "text")).toBeNull();
|
|
});
|
|
|
|
test("HTML previews as a response and formats as a request", () => {
|
|
expect(text("text/html", "html", "response")).toBe("preview");
|
|
expect(text("text/html", "html", "request")).toBe("formatted");
|
|
});
|
|
|
|
test("multipart has parts whether or not it reads as text", () => {
|
|
const base = { which: "request" as const, mime: "multipart/form-data", language: null };
|
|
expect(flowPrettyView({ ...base, text: null, binary: false, hasForm: false })).toBe("parts");
|
|
});
|
|
|
|
test("a URL-encoded form's fields are its formatted view, where the tab has them", () => {
|
|
const base = {
|
|
which: "request" as const,
|
|
mime: "application/x-www-form-urlencoded",
|
|
text: "a=1",
|
|
binary: false,
|
|
language: "text" as const,
|
|
};
|
|
expect(flowPrettyView({ ...base, hasForm: true })).toBe("form");
|
|
expect(flowPrettyView({ ...base, hasForm: false })).toBeNull();
|
|
});
|
|
|
|
test("images, binary and undecodable bodies have one view", () => {
|
|
const base = { which: "response" as const, language: null, hasForm: false };
|
|
expect(flowPrettyView({ ...base, mime: "image/png", text: null, binary: true })).toBeNull();
|
|
expect(
|
|
flowPrettyView({ ...base, mime: "application/json", text: null, binary: true }),
|
|
).toBeNull();
|
|
expect(
|
|
flowPrettyView({ ...base, mime: "application/octet-stream", text: null, binary: false }),
|
|
).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("shownViewMode", () => {
|
|
test("follows the preference", () => {
|
|
expect(shownViewMode({ key: "a", large: false, preferred: "pretty", chosen: null })).toBe(
|
|
"pretty",
|
|
);
|
|
expect(shownViewMode({ key: "a", large: false, preferred: "raw", chosen: null })).toBe("raw");
|
|
});
|
|
|
|
test("a large body opens raw, and formats once asked, for that body alone", () => {
|
|
expect(shownViewMode({ key: "a", large: true, preferred: "pretty", chosen: null })).toBe("raw");
|
|
const chosen = { key: "a", mode: "pretty" as const };
|
|
expect(shownViewMode({ key: "a", large: true, preferred: "pretty", chosen })).toBe("pretty");
|
|
expect(shownViewMode({ key: "b", large: true, preferred: "pretty", chosen })).toBe("raw");
|
|
});
|
|
});
|