refactor: clarify frontend module ownership
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
import { MantineProvider } from "@mantine/core";
|
||||
import { QueryClientProvider } from "@tanstack/react-query";
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { cssVariablesResolver, theme } from "@wealthledger/ui/theme";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { type InitialEntry, MemoryRouter } from "react-router";
|
||||
import { type InitialEntry, Link, MemoryRouter } from "react-router";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { AuthProvider } from "@/features/auth";
|
||||
@@ -12,10 +14,11 @@ import { server } from "@/test/server";
|
||||
|
||||
import { AppRoutes } from "./AppRoutes";
|
||||
|
||||
function renderRoutes(path: InitialEntry) {
|
||||
function renderRoutes(path: InitialEntry, controls?: ReactNode) {
|
||||
return render(
|
||||
<QueryClientProvider client={createTestQueryClient()}>
|
||||
<MemoryRouter initialEntries={[path]}>
|
||||
{controls}
|
||||
<MantineProvider
|
||||
cssVariablesResolver={cssVariablesResolver}
|
||||
theme={theme}
|
||||
@@ -110,6 +113,43 @@ describe("AppRoutes", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ isFailure: false, isNewDestination: false },
|
||||
{ isFailure: true, isNewDestination: false },
|
||||
{ isFailure: true, isNewDestination: true },
|
||||
])("finishes logout safely: failure=$isFailure, new destination=$isNewDestination", async ({ isFailure, isNewDestination }) => {
|
||||
const { promise: pendingLogout, resolve: finishLogout }
|
||||
= Promise.withResolvers<void>();
|
||||
|
||||
server.use(
|
||||
http.post("*/api/v1/auth/refresh", () => HttpResponse.json({
|
||||
accessToken: "test-token", user: { email: "user@example.com", id: "user-1" },
|
||||
})),
|
||||
http.post("*/api/v1/auth/logout", async () => {
|
||||
await pendingLogout;
|
||||
|
||||
return isFailure
|
||||
? HttpResponse.error()
|
||||
: new HttpResponse(null, { status: 204 });
|
||||
}),
|
||||
);
|
||||
renderRoutes("/settings", <Link to="/settings?source=manual">Открыть настройки</Link>);
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Выйти" }));
|
||||
await screen.findByRole("heading", { level: 1, name: "Вход" });
|
||||
if (isNewDestination) fireEvent.click(screen.getByRole("link", { 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: "Вход" }));
|
||||
finishLogout();
|
||||
|
||||
const destination = isNewDestination
|
||||
? { level: 1, name: "Настройки" }
|
||||
: { level: 2, name: "Нет инвестиционных счетов" };
|
||||
|
||||
expect(await screen.findByRole("heading", destination)).toBeInTheDocument();
|
||||
expect(document.title).toBe(isNewDestination ? "Настройки — WealthLedger" : "Счета — WealthLedger");
|
||||
});
|
||||
|
||||
it("returns after login to cards with the selected month without T-Bank", async () => {
|
||||
server.use(
|
||||
http.get("*/api/v1/bank-cards/categories", () => HttpResponse.json([])),
|
||||
|
||||
Reference in New Issue
Block a user