Files
multica/packages/views/layout/help-launcher.test.tsx
Marcelo Cecin 7985699df9 feat(help): surface the running server version in the Help popover (#4959)
Surface the running server build version in the Help popover so self-hosted
operators can confirm what's deployed and include it in bug reports.

- Backend exposes it via /api/config's server_version (from main.version),
  omitempty so older/unstamped builds omit the field.
- Unstamped "dev" builds are normalized to empty and the row stays hidden.
- The row is suppressed on the managed cloud (frontend host multica.ai) and
  shown only on self-hosted deployments.
- Frontend renders a muted footer row in the Help popover only when the value
  is non-empty; i18n added for en/ja/ko/zh-Hans.
2026-07-14 20:11:52 +08:00

52 lines
2.0 KiB
TypeScript

import type { ReactNode } from "react";
import { render, screen } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { configStore } from "@multica/core/config";
import enLayout from "../locales/en/layout.json";
import { HelpLauncher } from "./help-launcher";
// react-i18next isn't initialised in the views test env, so resolve the
// selector against the real en/layout.json to assert on actual copy.
vi.mock("../i18n", () => ({
useT: () => ({
t: (
sel: (r: typeof enLayout) => string,
vars?: Record<string, string>,
) => {
const template = sel(enLayout);
return vars
? template.replace(/\{\{(\w+)\}\}/g, (_, key) => String(vars[key] ?? ""))
: template;
},
}),
}));
// Follows the app-sidebar.test.tsx convention of flattening the Base UI
// dropdown primitives to plain children so the menu content is always in
// the DOM, instead of exercising the real portal/open-state interaction.
vi.mock("@multica/ui/components/ui/dropdown-menu", () => ({
DropdownMenu: ({ children }: { children: ReactNode }) => <>{children}</>,
DropdownMenuContent: ({ children }: { children: ReactNode }) => <>{children}</>,
DropdownMenuItem: ({ children }: { children: ReactNode }) => <>{children}</>,
DropdownMenuLabel: ({ children }: { children: ReactNode }) => <div>{children}</div>,
DropdownMenuSeparator: () => null,
DropdownMenuTrigger: ({ children }: { children: ReactNode }) => <>{children}</>,
}));
afterEach(() => {
configStore.getState().setServerVersion("");
});
describe("HelpLauncher", () => {
it("does not show a version row when the server omits it", () => {
render(<HelpLauncher />);
expect(screen.queryByText(/Server version/)).not.toBeInTheDocument();
});
it("shows the server version once /api/config resolves it", () => {
configStore.getState().setServerVersion("1.2.3");
render(<HelpLauncher />);
expect(screen.getByText("Server version 1.2.3")).toBeInTheDocument();
});
});