feat: establish frontend foundation

This commit is contained in:
2026-08-12 23:04:16 +03:00
parent 3331b7f684
commit 1e13adabd3
46 changed files with 2868 additions and 1588 deletions
+81
View File
@@ -0,0 +1,81 @@
import { MantineProvider } from "@mantine/core";
import { cleanup, render, screen } from "@testing-library/react";
import { MemoryRouter } from "react-router";
import { afterEach, describe, expect, it } from "vitest";
import {
AccountsPageEmpty,
AccountsPageError,
AccountsPageLoading,
} from "../../pages/accounts";
import { theme } from "../theme";
import { AppRoutes } from "./AppRoutes";
describe("AppRoutes", () => {
afterEach(cleanup);
it.each([
["/", "Счета"],
["/login", "Вход"],
["/register", "Регистрация"],
["/accounts", "Счета"],
["/accounts/demo", "Счет"],
["/settings", "Настройки"],
["/unknown", "Страница не найдена"],
])("renders %s with its page title", (path, title) => {
render(
<MemoryRouter initialEntries={[path]}>
<MantineProvider theme={theme}>
<AppRoutes />
</MantineProvider>
</MemoryRouter>,
);
expect(
screen.getByRole("heading", { level: 1, name: title }),
).toBeInTheDocument();
});
it("renders only the empty state for accounts by default", () => {
render(
<MemoryRouter initialEntries={["/accounts"]}>
<MantineProvider theme={theme}>
<AppRoutes />
</MantineProvider>
</MemoryRouter>,
);
expect(
screen.getByRole("heading", { level: 2, name: "Пока ничего нет" }),
).toBeInTheDocument();
expect(screen.queryByText("Загрузка")).not.toBeInTheDocument();
expect(screen.queryByText("Что-то пошло не так")).not.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);
});
});