Файли
openidea/src/workbench/WebConnectionBanner.test.tsx
T
Luis Felipeтаluisfelipe18 9f643af069 feat(web): openidea-server --web serves the IDE to a browser (#5134)
`openidea-server --web` serves the built frontend and the IDE backend over one HTTP + WebSocket port, directly or behind a reverse proxy that strips or keeps its path prefix.

- The rpc dispatcher gains an async `invoke` with a channel sink, so project-host commands, streaming channels and IDE events run over WebSockets as they do over `--stdio`.
- Token auth is on by default (a random token unless `--token` or `--no-auth`), binds 127.0.0.1 by default, and WebSocket upgrades must be same-origin.
- The browser serves the desktop shell commands with the trust classes the desktop declares (a test keeps them in step), and the desktop menu spec, now in `ide_host::menu`. Recent-project recording and project rename are shared ide-host ops.
- WebSocket output is queued without dropping channel data or events. A reloaded page gets back the project its window still has open; after a server restart the page reloads. One tab per window, with Take Over.
- Browser fallbacks for the title bar menu, path chooser, clipboard, dialogs, Settings and external links; a reconnecting banner and an unsaved-changes guard.
- `scripts/start-web.sh` and the guide (English and Chinese).

Co-authored-by: luisfelipe18 <[email protected]>
2026-11-26 23:00:28 +08:00

48 рядки
1.8 KiB
TypeScript

import { act, fireEvent, render, screen } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import * as webBridge from "@/platform/webBridge";
import { useWebConnection } from "@/platform/webBridge";
import { WebConnectionBanner } from "./WebConnectionBanner";
describe("WebConnectionBanner", () => {
afterEach(() => {
vi.restoreAllMocks();
useWebConnection.setState({
active: false,
status: "idle",
windowLabel: "main",
serverHome: "",
serverOs: "linux",
});
});
it("renders nothing outside web mode or while connected", () => {
const { container } = render(<WebConnectionBanner />);
expect(container.firstChild).toBeNull();
act(() => useWebConnection.setState({ active: true, status: "connected" }));
expect(container.firstChild).toBeNull();
});
it("shows a reconnecting status banner while the web socket is reconnecting", () => {
act(() => useWebConnection.setState({ active: true, status: "reconnecting" }));
render(<WebConnectionBanner />);
const banner = screen.getByRole("status");
expect(banner.hasAttribute("data-web-reconnecting")).toBe(true);
expect(banner.textContent).toContain("Reconnecting");
});
it("shows a superseded status banner with a Take Over button", () => {
const takeOverSpy = vi.spyOn(webBridge, "takeOverWebSession").mockImplementation(() => {});
act(() => useWebConnection.setState({ active: true, status: "superseded" }));
render(<WebConnectionBanner />);
const banner = screen.getByRole("status");
expect(banner.hasAttribute("data-web-superseded")).toBe(true);
expect(banner.textContent).toContain("This OpenIDEA session is open in another browser tab.");
fireEvent.click(screen.getByRole("button", { name: "Take Over" }));
expect(takeOverSpy).toHaveBeenCalledTimes(1);
});
});