feat(web): field-form selects use ui/Select; rewrite select tests (#51)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-08 06:03:54 +02:00
parent 71d899cbdc
commit ede32551be
2 changed files with 57 additions and 41 deletions
+37 -26
View File
@@ -12,6 +12,13 @@ import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Checkbox } from "@/components/ui/checkbox";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
type LabelInput = components["schemas"]["LabelInput"];
type FieldDefinitionView = components["schemas"]["FieldDefinitionView"];
@@ -117,58 +124,62 @@ export function FieldForm({
<div className="space-y-1">
<Label htmlFor="field-type">{t("fields.type")}</Label>
<select
id="field-type"
value={dataType}
disabled={isEdit}
onChange={(e) => setDataType(e.target.value)}
className="w-full rounded-md border px-2 py-1 text-sm disabled:opacity-60"
>
<Select value={dataType} onValueChange={(v) => setDataType(v ?? "")} disabled={isEdit}>
<SelectTrigger id="field-type">
<SelectValue />
</SelectTrigger>
<SelectContent>
{TYPES.map((type) => (
<option key={type} value={type}>
<SelectItem key={type} value={type}>
{t(`fields.types.${type}`)}
</option>
</SelectItem>
))}
</select>
</SelectContent>
</Select>
</div>
{dataType === "term" && (
<div className="space-y-1">
<Label htmlFor="field-vocab">{t("fields.vocabulary")}</Label>
<select
id="field-vocab"
<Select
value={vocabularyId}
onValueChange={(v) => setVocabularyId(v ?? "")}
disabled={isEdit}
onChange={(e) => setVocabularyId(e.target.value)}
className="w-full rounded-md border px-2 py-1 text-sm disabled:opacity-60"
>
<option value="">{t("form.selectPlaceholder")}</option>
<SelectTrigger id="field-vocab">
<SelectValue placeholder={t("form.selectPlaceholder")} />
</SelectTrigger>
<SelectContent>
{vocabularies?.map((vocab) => (
<option key={vocab.id} value={vocab.id}>
<SelectItem key={vocab.id} value={vocab.id}>
{vocab.key}
</option>
</SelectItem>
))}
</select>
</SelectContent>
</Select>
</div>
)}
{dataType === "authority" && (
<div className="space-y-1">
<Label htmlFor="field-kind">{t("fields.authorityKind")}</Label>
<select
id="field-kind"
<Select
value={authorityKind}
onValueChange={(v) => setAuthorityKind(v ?? "")}
disabled={isEdit}
onChange={(e) => setAuthorityKind(e.target.value)}
className="w-full rounded-md border px-2 py-1 text-sm disabled:opacity-60"
>
<option value="">{t("fields.anyKind")}</option>
<SelectTrigger id="field-kind">
<SelectValue placeholder={t("fields.anyKind")} />
</SelectTrigger>
<SelectContent>
<SelectItem value="">{t("fields.anyKind")}</SelectItem>
{KINDS.map((kind) => (
<option key={kind} value={kind}>
<SelectItem key={kind} value={kind}>
{t(`authorities.${kind}`)}
</option>
</SelectItem>
))}
</select>
</SelectContent>
</Select>
</div>
)}
+11 -6
View File
@@ -1,5 +1,5 @@
import { expect, test } from "vitest";
import { screen, waitFor } from "@testing-library/react";
import { screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { http, HttpResponse } from "msw";
import { Route, Routes } from "react-router-dom";
@@ -16,6 +16,11 @@ function tree() {
);
}
async function choose(triggerName: RegExp, optionName: RegExp) {
await userEvent.click(screen.getByRole("combobox", { name: triggerName }));
await userEvent.click(await within(document.body).findByRole("option", { name: optionName }));
}
test("lists field definitions grouped, with an Other heading for ungrouped", async () => {
renderApp(tree(), { route: "/fields" });
expect(await screen.findByText("Inscription")).toBeInTheDocument();
@@ -56,9 +61,9 @@ test("selecting Authority reveals the kind picker and posts the chosen kind", as
await userEvent.type(screen.getByLabelText(/^key$/i), "maker");
await userEvent.type(screen.getByLabelText(/^label$/i), "Maker");
await userEvent.selectOptions(screen.getByLabelText(/^type$/i), "authority");
const kind = await screen.findByLabelText(/authority kind/i);
await userEvent.selectOptions(kind, "person");
await choose(/^type$/i, /^authority$/i);
await screen.findByLabelText(/authority kind/i);
await choose(/authority kind/i, /^person$/i);
await userEvent.click(screen.getByRole("button", { name: /create field/i }));
await waitFor(() => expect(body?.authority_kind).toBe("person"));
@@ -77,7 +82,7 @@ test("selecting Term reveals the vocabulary picker and blocks submit until chose
await userEvent.type(screen.getByLabelText(/^key$/i), "material");
await userEvent.type(screen.getByLabelText(/^label$/i), "Material");
await userEvent.selectOptions(screen.getByLabelText(/^type$/i), "term");
await choose(/^type$/i, /^term$/i);
const vocab = await screen.findByLabelText(/^vocabulary$/i);
@@ -87,7 +92,7 @@ test("selecting Term reveals the vocabulary picker and blocks submit until chose
expect(await screen.findByRole("alert")).toBeInTheDocument();
expect(posted).toBe(false);
await userEvent.selectOptions(vocab, "v-material");
await choose(/^vocabulary$/i, /^material$/i);
await userEvent.click(screen.getByRole("button", { name: /create field/i }));
await waitFor(() => expect(posted).toBe(true));
});