chore: finish frontend ESLint migration #18
Enable every plugin recommended preset and replace Biome with ESLint formatting. Preserve API contracts and JSX whitespace; verify source, tests, builds and tooling.
This commit is contained in:
@@ -7,55 +7,61 @@ import {
|
||||
waitFor,
|
||||
within,
|
||||
} from "@testing-library/react";
|
||||
import { HttpResponse, http } from "msw";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { MemoryRouter, Route, Routes } from "react-router";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { configureAuthClient } from "@/shared/api";
|
||||
import { createTestQueryClient } from "@/test/query";
|
||||
import { server } from "@/test/server";
|
||||
|
||||
import { CardPage } from "./CardPage";
|
||||
|
||||
const money = (value: string) => ({ currency: "RUB", value });
|
||||
const card = {
|
||||
id: "a",
|
||||
name: "Повседневная",
|
||||
bankName: null,
|
||||
lastFour: null,
|
||||
balance: money("10000"),
|
||||
openingBalance: money("10000"),
|
||||
openingDate: "2026-01-01",
|
||||
archivedAt: null,
|
||||
version: 1,
|
||||
};
|
||||
const operation = {
|
||||
id: "transfer",
|
||||
kind: "transfer",
|
||||
cardId: "a",
|
||||
cardName: "Повседневная",
|
||||
targetCardId: "b",
|
||||
targetCardName: "Запасная",
|
||||
categoryId: null,
|
||||
categoryName: null,
|
||||
originalExpenseId: null,
|
||||
amount: money("50.01"),
|
||||
availableRefund: null,
|
||||
date: "2026-08-03",
|
||||
description: null,
|
||||
version: 1,
|
||||
createdAt: "2026-08-03T00:00:00Z",
|
||||
};
|
||||
const card = (/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
|
||||
{
|
||||
archivedAt: null,
|
||||
balance: money("10000"),
|
||||
bankName: null,
|
||||
id: "a",
|
||||
lastFour: null,
|
||||
name: "Повседневная",
|
||||
openingBalance: money("10000"),
|
||||
openingDate: "2026-01-01",
|
||||
version: 1,
|
||||
}
|
||||
/* eslint-enable unicorn/no-null */);
|
||||
const operation = (/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
|
||||
{
|
||||
amount: money("50.01"),
|
||||
availableRefund: null,
|
||||
cardId: "a",
|
||||
cardName: "Повседневная",
|
||||
categoryId: null,
|
||||
categoryName: null,
|
||||
createdAt: "2026-08-03T00:00:00Z",
|
||||
date: "2026-08-03",
|
||||
description: null,
|
||||
id: "transfer",
|
||||
kind: "transfer",
|
||||
originalExpenseId: null,
|
||||
targetCardId: "b",
|
||||
targetCardName: "Запасная",
|
||||
version: 1,
|
||||
}
|
||||
/* eslint-enable unicorn/no-null */);
|
||||
function setup(
|
||||
options: {
|
||||
month?: string;
|
||||
missing?: boolean;
|
||||
summaryError?: boolean;
|
||||
cardsError?: boolean;
|
||||
missing?: boolean;
|
||||
month?: string;
|
||||
summaryError?: boolean;
|
||||
} = {},
|
||||
) {
|
||||
configureAuthClient({
|
||||
accessToken: () => "test",
|
||||
refresh: async () => false,
|
||||
clear: () => {},
|
||||
refresh: () => Promise.resolve(false),
|
||||
});
|
||||
const requests: string[] = [];
|
||||
const summaryRequests: string[] = [];
|
||||
@@ -73,6 +79,7 @@ function setup(
|
||||
http.get("*/api/v1/bank-cards/a/operations", ({ request }) => {
|
||||
requests.push(new URL(request.url).search);
|
||||
return HttpResponse.json({
|
||||
hasNext: Number(new URL(request.url).searchParams.get("page")) < 3,
|
||||
items: [
|
||||
{
|
||||
...operation,
|
||||
@@ -81,7 +88,6 @@ function setup(
|
||||
],
|
||||
page: Number(new URL(request.url).searchParams.get("page")),
|
||||
total: 30,
|
||||
hasNext: Number(new URL(request.url).searchParams.get("page")) < 3,
|
||||
});
|
||||
}),
|
||||
http.get("*/api/v1/bank-cards/summary", ({ request }) => {
|
||||
@@ -89,12 +95,12 @@ function setup(
|
||||
return options.summaryError
|
||||
? HttpResponse.error()
|
||||
: HttpResponse.json({
|
||||
month: "2026-08",
|
||||
cardId: "a",
|
||||
expenses: money("0"),
|
||||
refunds: money("50"),
|
||||
net: money("-50"),
|
||||
categories: [],
|
||||
expenses: money("0"),
|
||||
month: "2026-08",
|
||||
net: money("-50"),
|
||||
refunds: money("50"),
|
||||
});
|
||||
}),
|
||||
);
|
||||
@@ -106,13 +112,13 @@ function setup(
|
||||
initialEntries={[`/cards/a?month=${options.month ?? "2026-08"}`]}
|
||||
>
|
||||
<Routes>
|
||||
<Route path="/cards/:cardId" element={<CardPage />} />
|
||||
<Route element={<CardPage />} path="/cards/:cardId" />
|
||||
</Routes>
|
||||
</MemoryRouter>
|
||||
</MantineProvider>
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
return { requests, summaryRequests, client };
|
||||
return { client, requests, summaryRequests };
|
||||
}
|
||||
describe("CardPage", () => {
|
||||
it.each([
|
||||
@@ -145,10 +151,10 @@ describe("CardPage", () => {
|
||||
expect(screen.getByText("−50,01 ₽")).toBeInTheDocument();
|
||||
expect(await screen.findByText("-50,00 ₽")).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Назад" })).toBeDisabled();
|
||||
expect(requests.every((value) => value.includes("limit=10"))).toBe(true);
|
||||
expect(requests.every(value => value.includes("limit=10"))).toBe(true);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Далее" }));
|
||||
await waitFor(() =>
|
||||
expect(requests.some((v) => v.includes("page=2"))).toBe(true),
|
||||
expect(requests.some(v => v.includes("page=2"))).toBe(true),
|
||||
);
|
||||
const lastPage = await screen.findByRole("button", { name: "Страница 3" });
|
||||
await waitFor(() => expect(lastPage).toBeEnabled());
|
||||
@@ -170,10 +176,10 @@ describe("CardPage", () => {
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
requests.some(
|
||||
(v) =>
|
||||
v.includes("from=2026-08-10") &&
|
||||
v.includes("to=2026-08-20") &&
|
||||
v.includes("page=1"),
|
||||
v =>
|
||||
v.includes("from=2026-08-10")
|
||||
&& v.includes("to=2026-08-20")
|
||||
&& v.includes("page=1"),
|
||||
),
|
||||
).toBe(true),
|
||||
);
|
||||
@@ -187,7 +193,7 @@ describe("CardPage", () => {
|
||||
expect(screen.getByText(/10\s000 ₽/)).toBeInTheDocument();
|
||||
});
|
||||
it("keeps the journal in place while the next page loads", async () => {
|
||||
const scroll = vi.spyOn(window, "scrollBy").mockImplementation(() => {});
|
||||
const scroll = vi.spyOn(globalThis, "scrollBy").mockImplementation(() => {});
|
||||
setup();
|
||||
await screen.findByText("Перевод на «Запасная»");
|
||||
const navigation = screen.getByRole("navigation", {
|
||||
@@ -196,18 +202,16 @@ describe("CardPage", () => {
|
||||
const measure = vi
|
||||
.spyOn(navigation, "getBoundingClientRect")
|
||||
.mockReturnValue({ top: 600 } as DOMRect);
|
||||
let release = () => {};
|
||||
const pending = new Promise<void>((resolve) => {
|
||||
release = resolve;
|
||||
});
|
||||
|
||||
const { promise: pending, resolve: release } = Promise.withResolvers<void>();
|
||||
server.use(
|
||||
http.get("*/api/v1/bank-cards/a/operations", async () => {
|
||||
await pending;
|
||||
return HttpResponse.json({
|
||||
items: [{ ...operation, id: "next", description: "Новая страница" }],
|
||||
hasNext: true,
|
||||
items: [{ ...operation, description: "Новая страница", id: "next" }],
|
||||
page: 2,
|
||||
total: 30,
|
||||
hasNext: true,
|
||||
});
|
||||
}),
|
||||
);
|
||||
@@ -224,11 +228,12 @@ describe("CardPage", () => {
|
||||
measure.mockReturnValue({ top: 200 } as DOMRect);
|
||||
release();
|
||||
await screen.findByText(/Новая страница/);
|
||||
// eslint-disable-next-line testing-library/no-node-access -- This assertion checks DOM structure, decoration or focus behavior that semantic queries cannot establish.
|
||||
const list = screen.getByText(/Новая страница/).closest("[aria-busy]");
|
||||
expect(list?.parentElement?.style.minHeight).toBe("");
|
||||
expect(scroll).toHaveBeenCalledExactlyOnceWith({
|
||||
top: -400,
|
||||
behavior: "instant",
|
||||
top: -400,
|
||||
});
|
||||
measure.mockRestore();
|
||||
scroll.mockRestore();
|
||||
@@ -250,8 +255,8 @@ describe("CardPage", () => {
|
||||
fireEvent.click(await screen.findByRole("option", { name: "20" }));
|
||||
await waitFor(() => {
|
||||
expect(requests.at(-1)).toContain("limit=20");
|
||||
expect(requests.at(-1)).toContain("page=1");
|
||||
});
|
||||
expect(requests.at(-1)).toContain("page=1"); ;
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole("button", { name: "Страница 1" })).toBeEnabled(),
|
||||
);
|
||||
@@ -313,15 +318,17 @@ describe("CardPage", () => {
|
||||
),
|
||||
http.patch("*/api/v1/bank-cards/a", async ({ request }) => {
|
||||
const body = (await request.json()) as {
|
||||
version: number;
|
||||
archived: boolean;
|
||||
version: number;
|
||||
};
|
||||
bodies.push(body);
|
||||
current = {
|
||||
...current,
|
||||
version: current.version + 1,
|
||||
archivedAt: body.archived ? "2026-09-01" : null,
|
||||
} as typeof card;
|
||||
current = (/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
|
||||
{
|
||||
...current,
|
||||
archivedAt: body.archived ? "2026-09-01" : null,
|
||||
version: current.version + 1,
|
||||
}
|
||||
/* eslint-enable unicorn/no-null */) as typeof card;
|
||||
return HttpResponse.json(current);
|
||||
}),
|
||||
);
|
||||
@@ -338,8 +345,8 @@ describe("CardPage", () => {
|
||||
screen.getByRole("button", { name: "Добавить операцию" }),
|
||||
).toBeEnabled();
|
||||
expect(bodies).toEqual([
|
||||
{ version: 1, archived: true },
|
||||
{ version: 2, archived: false },
|
||||
{ archived: true, version: 1 },
|
||||
{ archived: false, version: 2 },
|
||||
]);
|
||||
});
|
||||
it("recovers the prerequisite card list while preserving the visible balance and journal", async () => {
|
||||
|
||||
Reference in New Issue
Block a user