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
+43
View File
@@ -0,0 +1,43 @@
// @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/stocks/component", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("renders invalid configuration message when watchlist is empty", () => {
useWidgetAPI.mockReturnValue({ data: undefined, error: undefined });
renderWithProviders(<Component service={{ widget: { type: "stocks", watchlist: [] } }} />, {
settings: { hideErrors: false },
});
expect(screen.getByText("stocks.invalidConfiguration")).toBeInTheDocument();
});
it("renders stock items for a valid watchlist", () => {
useWidgetAPI.mockImplementation((_widget, endpoint) => {
if (endpoint === "quote") return { data: { dp: 1.23, c: 100 }, error: undefined };
if (endpoint === "status") return { data: { isOpen: true }, error: undefined };
return { data: undefined, error: undefined };
});
renderWithProviders(
<Component service={{ widget: { type: "stocks", watchlist: ["AAPL"], showUSMarketStatus: true } }} />,
{ settings: { hideErrors: false } },
);
expect(screen.getByText("AAPL")).toBeInTheDocument();
expect(screen.getByText("1.23%")).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("stocks widget config", () => {
it("exports a valid widget config", () => {
expectWidgetConfigShape(widget);
});
});