feat: session-scoped entries query, session title tree and message stream updates
This commit is contained in:
1 parent
bef8a35632
commit
e910e75849
37 files changed
+1409
-75
No files matched your search
@@ -0,0 +1,114 @@
|
||||
import { act } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { renderPage, type TestRoute } from "./helpers/render-page";
|
||||
|
||||
import { ServerChip } from "@/components/shared/server-chip";
|
||||
import type { InfoResponse } from "@/lib/api";
|
||||
import { setLanguage } from "@/lib/i18n";
|
||||
import { useConnectionStore } from "@/stores/connection";
|
||||
|
||||
/** Realistic daemon /info response payload without `status` field. */
|
||||
const realisticInfo: InfoResponse = {
|
||||
v: 1,
|
||||
daemonId: "daemon-test-1",
|
||||
machineId: "machine-test-1",
|
||||
platform: "linux",
|
||||
hostname: "devbook-eos",
|
||||
os: "Linux 6.12.0",
|
||||
version: "0.1.3",
|
||||
uptimeMs: 123456,
|
||||
port: 7676,
|
||||
capabilities: ["read", "steer"],
|
||||
limits: { maxInstances: 5 },
|
||||
};
|
||||
|
||||
const routes = (): TestRoute[] => [
|
||||
{
|
||||
path: "/",
|
||||
component: () => <ServerChip />,
|
||||
},
|
||||
{
|
||||
path: "/status",
|
||||
component: () => <div>Status Page</div>,
|
||||
},
|
||||
];
|
||||
|
||||
describe("ServerChip", () => {
|
||||
beforeEach(() => {
|
||||
setLanguage("en");
|
||||
useConnectionStore.getState().disconnect();
|
||||
useConnectionStore.getState().connect({ endpoint: "http://127.0.0.1:7676" });
|
||||
});
|
||||
|
||||
it("renders dot--ok and Online in English / 在线 in Chinese when serverStatus is online with status-less info payload", async () => {
|
||||
// Explicitly assert that realisticInfo does not contain a wire `status` field.
|
||||
expect("status" in realisticInfo).toBe(false);
|
||||
|
||||
const { container } = await renderPage(routes(), "/", { paired: true });
|
||||
|
||||
act(() => {
|
||||
const store = useConnectionStore.getState();
|
||||
store.setServer(realisticInfo);
|
||||
store.setServerStatus("online");
|
||||
});
|
||||
|
||||
const dot = container.querySelector(".server-chip .dot");
|
||||
expect(dot).not.toBeNull();
|
||||
expect(dot).toHaveClass("dot--ok");
|
||||
expect(dot).not.toHaveClass("dot--exited");
|
||||
expect(dot?.getAttribute("title")).toBe("Online");
|
||||
expect(dot?.getAttribute("aria-label")).toBe("Online");
|
||||
|
||||
// Verify Chinese localization
|
||||
act(() => {
|
||||
setLanguage("zh");
|
||||
});
|
||||
expect(dot?.getAttribute("title")).toBe("在线");
|
||||
expect(dot?.getAttribute("aria-label")).toBe("在线");
|
||||
});
|
||||
|
||||
it("renders dot--idle and Unknown / 未知 when serverStatus is unknown", async () => {
|
||||
const { container } = await renderPage(routes(), "/", { paired: true });
|
||||
|
||||
act(() => {
|
||||
const store = useConnectionStore.getState();
|
||||
store.setServer(realisticInfo);
|
||||
store.setServerStatus("unknown");
|
||||
});
|
||||
|
||||
const dot = container.querySelector(".server-chip .dot");
|
||||
expect(dot).not.toBeNull();
|
||||
expect(dot).toHaveClass("dot--idle");
|
||||
expect(dot?.getAttribute("title")).toBe("Unknown");
|
||||
expect(dot?.getAttribute("aria-label")).toBe("Unknown");
|
||||
|
||||
act(() => {
|
||||
setLanguage("zh");
|
||||
});
|
||||
expect(dot?.getAttribute("title")).toBe("未知");
|
||||
expect(dot?.getAttribute("aria-label")).toBe("未知");
|
||||
});
|
||||
|
||||
it("renders dot--exited and Offline / 离线 when serverStatus is offline", async () => {
|
||||
const { container } = await renderPage(routes(), "/", { paired: true });
|
||||
|
||||
act(() => {
|
||||
const store = useConnectionStore.getState();
|
||||
store.setServer(realisticInfo);
|
||||
store.setServerStatus("offline");
|
||||
});
|
||||
|
||||
const dot = container.querySelector(".server-chip .dot");
|
||||
expect(dot).not.toBeNull();
|
||||
expect(dot).toHaveClass("dot--exited");
|
||||
expect(dot?.getAttribute("title")).toBe("Offline");
|
||||
expect(dot?.getAttribute("aria-label")).toBe("Offline");
|
||||
|
||||
act(() => {
|
||||
setLanguage("zh");
|
||||
});
|
||||
expect(dot?.getAttribute("title")).toBe("离线");
|
||||
expect(dot?.getAttribute("aria-label")).toBe("离线");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user