refactor: migrate remaining form components to new standard#3997
refactor: migrate remaining form components to new standard#3997
Conversation
Co-authored-by: gpaoloni <[email protected]>
|
@copilot fix the lint errors (and tests if any). This can be run from |
Co-authored-by: gpaoloni <[email protected]>
Fixed in 40178a1. The lint error was |
|
@copilot In a new PR, write unit tests for each input type (they are defined here ) that asserts the behavior. Follow the already existing test suiteplugin-hrm-form/src/components/forms/components/FormInput/FormInput.test.tsx as a guideline.
The goal of this new PR is to assert that behavior remains EXACTLY the same between the old and the new behavior. |
…ty tests Co-authored-by: gpaoloni <[email protected]>
Done in 317e6a9. Added unit tests for all 8 remaining input types, each with:
Tests cover: render accessibility, A few notes on what was discovered during testing:
|
Migrates all remaining
FormInputTypecomponents out of the deprecatedformGenerators.tsxand into the newplugin-hrm-form/src/components/forms/components/structure — each with a stateless*UIcomponent and a stateful wrapper that owns RHF bindings. Adds unit tests for each migrated component with parity tests against the oldgetInputTypeto assert behavioral equivalence.Description
New components
SearchInput/— search input with icon + visually-hidden accessible labelFormInput/NumericInput.tsx— reusesFormInputUI; overridesregisterOptions.patternwith/^[0-9]+$/gFormInput/Email.tsx— reusesFormInputUI; overridesregisterOptions.patternwith/\S+@\S+\.\S+/RadioInput/— radio group withdefaultOptionreset supportListboxMultiselect/— multi-select listbox with keyboard navigation (Arrow keys) and focus rovingMixedCheckbox/— three-state checkbox (true/false/'mixed') usingsetValuedirectlyDateInput/—DateInputandTimeInputshare a singleDateTimeInputUI(same structure, different styled component +typeattribute)FileUpload/— thin wrapper delegating to the existingUploadFileInputModified
FormInput/FormInput.tsx— exportsFormInputUIsoNumericInputandEmailcan reuse the UI without duplication (mirrors theFormSelectUIpattern)inputGenerator.tsx— addscasebranches for all 9 newly migrated types; removes thedefaultfallback togetInputType; removeseslint-disable sonarjs/no-small-switch(no longer needed)New tests
Each migrated component has a test file under its directory in
plugin-hrm-form/src/components/forms/components/, following the existingFormInput.test.tsxpattern:SearchInput/SearchInput.test.tsxFormInput/NumericInput.test.tsx— includes assertion thatregisteris called with the numericpatternFormInput/Email.test.tsx— includes assertion thatregisteris called with the emailpatternRadioInput/RadioInput.test.tsxListboxMultiselect/ListboxMultiselect.test.tsxMixedCheckbox/MixedCheckbox.test.tsx— includes assertion of themixed → true → false → mixedstate cycleDateInput/DateInput.test.tsx— covers bothDateInputandTimeInput; parity tests are parameterized viajest-eachto avoid duplicationFileUpload/FileUpload.test.tsxEach test file contains two
describeblocks:updateCallbackinvocation, required/disabled/error UI states)getInputTypeto assert identical behaviorChecklist
Other Related Issues
None
Verification steps
Each input type should render and behave identically to its predecessor in
formGenerators.tsx. Spot-check by opening a contact form that exercises each input type (search, numeric, email, radio, multiselect, mixed checkbox, date, time, file upload).Run the new tests with:
AFTER YOU MERGE
You are responsible for ensuring the above steps are completed. If you move a ticket into QA without advising what version to test, the QA team will assume the latest tag has the changes. If it does not, the following confusion is on you! :-P
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.