import { MantineProvider } from "@mantine/core"; import { render, screen, within } from "@testing-library/react"; import { MemoryRouter } from "react-router"; import { describe, expect, it } from "vitest"; import { resource } from "@/test/resource"; import { brokerageAccountCards } from "../../model/display"; import { BrokerageAccountList } from "./BrokerageAccountList"; describe("BrokerageAccountList", () => { it("renders account details and an account link", () => { render( , ); expect(screen.getByRole("link", { name: /Основной/ })).toHaveAttribute( "href", "/accounts/account-1", ); expect(screen.getAllByText("Брокерский счет")).toHaveLength(3); expect(screen.getByText(/^Открыт /)).toBeInTheDocument(); expect(screen.getByText("1 500 ₽")).toBeInTheDocument(); expect(screen.getByText("20 USD")).toBeInTheDocument(); expect(screen.getByText("Еще 1 валюта")).toBeInTheDocument(); expect(screen.getByText("Сводка временно недоступна")).toBeInTheDocument(); expect(screen.getByText("Нет текущих сумм")).toBeInTheDocument(); expect(screen.getAllByText("Открыть счет")).toHaveLength(3); const available = within(screen.getByRole("link", { name: /Основной/ })); expect(available.getAllByRole("definition")[0]).toHaveTextContent("5"); expect(available.getAllByRole("definition")[1]).toHaveTextContent("12"); const unvalued = within(screen.getByRole("link", { name: /Пустой/ })); expect(unvalued.getAllByRole("definition")[0]).toHaveTextContent("2"); expect(unvalued.getAllByRole("definition")[1]).toHaveTextContent("0"); expect( within(screen.getByRole("link", { name: /Недоступный/ })).queryByText( "Акции", ), ).not.toBeInTheDocument(); }); }); it("shows portfolio summary freshness independently for each account", () => { const accounts = brokerageAccountCards( ["fresh", "stale"].map( id => ({ id, name: id, openedOn: null, portfolioSummary: { bondPositionCount: 0, stockPositionCount: 1, totalsByCurrency: [{ currency: "RUB", value: "10" }], }, type: "BROKERAGE" as const, }), ), [ resource(null, { freshness: "fresh", resourceKey: "portfolio/fresh" }) .meta, resource(null, { freshness: "stale", resourceKey: "portfolio/stale" }) .meta, ], ); render( , ); expect( within(screen.getByRole("link", { name: /stale/ })).getByText( "Данные требуют обновления", ), ).toBeVisible(); expect( within(screen.getByRole("link", { name: /fresh/ })).queryByText( "Данные требуют обновления", ), ).not.toBeInTheDocument(); });