refactor: align frontend ownership boundaries
Close audit gaps across API drift, query policy, UI, and tests.
This commit is contained in:
@@ -1,25 +1,20 @@
|
||||
import { MantineProvider } from "@mantine/core";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { cleanup, render, screen, waitFor } from "@testing-library/react";
|
||||
import { QueryClientProvider } from "@tanstack/react-query";
|
||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { HttpResponse, http } from "msw";
|
||||
import { MemoryRouter } from "react-router";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { AuthProvider } from "@/features/auth";
|
||||
import {
|
||||
AccountsPageEmpty,
|
||||
AccountsPageError,
|
||||
AccountsPageLoading,
|
||||
} from "@/pages/accounts";
|
||||
import { createTestQueryClient } from "@/test/query";
|
||||
import { server } from "@/test/server";
|
||||
import { theme } from "../theme";
|
||||
import { AppRoutes } from "./AppRoutes";
|
||||
|
||||
describe("AppRoutes", () => {
|
||||
afterEach(cleanup);
|
||||
function renderRoutes(path: string) {
|
||||
return render(
|
||||
<QueryClientProvider client={new QueryClient()}>
|
||||
<QueryClientProvider client={createTestQueryClient()}>
|
||||
<MemoryRouter initialEntries={[path]}>
|
||||
<MantineProvider theme={theme}>
|
||||
<AuthProvider>
|
||||
@@ -50,37 +45,6 @@ describe("AppRoutes", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("renders the T-Bank settings action for a missing connection", () => {
|
||||
render(
|
||||
<MantineProvider theme={theme}>
|
||||
<MemoryRouter>
|
||||
<AccountsPageError code="TBANK_NOT_CONNECTED" />
|
||||
</MemoryRouter>
|
||||
</MantineProvider>,
|
||||
);
|
||||
|
||||
expect(
|
||||
screen.getByRole("link", { name: "Открыть настройки T-Bank" }),
|
||||
).toHaveAttribute("href", "/settings");
|
||||
});
|
||||
|
||||
it("renders retry and settings actions when T-Bank is unavailable", () => {
|
||||
const retry = vi.fn();
|
||||
render(
|
||||
<MantineProvider theme={theme}>
|
||||
<MemoryRouter>
|
||||
<AccountsPageError code="TBANK_UNAVAILABLE" retry={retry} />
|
||||
</MemoryRouter>
|
||||
</MantineProvider>,
|
||||
);
|
||||
|
||||
screen.getByRole("button", { name: "Повторить" }).click();
|
||||
expect(retry).toHaveBeenCalledOnce();
|
||||
expect(
|
||||
screen.getByRole("link", { name: "Открыть настройки T-Bank" }),
|
||||
).toHaveAttribute("href", "/settings");
|
||||
});
|
||||
|
||||
it("redirects anonymous users from accounts", async () => {
|
||||
renderRoutes("/accounts");
|
||||
|
||||
@@ -91,6 +55,40 @@ describe("AppRoutes", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("logs in through the public form and reaches the protected landing", async () => {
|
||||
let credentials: unknown;
|
||||
server.use(
|
||||
http.post("*/api/v1/auth/login", async ({ request }) => {
|
||||
credentials = await request.json();
|
||||
return HttpResponse.json({
|
||||
accessToken: "login-token",
|
||||
user: { id: "user-1", email: "user@example.com" },
|
||||
});
|
||||
}),
|
||||
);
|
||||
renderRoutes("/accounts");
|
||||
|
||||
await screen.findByRole("heading", { level: 1, name: "Вход" });
|
||||
fireEvent.change(screen.getByLabelText("Email"), {
|
||||
target: { value: " User@Example.com " },
|
||||
});
|
||||
fireEvent.change(screen.getByLabelText("Пароль"), {
|
||||
target: { value: "a secure password" },
|
||||
});
|
||||
fireEvent.click(screen.getByRole("button", { name: "Вход" }));
|
||||
|
||||
expect(
|
||||
await screen.findByRole("heading", {
|
||||
level: 2,
|
||||
name: "Нет инвестиционных счетов",
|
||||
}),
|
||||
).toBeInTheDocument();
|
||||
expect(credentials).toEqual({
|
||||
email: "user@example.com",
|
||||
password: "a secure password",
|
||||
});
|
||||
});
|
||||
|
||||
it("lazy-loads the protected shell for an authenticated accounts route", async () => {
|
||||
server.use(
|
||||
http.post("*/api/v1/auth/refresh", () =>
|
||||
@@ -114,37 +112,4 @@ describe("AppRoutes", () => {
|
||||
screen.getByRole("navigation", { name: "WealthLedger" }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it.each([
|
||||
["loading", AccountsPageLoading, "status"],
|
||||
["error", AccountsPageError, "alert"],
|
||||
["empty", AccountsPageEmpty, undefined],
|
||||
] as const)("renders only the Accounts %s state", (_name, State, role) => {
|
||||
render(
|
||||
<MantineProvider theme={theme}>
|
||||
<State />
|
||||
</MantineProvider>,
|
||||
);
|
||||
|
||||
if (role) {
|
||||
expect(screen.getByRole(role)).toBeInTheDocument();
|
||||
} else {
|
||||
expect(
|
||||
screen.getByRole("heading", {
|
||||
level: 2,
|
||||
name: "Нет инвестиционных счетов",
|
||||
}),
|
||||
).toBeInTheDocument();
|
||||
}
|
||||
|
||||
expect(screen.queryAllByRole("status")).toHaveLength(
|
||||
role === "status" ? 1 : 0,
|
||||
);
|
||||
expect(screen.queryAllByRole("alert")).toHaveLength(
|
||||
role === "alert" ? 1 : 0,
|
||||
);
|
||||
expect(screen.queryAllByText("Нет инвестиционных счетов")).toHaveLength(
|
||||
role ? 0 : 1,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user