Fixhancement: handle linkwarden API change (#7018)
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:
shamoon
2026-08-19 10:25:24 -07:00
committed by GitHub
parent 9cabb46bb7
commit 3ab6b040b2
2 changed files with 23 additions and 1 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ export default function Component({ service }) {
// Some APIs return raw arrays, others wrap the payload (e.g. { response: [...] }).
const collections = collectionsStatsData?.response ?? collectionsStatsData;
const tags = tagsStatsData?.response ?? tagsStatsData;
const tags = tagsStatsData?.response ?? tagsStatsData?.data?.tags ?? tagsStatsData;
const totalLinks = Array.isArray(collections)
? collections.reduce((sum, collection) => sum + (collection._count?.links || 0), 0)
+22
View File
@@ -67,4 +67,26 @@ describe("widgets/linkwarden/component", () => {
expectBlockValue(container, "linkwarden.collections", 2);
expectBlockValue(container, "linkwarden.tags", 4);
});
it("computes the tags total from the nested Linkwarden API response", () => {
useWidgetAPI.mockImplementation((_widget, endpoint) => {
if (endpoint === "collections") {
return { data: { response: [{ _count: { links: 2 } }] }, error: undefined };
}
if (endpoint === "tags") {
return { data: { data: { tags: [{ id: 1 }, { id: 2 }, { id: 3 }] } }, error: undefined };
}
return { data: undefined, error: undefined };
});
const { container } = renderWithProviders(<Component service={{ widget: { type: "linkwarden" } }} />, {
settings: { hideErrors: false },
});
expectBlockValue(container, "linkwarden.links", 2);
expectBlockValue(container, "linkwarden.collections", 1);
expectBlockValue(container, "linkwarden.tags", 3);
});
});