Chore: homepage tests (#6278)

This commit is contained in:
shamoon
2026-02-04 19:58:39 -08:00
committed by GitHub
parent 7d019185a3
commit 872a3600aa
558 changed files with 32606 additions and 84 deletions
@@ -0,0 +1,44 @@
// @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";
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
import Component from "./component";
describe("widgets/develancacheui/component", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("renders placeholders while loading", () => {
useWidgetAPI.mockReturnValue({ data: undefined, error: undefined });
const { container } = renderWithProviders(<Component service={{ widget: { type: "develancacheui" } }} />, {
settings: { hideErrors: false },
});
expect(container.querySelectorAll(".service-block")).toHaveLength(2);
expect(screen.getByText("develancacheui.cachehitbytes")).toBeInTheDocument();
expect(screen.getByText("develancacheui.cachemissbytes")).toBeInTheDocument();
});
it("renders byte totals when loaded", () => {
useWidgetAPI.mockReturnValue({
data: { totalCacheHitBytes: 100, totalCacheMissBytes: 200 },
error: undefined,
});
renderWithProviders(<Component service={{ widget: { type: "develancacheui" } }} />, {
settings: { hideErrors: false },
});
expect(screen.getByText("100")).toBeInTheDocument();
expect(screen.getByText("200")).toBeInTheDocument();
});
});
+11
View File
@@ -0,0 +1,11 @@
import { describe, it } from "vitest";
import { expectWidgetConfigShape } from "test-utils/widget-config";
import widget from "./widget";
describe("develancacheui widget config", () => {
it("exports a valid widget config", () => {
expectWidgetConfigShape(widget);
});
});