Files
multica/packages/views/runtimes/components/update-section.test.tsx
Multica Eve 2d9cf045d0 MUL-4861: align runtime CLI update permissions (#5514)
* fix(runtimes): align CLI update permissions

Co-authored-by: multica-agent <github@multica.ai>

* fix(runtimes): address update review nits

Co-authored-by: multica-agent <github@multica.ai>

---------

Co-authored-by: Eve <eve@multica-ai.local>
Co-authored-by: multica-agent <github@multica.ai>
2026-07-16 13:54:01 +08:00

101 lines
2.8 KiB
TypeScript

// @vitest-environment jsdom
import { afterEach, describe, expect, it, vi } from "vitest";
import { cleanup, render, screen } from "@testing-library/react";
import { I18nProvider } from "@multica/core/i18n/react";
import enCommon from "../../locales/en/common.json";
import enRuntimes from "../../locales/en/runtimes.json";
import { UpdateSection } from "./update-section";
const TEST_RESOURCES = { en: { common: enCommon, runtimes: enRuntimes } };
vi.mock("@multica/core/api", () => ({
api: {
initiateUpdate: vi.fn(),
getUpdateResult: vi.fn(),
},
}));
function renderSection(props: {
runtimeId: string | null;
launchedBy?: string | null;
currentVersion?: string;
}) {
return render(
<I18nProvider locale="en" resources={TEST_RESOURCES}>
<UpdateSection
runtimeId={props.runtimeId}
currentVersion={props.currentVersion ?? "v0.4.0"}
isOnline
launchedBy={props.launchedBy}
/>
</I18nProvider>,
);
}
afterEach(() => {
cleanup();
vi.unstubAllGlobals();
});
describe("UpdateSection read-only status", () => {
it("shows Latest without a redundant read-only label or update action", async () => {
vi.stubGlobal(
"fetch",
vi.fn().mockResolvedValue({
ok: true,
json: async () => ({ tag_name: "v0.4.0" }),
}),
);
renderSection({ runtimeId: null });
expect(await screen.findByText("Latest")).toBeInTheDocument();
expect(screen.queryByText("Read-only")).not.toBeInTheDocument();
expect(
screen.queryByRole("button", { name: "Update" }),
).not.toBeInTheDocument();
});
it("shows the Desktop manager without exposing an update action", () => {
vi.stubGlobal(
"fetch",
vi.fn().mockResolvedValue({
ok: true,
json: async () => ({ tag_name: "v0.4.0" }),
}),
);
renderSection({ runtimeId: null, launchedBy: "desktop" });
expect(screen.getByText("Managed by Desktop")).toBeInTheDocument();
expect(screen.queryByText("Read-only")).not.toBeInTheDocument();
expect(
screen.queryByRole("button", { name: "Update" }),
).not.toBeInTheDocument();
});
it("shows an available version without an action for a read-only viewer", async () => {
vi.stubGlobal(
"fetch",
vi.fn().mockResolvedValue({
ok: true,
json: async () => ({ tag_name: "v0.4.0" }),
}),
);
renderSection({ runtimeId: null, currentVersion: "v0.3.17" });
expect(await screen.findByText("available")).toBeInTheDocument();
expect(screen.getByText("Read-only")).toBeInTheDocument();
expect(
screen.getByTitle(
"Only runtime owners and workspace admins can update the CLI.",
),
).toBeInTheDocument();
expect(
screen.queryByRole("button", { name: "Update" }),
).not.toBeInTheDocument();
});
});