refactor: simplify auth and instrument pages
Frontend verify / commits (pull_request) Successful in 24s
Frontend verify / security (pull_request) Failing after 9s
Frontend verify / verify (pull_request) Skipped

This commit is contained in:
2026-09-29 05:45:08 +03:00
parent 32a77860c8
commit b404c1802a
38 changed files with 644 additions and 790 deletions
+22 -7
View File
@@ -3,7 +3,7 @@ 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 { MemoryRouter } from "react-router";
import { type InitialEntry, MemoryRouter } from "react-router";
import { describe, expect, it } from "vitest";
import { AuthProvider } from "@/features/auth";
@@ -12,7 +12,7 @@ import { server } from "@/test/server";
import { AppRoutes } from "./AppRoutes";
function renderRoutes(path: string) {
function renderRoutes(path: InitialEntry) {
return render(
<QueryClientProvider client={createTestQueryClient()}>
<MemoryRouter initialEntries={[path]}>
@@ -57,10 +57,18 @@ describe("AppRoutes", () => {
).toBeInTheDocument();
});
it("logs in through the public form and reaches the protected landing", async () => {
it.each([
{ endpoint: "login", path: "/accounts", title: "Вход" },
{ endpoint: "register", path: "/register", title: "Регистрация" },
{
endpoint: "login",
path: { pathname: "/login", state: { returnTo: "//example.com" } },
title: "Вход",
},
])("authenticates via $endpoint and reaches the protected landing from $path", async ({ endpoint, path, title }) => {
let credentials: unknown;
server.use(
http.post("*/api/v1/auth/login", async ({ request }) => {
http.post(`*/api/v1/auth/${endpoint}`, async ({ request }) => {
credentials = await request.json();
return HttpResponse.json({
@@ -69,16 +77,23 @@ describe("AppRoutes", () => {
});
}),
);
renderRoutes("/accounts");
renderRoutes(path);
await screen.findByRole("heading", { level: 1, name: "Вход" });
await screen.findByRole("heading", { level: 1, name: title });
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: "Вход" }));
if (endpoint === "register") {
fireEvent.change(screen.getByLabelText("Подтвердите пароль"), {
target: { value: "a secure password" },
});
}
fireEvent.click(screen.getByRole("button", { name: title }));
expect(
await screen.findByRole("heading", {