52 lines
1.8 KiB
TypeScript
52 lines
1.8 KiB
TypeScript
import { MantineProvider } from "@mantine/core";
|
|
import { render, screen, within } from "@testing-library/react";
|
|
import { MemoryRouter } from "react-router";
|
|
import { assert, describe, expect, it } from "vitest";
|
|
|
|
import { toAccountPagePositionSections } from "../../model/positions";
|
|
import { portfolio, position, second } from "../../model/positions.fixtures";
|
|
import { PositionSection } from "./components/PositionSection.view";
|
|
|
|
describe("Positions grouped by security", () => {
|
|
it("shows one security with exact per-account quantities and valuations", () => {
|
|
const section = toAccountPagePositionSections({
|
|
...portfolio, positions: [position, second],
|
|
})[0];
|
|
|
|
assert.isDefined(section);
|
|
|
|
render(
|
|
<MantineProvider>
|
|
<MemoryRouter>
|
|
<PositionSection section={section} />
|
|
</MemoryRouter>
|
|
</MantineProvider>,
|
|
);
|
|
expect(screen.getAllByText("Сбербанк")).toHaveLength(1);
|
|
|
|
const rows = within(
|
|
screen.getByRole("list", { name: "Позиции по счетам" }),
|
|
).getAllByRole("listitem");
|
|
|
|
expect(rows).toHaveLength(2);
|
|
assert.isDefined(rows[0]);
|
|
assert.isDefined(rows[1]);
|
|
expect(
|
|
within(rows[0]).getByRole("link", { name: "Основной" }),
|
|
).toHaveAttribute("href", "/accounts/a");
|
|
expect(within(rows[0]).getByText("Количество: 1.25")).toBeInTheDocument();
|
|
expect(within(rows[0]).getByText("375 ₽")).toBeInTheDocument();
|
|
expect(within(rows[0]).getByText("+25 ₽ · +7,14 %"))
|
|
.toBeInTheDocument();
|
|
expect(
|
|
within(rows[0]).getByText("Средняя цена: 280 ₽"),
|
|
).toBeInTheDocument();
|
|
expect(within(rows[1]).getByRole("link", { name: "ИИС" })).toHaveAttribute(
|
|
"href",
|
|
"/accounts/b",
|
|
);
|
|
expect(within(rows[1]).getByText("Количество: -2")).toBeInTheDocument();
|
|
expect(rows[1]).not.toHaveTextContent("₽");
|
|
});
|
|
});
|