дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
reqwest's automatic redirects turned a POST into a plain GET on a 301 or 302, such as the http to https redirect in #4486, and hid the redirect. Redirects are now followed by hand, as IntelliJ's HTTP Client does: 301, 302, 303, 307 and 308, at most 50 times. A 303 continues as GET without the body; the other statuses keep the method and body. Authorization and cookie headers are not re-sent to another host. The followed hops are listed in the response view. Co-authored-by: Inf1mum <[email protected]>
69 рядки
2.4 KiB
TypeScript
69 рядки
2.4 KiB
TypeScript
import { act, fireEvent, render, screen } from "@testing-library/react";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import type { HttpExchange } from "@/platform/ipc";
|
|
|
|
vi.mock("./store", async (importOriginal) => ({
|
|
...(await importOriginal<typeof import("./store")>()),
|
|
refreshHistory: vi.fn(async () => {}),
|
|
}));
|
|
|
|
const { useHttpClient } = await import("./store");
|
|
const { HttpClientView } = await import("./HttpClientView");
|
|
|
|
const exchange: HttpExchange = {
|
|
entry: {
|
|
id: "e1",
|
|
timeMs: 0,
|
|
name: null,
|
|
method: "GET",
|
|
url: "http://x/api",
|
|
status: 200,
|
|
totalMs: 5,
|
|
file: null,
|
|
error: null,
|
|
},
|
|
request: { name: null, method: "GET", url: "http://x/api", headers: [], body: null },
|
|
response: {
|
|
status: 200,
|
|
statusText: "OK",
|
|
version: "HTTP/1.1",
|
|
headers: [["content-type", "text/plain"]],
|
|
contentType: "text/plain",
|
|
redirects: [],
|
|
body: "alpha beta\nbeta gamma\nBeta",
|
|
size: 26,
|
|
truncated: false,
|
|
ttfbMs: 1,
|
|
totalMs: 5,
|
|
},
|
|
};
|
|
|
|
describe("HTTP response find", () => {
|
|
afterEach(() => useHttpClient.setState({ history: [], exchanges: {}, selected: null }));
|
|
|
|
it("opens a find bar with ⌘F in the response and marks the matches", () => {
|
|
Element.prototype.scrollIntoView ??= () => {};
|
|
useHttpClient.setState({ history: [exchange.entry], exchanges: { e1: exchange }, selected: "e1" });
|
|
render(<HttpClientView />);
|
|
const body = screen.getByLabelText("Response body");
|
|
fireEvent.keyDown(body, { key: "f", metaKey: true, ctrlKey: true });
|
|
const input = screen.getByLabelText("Find in response", { selector: "input" });
|
|
act(() => {
|
|
fireEvent.change(input, { target: { value: "beta" } });
|
|
});
|
|
const marks = body.querySelectorAll("mark");
|
|
expect([...marks].map((m) => m.textContent)).toEqual(["beta", "beta", "Beta"]);
|
|
expect(screen.getByText("1/3")).toBeTruthy();
|
|
expect(body.textContent).toBe("alpha beta\nbeta gamma\nBeta");
|
|
fireEvent.keyDown(input, { key: "Enter" });
|
|
expect(screen.getByText("2/3")).toBeTruthy();
|
|
expect(
|
|
marks[1]!.hasAttribute("data-find-current") ||
|
|
body.querySelectorAll("mark")[1]!.hasAttribute("data-find-current"),
|
|
).toBe(true);
|
|
fireEvent.keyDown(input, { key: "Escape" });
|
|
expect(screen.queryByLabelText("Find in response", { selector: "input" })).toBeNull();
|
|
expect(body.querySelectorAll("mark")).toHaveLength(0);
|
|
});
|
|
});
|