Files
AgentHub/client/src/components/__tests__/Sidebar.test.tsx
T
nntrivi2001 cc85e35439 feat(updates): detect the newest release and self-apply it, including plugin installs
Update detection was a commit count against the default branch, which says nothing about whether a *version* shipped and is pure noise on the plugin cache (a depth-1 clone, where every distance is a graft artefact). It now reads the forge's own releases API and compares the published tag to this install's package.json version, falling back to the commit count only when no release can be read — with the reason in release_check, so "up to date" never silently means "we could not look".

Two states a commit count cannot express: dev_build (ahead of the newest release, missing nothing from it) now reads "Dev build - N ahead" instead of a false "Up to date"; and on a shallow clone every commits_*_release field is null and dev_build is never asserted, because the numbers would be meaningless.

POST /api/updates/apply gains a second mode, chosen by install kind and never by the request body. A checkout still fast-forwards onto the release tag, rebuilds and self-restarts. A ~/.claude/plugins/cache/ install is refused by applyUpdate (that directory is Claude Code's to replace) and handed instead to a detached chain: claude plugin marketplace update -> claude plugin update -y -> plugin-bootstrap.js --force from the NEW cache dir, which retires this server and starts its replacement. Both write the HTTP response before anything stops the process.

The chain records every outcome to plugin-update.json in the runtime dir, outside the cache the update replaces, so the next server reports it as last_plugin_update: a failed chain is otherwise indistinguishable from a slow one, and the tab would poll a server that never returns. /reload-plugins is deliberately not in the chain - it is REPL-scoped to the session that runs it, so no background process can perform it, and plugin-bootstrap derives PLUGIN_ROOT from its own __dirname, which is what makes it unnecessary for the dashboard.

Also rebrands the sidebar subtitle, splash and page title to SmartGift Solution, and corrects three ARCHITECTURE.md statements that claimed /apply did not exist.

Verified: server 1683/1683, client 486/486, build, prettier, file-header audit, openapi.yaml regenerated.
2026-09-10 16:03:07 +07:00

102 lines
3.8 KiB
TypeScript

/**
* @file Sidebar.test.tsx
* @description Unit tests for the Sidebar component, which is responsible for rendering the application's sidebar navigation. The tests cover rendering of the brand name, subtitle, navigation links, WebSocket connection status, and version number. The tests use React Testing Library and Vitest for assertions and mocking.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
import { describe, it, expect } from "vitest";
import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { MemoryRouter } from "react-router-dom";
import { Sidebar } from "../Sidebar";
function renderSidebar(wsConnected: boolean, collapsed = false) {
return render(
<MemoryRouter>
<Sidebar wsConnected={wsConnected} collapsed={collapsed} onToggle={() => {}} />
</MemoryRouter>
);
}
describe("Sidebar", () => {
it("should render the brand name", () => {
renderSidebar(true);
expect(screen.getByText("Agent Dashboard")).toBeInTheDocument();
});
it("should render the subtitle", () => {
renderSidebar(true);
expect(screen.getByText("SmartGift Solution")).toBeInTheDocument();
});
it("should render all navigation links", () => {
renderSidebar(true);
expect(screen.getByText("Dashboard")).toBeInTheDocument();
expect(screen.getByText("Sessions")).toBeInTheDocument();
// Activity Feed and Claude Config are no longer top-level entries: they
// moved into tabs on /sessions and /settings respectively.
expect(screen.getByText("Settings")).toBeInTheDocument();
expect(screen.queryByText("Activity Feed")).toBeNull();
});
it('should show "Live" when WebSocket is connected', () => {
renderSidebar(true);
expect(screen.getByText("Live")).toBeInTheDocument();
});
it('should show "Disconnected" when WebSocket is not connected', () => {
renderSidebar(false);
expect(screen.getByText("Disconnected")).toBeInTheDocument();
});
it("should show version number", () => {
// `__APP_VERSION__` is injected by Vite from the repo-root package.json
// (see vite.config.ts) and replaced at transform time in tests too, so this
// stays correct as the project version changes.
renderSidebar(true);
expect(screen.getByText(`v${__APP_VERSION__}`)).toBeInTheDocument();
});
it("should have correct navigation hrefs", () => {
renderSidebar(true);
const links = screen.getAllByRole("link");
const hrefs = links.map((link) => link.getAttribute("href"));
expect(hrefs).toContain("/");
expect(hrefs).toContain("/sessions");
expect(hrefs).toContain("/settings");
expect(hrefs).not.toContain("/activity");
});
it("should render both language options in expanded mode", () => {
renderSidebar(true);
expect(screen.getByRole("button", { name: "English" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Vietnamese" })).toBeInTheDocument();
// Chinese and Korean were dropped; offering them would render raw keys.
expect(screen.queryByRole("button", { name: "Chinese" })).toBeNull();
expect(screen.queryByRole("button", { name: "Korean" })).toBeNull();
});
it("should switch to Vietnamese when Vietnamese option is clicked", async () => {
const user = userEvent.setup();
renderSidebar(true);
await user.click(screen.getByRole("button", { name: "Vietnamese" }));
await waitFor(() => {
expect(screen.getByText("Tổng quan")).toBeInTheDocument();
});
});
it("should cycle language in collapsed mode", async () => {
const user = userEvent.setup();
renderSidebar(true, true);
expect(screen.getByText("EN")).toBeInTheDocument();
await user.click(screen.getByRole("button", { name: "Switch to Vietnamese" }));
await waitFor(() => {
expect(screen.getByText("VI")).toBeInTheDocument();
});
});
});