Add specs for remaining under-covered form controls - #650
Open
fpigeonjr wants to merge 2 commits into
Open
Conversation
Raise unit-test coverage for the remaining under-covered form controls: checkbox, text, select, textarea, number, date-time, sam-form-control, radiobutton, toggle-switch, and the sam-sds-autocomplete search component. All new specs exercise components through their public API (inputs/outputs/DOM/ControlValueAccessor methods), not private implementation details.
There was a problem hiding this comment.
Pull request overview
This pull request increases Vitest unit-test coverage for multiple under-covered Angular form controls in src/ui-kit/form-controls/, primarily by adding new spec cases and expanding existing ones (including a new spec file for checkbox).
Changes:
- Added a new
checkboxspec suite and expanded spec coverage for several existing form controls (text, select, textarea, number, date-time, radiobutton, toggle-switch). - Added/expanded specs covering
SamFormServicewiring, blur/focus behaviors, CVA interactions, and key handling. - Expanded
sam-sds-autocompletesearch component specs to cover additional focus, free-text, scrolling, and writeValue branches.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/ui-kit/form-controls/toggle-switch/toggle-switch.spec.ts | Adds a test for event stopPropagation behavior in onSwitchClick. |
| src/ui-kit/form-controls/textarea/textarea.spec.ts | Adds tests for form-service wiring, focus events, and blur whitespace trimming. |
| src/ui-kit/form-controls/text/text.spec.ts | Adds tests for error formatting/validation paths, blur trimming, touched-on-focus, and emitOn filtering/unsubscribe. |
| src/ui-kit/form-controls/select/select.spec.ts | Adds tests for SamFormService submit/reset wiring and blur touched behavior. |
| src/ui-kit/form-controls/sam-sds-autocomplete/autocomplete-search/autocomplete-search.component.spec.ts | Adds extensive new branch coverage for focus/free-text modes, scrolling, selection, and writeValue behavior. |
| src/ui-kit/form-controls/sam-form-control/sam-form-control.spec.ts | Adds a new block testing reactive-form validation wiring and SamFormService submit/reset behavior. |
| src/ui-kit/form-controls/radiobutton/radiobutton.spec.ts | Adds coverage for formatting errors on FormControl value changes post-init. |
| src/ui-kit/form-controls/number/number.spec.ts | Adds tests for SamFormService wiring and keyDown invalid/valid key handling. |
| src/ui-kit/form-controls/date-time/date-time.spec.ts | Expands from smoke test to cover validation, parsing, emission logic, focus delegation, reset, and form-service wiring. |
| src/ui-kit/form-controls/checkbox/checkbox.spec.ts | New spec file covering CVA behavior, option rendering, selection ordering, select-all, disabled filtering, label/id derivation, and messaging. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Assert '+' is actually blocked by keyDownHandler, matching the test's stated description (Copilot review comment). - Rename the MULTIPLE-mode writeValue test to match its actual assertion (inputValue is left unchanged, not set from the first item) and assert that behavior explicitly (Copilot review comment).
fpigeonjr
marked this pull request as ready for review
August 27, 2026 22:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Raises unit-test coverage for the remaining under-covered form controls called out in #631:
checkbox,text,select,textarea,number,date-time,sam-form-control,radiobutton,toggle-switch, and thesam-sds-autocompletesearch component (autocomplete-search.component.ts).checkbox/checkbox.spec.ts(new) — no spec previously existed for this component. CoversControlValueAccessorwiring, rendering per-option checkboxes, checked-state ordering ononCheckChanged,onSelectAllChange(select/deselect all), disabled-option filtering insetModelValue,checkAllLabelOrId(with/withoutid), and reactive-form error formatting viangOnInit.text.spec.ts— added coverage for_setupFormControl(bothuseFormServicebranches, submit/reset events viaSamFormService),ngOnDestroyunsubscribe path, whitespace trimming on blur, focus-drivenonTouched,emitOn: "change"vs"input"filtering.select.spec.ts— addeduseFormServicesubmit/reset wiring andonBlurtouched/format-errors behavior.textarea.spec.ts— addeduseFormServicewiring,onFocusemitters.number.spec.ts— addeduseFormServicewiring andkeyDownHandlerinvalid-key blocking (e,-) vs. valid numeric keys.date-time.spec.ts— expanded from a single smoke test to cover the 508-compliance name check,writeValue/parseValueString(valid, falsy-reset, and unparsable-value/console.errorbranches), all threeonInputChangebranches (empty/valid/invalid),emitChangeswith/without a registeredonChange,dateBlurfocus delegation,resetInput, and bothuseFormServicebranches.sam-form-control.spec.ts— added a newdescribeblock coveringinitReactiveForms(bothdisableValidationbranches),setValidationMethod(bothuseFormServicebranches via submit/reset events),initWrapper, and the "no control" no-op paths forngOnInit/ngAfterViewInit.radiobutton.spec.ts— added thengAfterViewInitcase with aFormControlpresent (hitting thevalueChanges.subscribeline, previously only exercised without a control).toggle-switch.spec.ts— added a case assertingstopPropagationis called ononSwitchClickwhen the event supports it.autocomplete-search.component.spec.ts— the largest remaining gap; added ~25 new cases coveringcheckForFocus(default / tag-mode / free-text branches),updateSingleModeFocusOutModel,clickOutSide,focusRemovedacross single-mode (existing-item vs. new free-text) and multiple-mode (delimiter vs. plain free-text vs. neither) branches,onkeypressread-only gating,selectItemwithessentialModelFields,openOptions, allshowFreeTextbranches,getClass,onScroll/getAdditionalResults, andwriteValue's non-instance/empty-items/multi-mode branches.All new/expanded specs exercise components through their public API (inputs, outputs, DOM, and
ControlValueAccessormethods) — no reaching into private members — matching the existing spec conventions in this repo.Motivation and Context
Closes #631
Type of Change (Select One and Apply Label)
bugfixlabelenhancementlabelbreakinglabelmaintenancelabelHow to Test
npm ci && npm ci --prefix test-appnpm --prefix test-app test— runs the full spec suite via Vitest with coverage.npm run coverage:check— confirms the repo-wide ratcheting coverage floor still passes (it improves).npm run lint:baseline— confirms no new ESLint warnings beyond the existing baseline.npm run format:check— confirms Prettier formatting.cd test-app && npm run build— confirms the app still builds.Expected result:
Test Files 107 passed (107)/Tests 744 passed (744)(up from 667 onmaster). Per-control line coverage increases measurably from baseline for every control listed in #631, e.g.checkbox.component.ts52.7% → 97.3%,date-time.component.ts56.5% → 100%,autocomplete-search.component.ts62.5% → 85.7%. Repo-wide coverage gate passes (lines 55.37%vs. floor52.84%). Lint baseline gate passes at1630warnings (baseline1631, i.e. it improved).format:checkpasses cleanly.Screenshots (if appropriate)
N/A — test-only changes, no UI/behavior changes.
Checklist
gh-<number>-<slug>)format:checkpasses (npm run format:check)lintpasses (npm run lint)buildpasses (cd test-app && npm run build)cd test-app && npm test)