feat(web): dynamic FieldInput (text/integer/date/boolean/localized_text/term/authority)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { expect, test } from "vitest";
|
||||
import { screen } from "@testing-library/react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { renderApp } from "../test/render";
|
||||
import { FieldInput } from "./field-input";
|
||||
import { fieldDefinitions } from "../test/fixtures";
|
||||
|
||||
function Harness({ defKey }: { defKey: string }) {
|
||||
const def = fieldDefinitions.find((d) => d.key === defKey)!;
|
||||
const form = useForm({ defaultValues: { fields: {} as Record<string, unknown> } });
|
||||
|
||||
return <FieldInput definition={def} form={form} />;
|
||||
}
|
||||
|
||||
test("text field renders a text input labelled in the active locale", async () => {
|
||||
renderApp(<Harness defKey="inscription" />);
|
||||
expect(await screen.findByLabelText("Inscription")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("boolean field renders a checkbox", async () => {
|
||||
renderApp(<Harness defKey="is_fragment" />);
|
||||
expect(await screen.findByRole("checkbox", { name: /is fragment/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("localized_text renders sv and en inputs", async () => {
|
||||
renderApp(<Harness defKey="title_ml" />);
|
||||
expect(await screen.findByLabelText(/title.*\(en\)/i)).toBeInTheDocument();
|
||||
expect(screen.getByLabelText(/title.*\(sv\)/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("term field renders a select populated from the vocabulary", async () => {
|
||||
renderApp(<Harness defKey="material" />);
|
||||
expect(await screen.findByText("Bronze")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("authority field renders a select populated by kind", async () => {
|
||||
renderApp(<Harness defKey="maker" />);
|
||||
expect(await screen.findByText("Ada Lovelace")).toBeInTheDocument();
|
||||
});
|
||||
Reference in New Issue
Block a user