mirror of
https://github.com/gethomepage/homepage.git
synced 2026-05-18 19:40:58 +08:00
Some checks failed
Crowdin Action / Crowdin Sync (push) Has been cancelled
Docker CI / Linting Checks (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
Repository Maintenance / Stale (push) Has been cancelled
Repository Maintenance / Lock Old Threads (push) Has been cancelled
Repository Maintenance / Close Answered Discussions (push) Has been cancelled
Repository Maintenance / Close Outdated Discussions (push) Has been cancelled
Repository Maintenance / Close Unsupported Feature Requests (push) Has been cancelled
52 lines
2.0 KiB
JavaScript
52 lines
2.0 KiB
JavaScript
// @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";
|
|
import { expectBlockValue } from "test-utils/widget-assertions";
|
|
|
|
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
|
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
|
|
|
import Component from "./component";
|
|
|
|
describe("widgets/mealie/component", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("uses v1 endpoint by default and renders placeholders while loading", () => {
|
|
useWidgetAPI.mockReturnValue({ data: undefined, error: undefined });
|
|
|
|
const { container } = renderWithProviders(<Component service={{ widget: { type: "mealie", url: "http://x" } }} />, {
|
|
settings: { hideErrors: false },
|
|
});
|
|
|
|
expect(useWidgetAPI.mock.calls[0][1]).toBe("statisticsv1");
|
|
expect(container.querySelectorAll(".service-block")).toHaveLength(4);
|
|
expect(screen.getByText("mealie.recipes")).toBeInTheDocument();
|
|
expect(screen.getByText("mealie.users")).toBeInTheDocument();
|
|
expect(screen.getByText("mealie.categories")).toBeInTheDocument();
|
|
expect(screen.getByText("mealie.tags")).toBeInTheDocument();
|
|
});
|
|
|
|
it("uses v2 endpoint when widget.version === 2 and renders counts", () => {
|
|
useWidgetAPI.mockReturnValue({
|
|
data: { totalRecipes: 1, totalUsers: 2, totalCategories: 3, totalTags: 4 },
|
|
error: undefined,
|
|
});
|
|
|
|
const { container } = renderWithProviders(
|
|
<Component service={{ widget: { type: "mealie", url: "http://x", version: 2 } }} />,
|
|
{ settings: { hideErrors: false } },
|
|
);
|
|
|
|
expect(useWidgetAPI.mock.calls[0][1]).toBe("statisticsv2");
|
|
expectBlockValue(container, "mealie.recipes", 1);
|
|
expectBlockValue(container, "mealie.users", 2);
|
|
expectBlockValue(container, "mealie.categories", 3);
|
|
expectBlockValue(container, "mealie.tags", 4);
|
|
});
|
|
});
|