From 69b1b9805b837d0d244f730da482086863377c95 Mon Sep 17 00:00:00 2001 From: LukeGus Date: Wed, 30 Sep 2026 17:48:37 -0500 Subject: [PATCH] fix: proxmox stats tab reads its switch from plugin host settings --- .../src/frontend/stats/ProxmoxStatsTab.tsx | 15 ++++--- .../frontend/stats/ProxmoxStatsTab.test.tsx | 45 +++++++++++++++++++ 2 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 plugins/proxmox/tests/frontend/stats/ProxmoxStatsTab.test.tsx diff --git a/plugins/proxmox/src/frontend/stats/ProxmoxStatsTab.tsx b/plugins/proxmox/src/frontend/stats/ProxmoxStatsTab.tsx index 0e1b0d5ae..774faed7b 100644 --- a/plugins/proxmox/src/frontend/stats/ProxmoxStatsTab.tsx +++ b/plugins/proxmox/src/frontend/stats/ProxmoxStatsTab.tsx @@ -42,8 +42,12 @@ interface HostConfig { name: string; ip: string; username: string; - enableProxmoxStats?: boolean; - proxmoxStatsConfig?: string | ProxmoxStatsConfig | null; + pluginSettings?: { + proxmox?: { + enableProxmoxStats?: boolean; + proxmoxStatsConfig?: string | ProxmoxStatsConfig | null; + }; + }; authType?: string; port?: number; [key: string]: unknown; @@ -115,9 +119,10 @@ function ProxmoxStatsInner({ null, ); + const proxmoxSettings = currentHostConfig?.pluginSettings?.proxmox; const statsConfig = React.useMemo( - () => parseProxmoxStatsConfig(currentHostConfig?.proxmoxStatsConfig), - [currentHostConfig?.proxmoxStatsConfig], + () => parseProxmoxStatsConfig(proxmoxSettings?.proxmoxStatsConfig), + [proxmoxSettings?.proxmoxStatsConfig], ); React.useEffect(() => { @@ -162,7 +167,7 @@ function ProxmoxStatsInner({ }); }, []); - const notEnabled = currentHostConfig?.enableProxmoxStats !== true; + const notEnabled = proxmoxSettings?.enableProxmoxStats !== true; const stopPollingRef = React.useRef<(() => void) | null>(null); const fetchSnapshot = React.useCallback(async (): Promise => { diff --git a/plugins/proxmox/tests/frontend/stats/ProxmoxStatsTab.test.tsx b/plugins/proxmox/tests/frontend/stats/ProxmoxStatsTab.test.tsx new file mode 100644 index 000000000..fc4cfdf54 --- /dev/null +++ b/plugins/proxmox/tests/frontend/stats/ProxmoxStatsTab.test.tsx @@ -0,0 +1,45 @@ +import { cleanup, render, screen } from "@testing-library/react"; +import "@testing-library/jest-dom/vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; + +vi.mock("@termix/plugin-sdk/frontend", async (importOriginal) => ({ + ...(await importOriginal>()), + useTranslation: () => ({ t: (key: string) => key, language: "en" }), + usePluginApi: () => ({}), + useHosts: () => ({ hosts: [] }), +})); + +vi.mock("../../../src/frontend/stats/proxmox-stats-api", () => ({ + createProxmoxStatsApi: () => ({ + startPolling: () => new Promise(() => {}), + stopPolling: () => Promise.resolve(), + getSnapshot: () => new Promise(() => {}), + sendHeartbeat: () => Promise.resolve(), + }), +})); + +import { ProxmoxStatsTab } from "../../../src/frontend/stats/ProxmoxStatsTab"; + +const host = (proxmox: Record) => ({ + id: 1, + name: "pve", + ip: "10.0.0.1", + username: "root", + pluginSettings: { proxmox }, +}); + +afterEach(cleanup); + +describe("ProxmoxStatsTab", () => { + it("reads the stats switch from the plugin host settings", () => { + render(); + expect( + screen.queryByText("proxmoxStats.noHostSelected"), + ).not.toBeInTheDocument(); + }); + + it("shows the empty state when stats are off for the host", () => { + render(); + expect(screen.getByText("proxmoxStats.noHostSelected")).toBeInTheDocument(); + }); +});