huskies: merge 1058
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { WsConnectivity } from "../hooks/useChatWebSocket";
|
||||
import { ChatHeader } from "./ChatHeader";
|
||||
|
||||
vi.mock("../api/client", () => ({
|
||||
@@ -21,6 +22,8 @@ interface ChatHeaderProps {
|
||||
enableTools: boolean;
|
||||
onToggleTools: (enabled: boolean) => void;
|
||||
wsConnected: boolean;
|
||||
wsConnectivity?: WsConnectivity;
|
||||
wsDisconnectedAt?: Date | null;
|
||||
}
|
||||
|
||||
function makeProps(overrides: Partial<ChatHeaderProps> = {}): ChatHeaderProps {
|
||||
@@ -289,6 +292,53 @@ describe("ChatHeader", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ── Connectivity indicator ────────────────────────────────────────────────
|
||||
|
||||
it("does not render connectivity dot when wsConnectivity is not provided", () => {
|
||||
render(<ChatHeader {...makeProps()} />);
|
||||
expect(screen.queryByTestId("ws-connectivity-dot")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders green dot with title 'Connected' when connected", () => {
|
||||
render(<ChatHeader {...makeProps({ wsConnectivity: "connected" })} />);
|
||||
const dot = screen.getByTestId("ws-connectivity-dot");
|
||||
expect(dot).toBeInTheDocument();
|
||||
expect(dot).toHaveAttribute("title", "Connected");
|
||||
expect(dot.style.backgroundColor).toBe("rgb(76, 175, 80)");
|
||||
});
|
||||
|
||||
it("renders amber dot with title 'Reconnecting…' when reconnecting", () => {
|
||||
render(<ChatHeader {...makeProps({ wsConnectivity: "reconnecting" })} />);
|
||||
const dot = screen.getByTestId("ws-connectivity-dot");
|
||||
expect(dot).toHaveAttribute("title", "Reconnecting…");
|
||||
expect(dot.style.backgroundColor).toBe("rgb(245, 166, 35)");
|
||||
});
|
||||
|
||||
it("renders amber dot with title 'Connecting…' when connecting", () => {
|
||||
render(<ChatHeader {...makeProps({ wsConnectivity: "connecting" })} />);
|
||||
const dot = screen.getByTestId("ws-connectivity-dot");
|
||||
expect(dot).toHaveAttribute("title", "Connecting…");
|
||||
expect(dot.style.backgroundColor).toBe("rgb(245, 166, 35)");
|
||||
});
|
||||
|
||||
it("renders red dot with title 'Disconnected' when failed with no timestamp", () => {
|
||||
render(<ChatHeader {...makeProps({ wsConnectivity: "failed" })} />);
|
||||
const dot = screen.getByTestId("ws-connectivity-dot");
|
||||
expect(dot).toHaveAttribute("title", "Disconnected");
|
||||
expect(dot.style.backgroundColor).toBe("rgb(229, 57, 53)");
|
||||
});
|
||||
|
||||
it("renders red dot with 'Disconnected since HH:MM' when failed with timestamp", () => {
|
||||
const disconnectedAt = new Date("2026-05-14T14:30:00");
|
||||
render(
|
||||
<ChatHeader
|
||||
{...makeProps({ wsConnectivity: "failed", wsDisconnectedAt: disconnectedAt })}
|
||||
/>,
|
||||
);
|
||||
const dot = screen.getByTestId("ws-connectivity-dot");
|
||||
expect(dot.getAttribute("title")).toMatch(/Disconnected since/);
|
||||
});
|
||||
|
||||
it("clears reconnecting state when wsConnected transitions to true", async () => {
|
||||
const { api } = await import("../api/client");
|
||||
vi.mocked(api.rebuildAndRestart).mockRejectedValue(
|
||||
|
||||
Reference in New Issue
Block a user