import { afterEach, describe, expect, it, vi } from "vitest"; import { cleanup, fireEvent, render, screen } from "@testing-library/react"; vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (key: string) => key }), })); import { PluginConsentPrompt } from "@/plugins/PluginConsentPrompt"; import { mergePlugins } from "@/plugins/plugin-model"; afterEach(cleanup); const [plugin] = mergePlugins( [], [ { id: "docker", name: "Docker", description: "", author: "Termix", category: "", versions: [], latestVersion: "1.0.0", installed: false, installedVersion: null, updateAvailable: false, addedCapabilities: [], pinnedVersion: null, autoUpdate: false, bundled: false, installCount: null, installCountSource: null, }, ], ); describe("PluginConsentPrompt", () => { it("lists notable capabilities and folds the low risk ones", () => { render( {}} onConfirm={() => {}} />, ); expect( screen.getByText("plugins.capabilities.ssh:connect.title"), ).toBeTruthy(); expect(screen.queryByText("plugins.capabilities.kv:own.title")).toBeNull(); expect(screen.getByText("plugins.manager.consent.minor")).toBeTruthy(); }); it("confirms and cancels", () => { const onConfirm = vi.fn(); const onCancel = vi.fn(); render( , ); expect( screen.getByText("plugins.manager.consent.updateExplain"), ).toBeTruthy(); fireEvent.click(screen.getByText("plugins.manager.consent.agreeUpdate")); fireEvent.click(screen.getByText("common.cancel")); expect(onConfirm).toHaveBeenCalledOnce(); expect(onCancel).toHaveBeenCalledOnce(); }); it("renders nothing without a request", () => { const { container } = render( {}} onConfirm={() => {}} />, ); expect(container.innerHTML).toBe(""); }); });