52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import { render, screen } from "@testing-library/react";
|
||
import { it, expect, vi, beforeEach } from "vitest";
|
||
import type { Txn } from "@/api/schemas";
|
||
import { setHidden } from "@/ds/money";
|
||
|
||
const txns: Txn[] = [
|
||
{
|
||
date: "2026-08-20T09:00:00Z",
|
||
amount: "15000",
|
||
direction: "expense",
|
||
category: "Хоол",
|
||
title: "Кофе шоп",
|
||
accountId: 1,
|
||
txnId: 101,
|
||
},
|
||
{
|
||
date: "2026-08-20T08:00:00Z",
|
||
amount: "2500000",
|
||
direction: "income",
|
||
category: "Цалин",
|
||
title: "ХХК цалин",
|
||
accountId: 1,
|
||
txnId: 102,
|
||
salary: true,
|
||
},
|
||
];
|
||
|
||
vi.mock("@/api/hooks/reads", () => ({
|
||
useTransactions: () => ({ data: txns, isLoading: false }),
|
||
}));
|
||
|
||
import { TransactionList } from "./TransactionList";
|
||
|
||
beforeEach(() => {
|
||
setHidden(false);
|
||
});
|
||
|
||
it("renders transaction titles and formatted amounts, hiding salary rows by default", () => {
|
||
render(<TransactionList />);
|
||
|
||
// Non-salary row: title + a signed, grouped amount.
|
||
expect(screen.getByText("Кофе шоп")).toBeInTheDocument();
|
||
expect(screen.getByText("−15,000₮")).toBeInTheDocument();
|
||
|
||
// Salary row is filtered out of the row list by default...
|
||
expect(screen.queryByText("ХХК цалин")).not.toBeInTheDocument();
|
||
|
||
// ...but its amount still counts toward the income total (salary is
|
||
// included in totals per TransactionsModel.recompute, only excluded from
|
||
// the row list).
|
||
expect(screen.getByText("2,500,000₮")).toBeInTheDocument();
|
||
});
|