mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-26 22:11:20 -07:00
Fix: better handle PeaNUT missing data (#7139)
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
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
This commit is contained in:
@@ -41,17 +41,15 @@ export default function Component({ service }) {
|
||||
status = t("peanut.low_battery");
|
||||
break;
|
||||
default:
|
||||
status = upsStatus;
|
||||
status = typeof upsStatus === "string" && upsStatus ? upsStatus : "-";
|
||||
}
|
||||
|
||||
const percent = (value) => (value === undefined || value === null ? "-" : t("common.percent", { value }));
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block
|
||||
label="peanut.battery_charge"
|
||||
value={t("common.percent", { value: batteryCharge })}
|
||||
highlightValue={batteryCharge}
|
||||
/>
|
||||
<Block label="peanut.ups_load" value={t("common.percent", { value: upsLoad })} highlightValue={upsLoad} />
|
||||
<Block label="peanut.battery_charge" value={percent(batteryCharge)} highlightValue={batteryCharge} />
|
||||
<Block label="peanut.ups_load" value={percent(upsLoad)} highlightValue={upsLoad} />
|
||||
<Block label="peanut.ups_status" value={status} />
|
||||
</Container>
|
||||
);
|
||||
|
||||
@@ -51,4 +51,15 @@ describe("widgets/peanut/component", () => {
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user