diff --git a/apps/web/src/components/Form/FormInput.test.tsx b/apps/web/src/components/Form/FormInput.test.tsx new file mode 100644 index 000000000..0ea2f5ede --- /dev/null +++ b/apps/web/src/components/Form/FormInput.test.tsx @@ -0,0 +1,94 @@ +import { PositionValidationSchema } from "@app/validation/config/position.ts"; +import { render, screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { useForm } from "react-hook-form"; +import { describe, expect, it } from "vitest"; +import { GenericInput, type InputFieldProps } from "./FormInput.tsx"; + +type LatitudeForm = { latitude: number | undefined }; + +/** + * Mirrors how Position.tsx uses the latitude field: an optional numeric value + * that starts out `undefined` when the node has no fixed position. The stored + * form value is echoed into a test-only node, since the bug in #1308 was about + * what the field committed, not only what it displayed. + */ +function Harness({ + properties, +}: { + properties: InputFieldProps["properties"]; +}) { + const { control, watch } = useForm({ + defaultValues: { latitude: undefined }, + }); + + return ( + <> + + control={control} + field={{ + type: "number", + name: "latitude", + label: "Latitude", + properties, + }} + /> + {String(watch("latitude"))} + + ); +} + +// Matches the real latitude/longitude field config in Position.tsx. +const latitudeProperties = { step: 0.0000001, fieldLength: { max: 12 } }; + +/** GenericInput renders no