test(web): assert partial-create passes fieldsError state to the edit route

This commit is contained in:
2026-06-04 00:50:43 +02:00
parent 30d851182e
commit 22b37c138b
+9 -3
View File
@@ -2,17 +2,23 @@ import { expect, test } from "vitest";
import { screen, waitFor } from "@testing-library/react"; import { screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event"; import userEvent from "@testing-library/user-event";
import { http, HttpResponse } from "msw"; import { http, HttpResponse } from "msw";
import { Routes, Route } from "react-router-dom"; import { Routes, Route, useLocation } from "react-router-dom";
import { server } from "../test/server"; import { server } from "../test/server";
import { renderApp } from "../test/render"; import { renderApp } from "../test/render";
import { ObjectNewPage } from "./object-new-page"; import { ObjectNewPage } from "./object-new-page";
function EditStub() {
const location = useLocation();
const flagged = (location.state as { fieldsError?: boolean } | null)?.fieldsError === true;
return <div>edit page{flagged ? " (fields error)" : ""}</div>;
}
function tree() { function tree() {
return ( return (
<Routes> <Routes>
<Route path="/objects/new" element={<ObjectNewPage />} /> <Route path="/objects/new" element={<ObjectNewPage />} />
<Route path="/objects/:id" element={<div>detail view</div>} /> <Route path="/objects/:id" element={<div>detail view</div>} />
<Route path="/objects/:id/edit" element={<div>edit page</div>} /> <Route path="/objects/:id/edit" element={<EditStub />} />
</Routes> </Routes>
); );
} }
@@ -61,5 +67,5 @@ test("partial create: fields PUT fails -> navigate to edit with an error banner"
await userEvent.type(screen.getByLabelText(/inscription/i), "x"); await userEvent.type(screen.getByLabelText(/inscription/i), "x");
await userEvent.click(screen.getByRole("button", { name: /create object/i })); await userEvent.click(screen.getByRole("button", { name: /create object/i }));
await waitFor(() => expect(screen.getByText("edit page")).toBeInTheDocument()); await waitFor(() => expect(screen.getByText(/edit page \(fields error\)/i)).toBeInTheDocument());
}); });