mirror of
https://github.com/gethomepage/homepage.git
synced 2026-05-19 03:49:14 +08:00
Some checks failed
Crowdin Action / Crowdin Sync (push) Has been cancelled
Docker CI / Linting Checks (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Repository Maintenance / Stale (push) Has been cancelled
Repository Maintenance / Lock Old Threads (push) Has been cancelled
Repository Maintenance / Close Answered Discussions (push) Has been cancelled
Repository Maintenance / Close Outdated Discussions (push) Has been cancelled
Repository Maintenance / Close Unsupported Feature Requests (push) Has been cancelled
44 lines
1.5 KiB
JavaScript
44 lines
1.5 KiB
JavaScript
// @vitest-environment jsdom
|
|
|
|
import { screen } from "@testing-library/react";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
import { renderWithProviders } from "test-utils/render-with-providers";
|
|
import { expectBlockValue } from "test-utils/widget-assertions";
|
|
|
|
const { useSWR } = vi.hoisted(() => ({ useSWR: vi.fn() }));
|
|
vi.mock("swr", () => ({ default: useSWR }));
|
|
|
|
import Component from "./component";
|
|
|
|
describe("widgets/proxmoxvm/component", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("renders placeholders while loading", () => {
|
|
useSWR.mockReturnValue({ data: undefined, error: undefined });
|
|
|
|
const { container } = renderWithProviders(
|
|
<Component service={{ widget: { type: "proxmoxvm", node: "n1", vmid: "100" } }} />,
|
|
{ settings: { hideErrors: false } },
|
|
);
|
|
|
|
expect(container.querySelectorAll(".service-block")).toHaveLength(2);
|
|
expect(screen.getByText("resources.cpu")).toBeInTheDocument();
|
|
expect(screen.getByText("resources.mem")).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders cpu percent and mem bytes when loaded", () => {
|
|
useSWR.mockReturnValue({ data: { cpu: 0.5, mem: 1024 }, error: undefined });
|
|
|
|
const { container } = renderWithProviders(
|
|
<Component service={{ widget: { type: "proxmoxvm", node: "n1", vmid: "100" } }} />,
|
|
{ settings: { hideErrors: false } },
|
|
);
|
|
|
|
expectBlockValue(container, "resources.cpu", 50);
|
|
expectBlockValue(container, "resources.mem", 1024);
|
|
});
|
|
});
|