mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-31 23:55:23 +00:00
fix: proxmox stats tab reads its switch from plugin host settings
This commit is contained in:
1 parent
ba05b6a610
commit
69b1b9805b
2 files changed
+55
-5
No files matched your search
@@ -42,8 +42,12 @@ interface HostConfig {
|
|||||||
name: string;
|
name: string;
|
||||||
ip: string;
|
ip: string;
|
||||||
username: string;
|
username: string;
|
||||||
enableProxmoxStats?: boolean;
|
pluginSettings?: {
|
||||||
proxmoxStatsConfig?: string | ProxmoxStatsConfig | null;
|
proxmox?: {
|
||||||
|
enableProxmoxStats?: boolean;
|
||||||
|
proxmoxStatsConfig?: string | ProxmoxStatsConfig | null;
|
||||||
|
};
|
||||||
|
};
|
||||||
authType?: string;
|
authType?: string;
|
||||||
port?: number;
|
port?: number;
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
@@ -115,9 +119,10 @@ function ProxmoxStatsInner({
|
|||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const proxmoxSettings = currentHostConfig?.pluginSettings?.proxmox;
|
||||||
const statsConfig = React.useMemo(
|
const statsConfig = React.useMemo(
|
||||||
() => parseProxmoxStatsConfig(currentHostConfig?.proxmoxStatsConfig),
|
() => parseProxmoxStatsConfig(proxmoxSettings?.proxmoxStatsConfig),
|
||||||
[currentHostConfig?.proxmoxStatsConfig],
|
[proxmoxSettings?.proxmoxStatsConfig],
|
||||||
);
|
);
|
||||||
|
|
||||||
React.useEffect(() => {
|
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 stopPollingRef = React.useRef<(() => void) | null>(null);
|
||||||
|
|
||||||
const fetchSnapshot = React.useCallback(async (): Promise<void> => {
|
const fetchSnapshot = React.useCallback(async (): Promise<void> => {
|
||||||
|
|||||||
@@ -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<Record<string, unknown>>()),
|
||||||
|
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<string, unknown>) => ({
|
||||||
|
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(<ProxmoxStatsTab hostConfig={host({ enableProxmoxStats: true })} />);
|
||||||
|
expect(
|
||||||
|
screen.queryByText("proxmoxStats.noHostSelected"),
|
||||||
|
).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows the empty state when stats are off for the host", () => {
|
||||||
|
render(<ProxmoxStatsTab hostConfig={host({})} />);
|
||||||
|
expect(screen.getByText("proxmoxStats.noHostSelected")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user