diff --git a/src/widgets/peanut/component.jsx b/src/widgets/peanut/component.jsx index 8ff6b05b5..914b49cb6 100644 --- a/src/widgets/peanut/component.jsx +++ b/src/widgets/peanut/component.jsx @@ -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 ( - - + + ); diff --git a/src/widgets/peanut/component.test.jsx b/src/widgets/peanut/component.test.jsx index 466cddf9d..177fae34b 100644 --- a/src/widgets/peanut/component.test.jsx +++ b/src/widgets/peanut/component.test.jsx @@ -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(, { settings: { hideErrors: false } }); + + expect(screen.getAllByText("-")).toHaveLength(3); + }); });