Skip to content

Commit 33cf057

Browse files
committed
refactor(referents): remove name filter from admin and public search (#3281)
Drop the "Nom du référent" text input from both /admin/liste-referents and /referents. Only Région + Département filters remain. Strip the `query` field from the shared form, schemas, tRPC procedures (and their ilike filter), unit tests, and E2E tests. Expose the shared ReferentsSearchForm from the referents barrel.
1 parent 97d644f commit 33cf057

18 files changed

Lines changed: 25 additions & 126 deletions

packages/app/src/e2e/public-referents.e2e.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,32 +84,12 @@ test.describe("public referents search", () => {
8484
}
8585
});
8686

87-
test("search by name filters the results", async ({ browser }) => {
87+
test("name-search input is not exposed", async ({ browser }) => {
8888
const anonCtx = await browser.newContext({ storageState: undefined });
8989
try {
9090
const page = await anonCtx.newPage();
9191
await page.goto("/referents");
92-
await page.getByLabel("Nom du référent").fill("Rennes");
93-
await page.getByRole("button", { name: /^rechercher$/i }).click();
94-
95-
await expect(page.getByText("E2E Référent Rennes")).toBeVisible();
96-
await expect(page.getByText("E2E Référent Paris")).not.toBeVisible();
97-
} finally {
98-
await anonCtx.close();
99-
}
100-
});
101-
102-
test("search with no matches shows the empty state", async ({ browser }) => {
103-
const anonCtx = await browser.newContext({ storageState: undefined });
104-
try {
105-
const page = await anonCtx.newPage();
106-
await page.goto("/referents");
107-
await page
108-
.getByLabel("Nom du référent")
109-
.fill("ZZZZ-nonexistent-name-XXX");
110-
await page.getByRole("button", { name: /^rechercher$/i }).click();
111-
112-
await expect(page.getByText(/aucun référent/i)).toBeVisible();
92+
await expect(page.getByLabel("Nom du référent")).toHaveCount(0);
11393
} finally {
11494
await anonCtx.close();
11595
}

packages/app/src/modules/admin/referents/AdminReferentsPage.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ function ReferentsContent() {
113113
} = useImportModal();
114114

115115
const input = {
116-
query: searchParams.get("query") ?? undefined,
117116
region: (searchParams.get("region") as RegionCode) || undefined,
118117
county: (searchParams.get("county") as CountyCode) || undefined,
119118
page: Number(searchParams.get("page") ?? "1"),

packages/app/src/modules/admin/referents/SearchForm.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { ReferentsSearchForm } from "~/modules/referents/shared/ReferentsSearchForm";
3+
import { ReferentsSearchForm } from "~/modules/referents";
44

55
import { searchReferentsFormSchema } from "./schemas";
66

@@ -11,7 +11,6 @@ export function SearchForm() {
1111
emptyCountyLabel="Tous"
1212
emptyRegionLabel="Toutes"
1313
fieldPrefix="search"
14-
order="query-first"
1514
schema={searchReferentsFormSchema}
1615
/>
1716
);

packages/app/src/modules/admin/referents/__tests__/SearchForm.test.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,24 @@ describe("SearchForm", () => {
3737

3838
it("pushes a URL with the submitted filters on search", async () => {
3939
render(<SearchForm />);
40-
fireEvent.input(screen.getByLabelText("Nom du référent"), {
41-
target: { value: "Jean" },
42-
});
4340
fireEvent.change(screen.getByLabelText("Région"), {
4441
target: { value: "11" },
4542
});
4643
fireEvent.click(screen.getByRole("button", { name: "Rechercher" }));
4744

4845
await waitFor(() => {
4946
expect(routerPush).toHaveBeenCalledWith(
50-
expect.stringMatching(/\/admin\/liste-referents\?.*query=Jean/),
47+
expect.stringMatching(/\/admin\/liste-referents\?.*region=11/),
5148
);
5249
});
53-
expect(routerPush).toHaveBeenCalledWith(expect.stringMatching(/region=11/));
5450
expect(routerPush).toHaveBeenCalledWith(expect.stringMatching(/page=1/));
5551
});
5652

53+
it("does not render a name-search input", () => {
54+
render(<SearchForm />);
55+
expect(screen.queryByLabelText(/nom du référent/i)).toBeNull();
56+
});
57+
5758
it("resets and pushes the base URL on Réinitialiser", () => {
5859
render(<SearchForm />);
5960
fireEvent.click(screen.getByRole("button", { name: "Réinitialiser" }));

packages/app/src/modules/admin/referents/__tests__/schemas.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ describe("searchReferentsSchema", () => {
2222

2323
it("parses all fields", () => {
2424
const result = searchReferentsSchema.parse({
25-
query: "Dupont",
2625
region: "11",
2726
county: "75",
2827
page: "2",
@@ -31,7 +30,6 @@ describe("searchReferentsSchema", () => {
3130
sortOrder: "desc",
3231
});
3332
expect(result).toEqual({
34-
query: "Dupont",
3533
region: "11",
3634
county: "75",
3735
page: 2,

packages/app/src/modules/admin/referents/schemas.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export type SortColumn = (typeof SORT_COLUMNS)[number];
1616
export const DEFAULT_PAGE_SIZE = 20;
1717

1818
export const searchReferentsSchema = z.object({
19-
query: z.string().optional(),
2019
region: z.enum(REGION_CODES).optional().or(z.literal("")),
2120
county: z.enum(COUNTY_CODES).optional().or(z.literal("")),
2221
page: z.coerce.number().int().min(1).default(1),
@@ -29,7 +28,6 @@ export type SearchReferentsInput = z.input<typeof searchReferentsSchema>;
2928
export type SearchReferentsOutput = z.output<typeof searchReferentsSchema>;
3029

3130
export const searchReferentsFormSchema = z.object({
32-
query: z.string().optional(),
3331
region: z.string().optional(),
3432
county: z.string().optional(),
3533
});

packages/app/src/modules/referents/PublicReferentsPage.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ function ReferentsContent() {
1717
const searchParams = useSearchParams();
1818

1919
const input = {
20-
query: searchParams.get("query") ?? undefined,
2120
region: (searchParams.get("region") as RegionCode) || undefined,
2221
county: (searchParams.get("county") as CountyCode) || undefined,
2322
page: Number(searchParams.get("page") ?? "1"),

packages/app/src/modules/referents/PublicReferentsSearchForm.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export function PublicReferentsSearchForm() {
88
<ReferentsSearchForm
99
basePath="/referents"
1010
fieldPrefix="referents"
11-
queryPlaceholder="Ex : Durand"
12-
queryType="search"
1311
schema={publicSearchReferentsFormSchema}
1412
wrapFieldsInFieldset
1513
/>

packages/app/src/modules/referents/__tests__/PublicReferentsSearchForm.test.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ describe("PublicReferentsSearchForm", () => {
1717
mockPush.mockClear();
1818
});
1919

20-
it("renders region, county and name inputs", () => {
20+
it("renders region and county selects only", () => {
2121
render(<PublicReferentsSearchForm />);
2222
expect(screen.getByLabelText(/région/i)).toBeInTheDocument();
2323
expect(screen.getByLabelText(/département/i)).toBeInTheDocument();
24-
expect(screen.getByLabelText(/nom du référent/i)).toBeInTheDocument();
24+
expect(screen.queryByLabelText(/nom du référent/i)).toBeNull();
2525
});
2626

2727
it("disables the county select until a region is chosen", () => {
@@ -49,19 +49,13 @@ describe("PublicReferentsSearchForm", () => {
4949
fireEvent.change(screen.getByLabelText(/région/i), {
5050
target: { value: "11" },
5151
});
52-
fireEvent.input(screen.getByLabelText(/nom du référent/i), {
53-
target: { value: "durand" },
54-
});
5552
fireEvent.click(screen.getByRole("button", { name: /^rechercher$/i }));
5653

5754
await waitFor(() => {
5855
expect(mockPush).toHaveBeenCalledWith(
5956
expect.stringMatching(/\/referents\?.*region=11/),
6057
);
6158
});
62-
expect(mockPush).toHaveBeenCalledWith(
63-
expect.stringMatching(/query=durand/),
64-
);
6559
expect(mockPush).toHaveBeenCalledWith(expect.stringMatching(/page=1/));
6660
});
6761

packages/app/src/modules/referents/__tests__/schemas.test.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ describe("publicSearchReferentsSchema", () => {
5454
it("rejects an unknown region code", () => {
5555
expect(() => publicSearchReferentsSchema.parse({ region: "99" })).toThrow();
5656
});
57-
58-
it("trims query whitespace", () => {
59-
const result = publicSearchReferentsSchema.parse({
60-
query: " durand ",
61-
});
62-
expect(result.query).toBe("durand");
63-
});
6457
});
6558

6659
describe("publicSearchReferentsFormSchema", () => {
@@ -71,11 +64,10 @@ describe("publicSearchReferentsFormSchema", () => {
7164

7265
it("accepts free-form strings (form-level, server re-validates)", () => {
7366
const result = publicSearchReferentsFormSchema.parse({
74-
query: "durand",
7567
region: "11",
7668
county: "75",
7769
});
78-
expect(result).toEqual({ query: "durand", region: "11", county: "75" });
70+
expect(result).toEqual({ region: "11", county: "75" });
7971
});
8072
});
8173

0 commit comments

Comments
 (0)