import { composeStories } from "@storybook/react-vite"; import { cleanup, fireEvent, render, screen } from "@testing-library/react"; import { fn } from "storybook/test"; import { afterEach, describe, expect, it, vi } from "vitest"; import preview from "../../.storybook/preview"; import * as AccountStories from "../entities/brokerage-account/ui/BrokerageAccountList.stories"; import * as EventStories from "../entities/brokerage-event/ui/BrokerageEventsPreview.stories"; import * as LoadingStories from "../pages/account/ui/components/AccountPageLoading.stories"; import * as RefreshStories from "../pages/account/ui/components/PortfolioRefreshState.stories"; import * as PositionStories from "../pages/account/ui/components/PositionCard.stories"; import * as StateStories from "../shared/ui/StateView.stories"; afterEach(() => vi.restoreAllMocks()); describe("Storybook isolated product examples", () => { it("renders every fixture and runs callbacks without application network or browser data", () => { const spies = [ vi.spyOn(globalThis, "fetch"), vi.spyOn(XMLHttpRequest.prototype, "open"), vi.spyOn(Storage.prototype, "getItem"), vi.spyOn(Storage.prototype, "setItem"), vi.spyOn(Storage.prototype, "removeItem"), vi.spyOn(Document.prototype, "cookie", "get"), vi.spyOn(Document.prototype, "cookie", "set"), ]; const stories = [ ...Object.values(composeStories(AccountStories, preview)), ...Object.values(composeStories(LoadingStories, preview)), ...Object.values(composeStories(RefreshStories, preview)), ...Object.values(composeStories(PositionStories, preview)), ...Object.values(composeStories(EventStories, preview)), ...Object.values(composeStories(StateStories, preview)), ]; for (const Story of stories) { render(); for (const button of screen.queryAllByRole("button")) fireEvent.click(button); for (const link of screen.queryAllByRole("link")) fireEvent.click(link); for (const image of screen.queryAllByRole("img")) { expect(image).not.toHaveAttribute("src"); } cleanup(); } for (const spy of spies) expect(spy).not.toHaveBeenCalled(); }); it("keeps synthetic totals visible while the refresh example calls a local retry", () => { const { RefreshError } = composeStories(RefreshStories, preview); const retry = fn(); const view = render(); expect(screen.getByText(/125\s*000,50/)).toBeVisible(); fireEvent.click(screen.getByRole("button")); expect(retry).toHaveBeenCalledOnce(); view.rerender( , ); expect(screen.getByText(/125\s*000,50/)).toBeVisible(); expect(screen.getByRole("status")).toBeVisible(); }); });