fix(web): vocab form-level error states, newVocabulary heading, id guard, EN-required test
This commit is contained in:
@@ -51,3 +51,18 @@ test("selecting a vocabulary shows its terms and adds one", async () => {
|
|||||||
expect((termBody as { labels: { label: string }[] })?.labels[0].label).toBe("Stone"),
|
expect((termBody as { labels: { label: string }[] })?.labels[0].label).toBe("Stone"),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("add term without EN label shows required alert and does not POST", async () => {
|
||||||
|
let posted = false;
|
||||||
|
server.use(
|
||||||
|
http.post("/api/admin/vocabularies/:id/terms", () => {
|
||||||
|
posted = true;
|
||||||
|
return HttpResponse.json({ id: "t-x" }, { status: 201 });
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
renderApp(tree(), { route: "/vocabularies/v-material" });
|
||||||
|
expect(await screen.findByText("Bronze")).toBeInTheDocument();
|
||||||
|
await userEvent.click(screen.getByRole("button", { name: /add term/i }));
|
||||||
|
expect(screen.getByRole("alert")).toBeInTheDocument();
|
||||||
|
expect(posted).toBe(false);
|
||||||
|
});
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export function VocabularyList() {
|
|||||||
return (
|
return (
|
||||||
<div className="flex h-full flex-col">
|
<div className="flex h-full flex-col">
|
||||||
<form onSubmit={onCreate} className="space-y-1 border-b p-3">
|
<form onSubmit={onCreate} className="space-y-1 border-b p-3">
|
||||||
|
<div className="text-sm font-medium">{t("vocab.newVocabulary")}</div>
|
||||||
<Label htmlFor="vocab-key">{t("vocab.key")}</Label>
|
<Label htmlFor="vocab-key">{t("vocab.key")}</Label>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<Input
|
<Input
|
||||||
@@ -38,6 +39,11 @@ export function VocabularyList() {
|
|||||||
{t("vocab.create")}
|
{t("vocab.create")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
{create.isError && (
|
||||||
|
<p role="alert" className="text-xs text-red-600">
|
||||||
|
{t("form.rejected")}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
</form>
|
</form>
|
||||||
<ul className="flex-1 overflow-auto">
|
<ul className="flex-1 overflow-auto">
|
||||||
{isLoading && (
|
{isLoading && (
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ export function VocabularyTerms() {
|
|||||||
|
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState(false);
|
||||||
|
|
||||||
|
if (!id) return null;
|
||||||
|
|
||||||
const onAdd = (event: FormEvent) => {
|
const onAdd = (event: FormEvent) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
@@ -49,7 +51,7 @@ export function VocabularyTerms() {
|
|||||||
setError(false);
|
setError(false);
|
||||||
|
|
||||||
addTerm.mutate(
|
addTerm.mutate(
|
||||||
{ vocabularyId: id!, external_uri: uri.trim() || null, labels },
|
{ vocabularyId: id, external_uri: uri.trim() || null, labels },
|
||||||
{ onSuccess: () => { setLabels([]); setUri(""); } },
|
{ onSuccess: () => { setLabels([]); setUri(""); } },
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -85,6 +87,11 @@ export function VocabularyTerms() {
|
|||||||
{t("form.required")}
|
{t("form.required")}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
{addTerm.isError && (
|
||||||
|
<p role="alert" className="text-xs text-red-600">
|
||||||
|
{t("form.rejected")}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
<Button type="submit" size="sm" disabled={addTerm.isPending}>
|
<Button type="submit" size="sm" disabled={addTerm.isPending}>
|
||||||
{t("vocab.addTerm")}
|
{t("vocab.addTerm")}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user