diff --git a/public/locales/en/common.json b/public/locales/en/common.json index a55414819..c993ecba0 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -132,7 +132,8 @@ "movies": "Movies", "series": "Series", "episodes": "Episodes", - "songs": "Songs" + "songs": "Songs", + "albums": "Albums" }, "esphome": { "offline": "Offline", diff --git a/src/widgets/jellyfin/component.jsx b/src/widgets/jellyfin/component.jsx index 1ce543202..8c32bb69c 100644 --- a/src/widgets/jellyfin/component.jsx +++ b/src/widgets/jellyfin/component.jsx @@ -176,6 +176,13 @@ function SessionEntry({ playCommand, session, enableUser, showEpisodeNumber, ena function CountBlocks({ service, countData }) { const { t } = useTranslation(); + const { widget } = service; + + if (!widget.fields || widget.fields.length === 0) { + widget.fields = ["movies", "series", "episodes", "songs"]; + } else if (widget.fields?.length > 4) { + widget.fields = widget.fields.slice(0, 4); + } if (!countData) { return ( @@ -184,6 +191,7 @@ function CountBlocks({ service, countData }) { + ); } @@ -194,6 +202,7 @@ function CountBlocks({ service, countData }) { + ); } diff --git a/src/widgets/jellyfin/component.test.jsx b/src/widgets/jellyfin/component.test.jsx index b31193343..5b6cc114e 100644 --- a/src/widgets/jellyfin/component.test.jsx +++ b/src/widgets/jellyfin/component.test.jsx @@ -40,7 +40,7 @@ describe("widgets/jellyfin/component", () => { useWidgetAPI .mockReturnValueOnce({ data: [], error: undefined, mutate: vi.fn() }) // sessions .mockReturnValueOnce({ - data: { MovieCount: 1, SeriesCount: 2, EpisodeCount: 3, SongCount: 4 }, + data: { MovieCount: 1, SeriesCount: 2, EpisodeCount: 3, SongCount: 4, AlbumCount: 5 }, error: undefined, }); // count @@ -89,4 +89,21 @@ describe("widgets/jellyfin/component", () => { expect(screen.getByText(/00:00/)).toBeInTheDocument(); expect(screen.getByText(/01:00/)).toBeInTheDocument(); }); + + it("renders optional albums field when included", () => { + useWidgetAPI + .mockReturnValueOnce({ data: [], error: undefined, mutate: vi.fn() }) // sessions + .mockImplementation(() => ({ + data: { MovieCount: 1, SeriesCount: 2, EpisodeCount: 3, SongCount: 4, AlbumCount: 5 }, + error: undefined, + })); + + renderWithProviders( + , + ); + }); });