mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-17 09:35:50 -07:00
c764d05a0c
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (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
66 lines
2.0 KiB
React
66 lines
2.0 KiB
React
// @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";
|
|
|
|
const { useWidgetAPI } = vi.hoisted(() => ({
|
|
useWidgetAPI: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("utils/proxy/use-widget-api", () => ({
|
|
default: useWidgetAPI,
|
|
}));
|
|
|
|
import Component from "./component";
|
|
|
|
describe("widgets/peanut/component", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("renders placeholders while loading", () => {
|
|
useWidgetAPI.mockReturnValue({ data: undefined, error: undefined });
|
|
|
|
const { container } = renderWithProviders(<Component service={{ widget: { type: "peanut" } }} />, {
|
|
settings: { hideErrors: false },
|
|
});
|
|
|
|
expect(container.querySelectorAll(".service-block")).toHaveLength(3);
|
|
expect(screen.getByText("peanut.battery_charge")).toBeInTheDocument();
|
|
expect(screen.getByText("peanut.ups_load")).toBeInTheDocument();
|
|
expect(screen.getByText("peanut.ups_status")).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders legacy field mapping and status translation", () => {
|
|
const data = {
|
|
"battery.charge": 55,
|
|
"ups.load": 12,
|
|
"ups.status": "OL",
|
|
};
|
|
useWidgetAPI.mockReturnValue({
|
|
data,
|
|
error: undefined,
|
|
});
|
|
|
|
renderWithProviders(<Component service={{ widget: { type: "peanut" } }} />, { settings: { hideErrors: false } });
|
|
|
|
expect(screen.getByText("55")).toBeInTheDocument();
|
|
expect(screen.getByText("12")).toBeInTheDocument();
|
|
expect(screen.getByText("peanut.online")).toBeInTheDocument();
|
|
expect(data).toEqual({ "battery.charge": 55, "ups.load": 12, "ups.status": "OL" });
|
|
});
|
|
|
|
it("renders dashes when readings are missing", () => {
|
|
useWidgetAPI.mockReturnValue({
|
|
data: { "device.model": "OR500LCDRM1Ua", "ups.status": 0 },
|
|
error: undefined,
|
|
});
|
|
|
|
renderWithProviders(<Component service={{ widget: { type: "peanut" } }} />, { settings: { hideErrors: false } });
|
|
|
|
expect(screen.getAllByText("-")).toHaveLength(3);
|
|
});
|
|
});
|