Skip to content

Add specs for remaining under-covered form controls - #650

Open
fpigeonjr wants to merge 2 commits into
masterfrom
gh-631-form-control-specs
Open

Add specs for remaining under-covered form controls#650
fpigeonjr wants to merge 2 commits into
masterfrom
gh-631-form-control-specs

Conversation

@fpigeonjr

Copy link
Copy Markdown
Contributor

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 the sam-sds-autocomplete search component (autocomplete-search.component.ts).

  • checkbox/checkbox.spec.ts (new) — no spec previously existed for this component. Covers ControlValueAccessor wiring, rendering per-option checkboxes, checked-state ordering on onCheckChanged, onSelectAllChange (select/deselect all), disabled-option filtering in setModelValue, checkAllLabelOrId (with/without id), and reactive-form error formatting via ngOnInit.
  • text.spec.ts — added coverage for _setupFormControl (both useFormService branches, submit/reset events via SamFormService), ngOnDestroy unsubscribe path, whitespace trimming on blur, focus-driven onTouched, emitOn: "change" vs "input" filtering.
  • select.spec.ts — added useFormService submit/reset wiring and onBlur touched/format-errors behavior.
  • textarea.spec.ts — added useFormService wiring, onFocus emitters.
  • number.spec.ts — added useFormService wiring and keyDownHandler invalid-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.error branches), all three onInputChange branches (empty/valid/invalid), emitChanges with/without a registered onChange, dateBlur focus delegation, resetInput, and both useFormService branches.
  • sam-form-control.spec.ts — added a new describe block covering initReactiveForms (both disableValidation branches), setValidationMethod (both useFormService branches via submit/reset events), initWrapper, and the "no control" no-op paths for ngOnInit/ngAfterViewInit.
  • radiobutton.spec.ts — added the ngAfterViewInit case with a FormControl present (hitting the valueChanges.subscribe line, previously only exercised without a control).
  • toggle-switch.spec.ts — added a case asserting stopPropagation is called on onSwitchClick when the event supports it.
  • autocomplete-search.component.spec.ts — the largest remaining gap; added ~25 new cases covering checkForFocus (default / tag-mode / free-text branches), updateSingleModeFocusOutModel, clickOutSide, focusRemoved across single-mode (existing-item vs. new free-text) and multiple-mode (delimiter vs. plain free-text vs. neither) branches, onkeypress read-only gating, selectItem with essentialModelFields, openOptions, all showFreeText branches, getClass, onScroll/getAdditionalResults, and writeValue's non-instance/empty-items/multi-mode branches.

All new/expanded specs exercise components through their public API (inputs, outputs, DOM, and ControlValueAccessor methods) — 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)

  • Bug fix (non-breaking change which fixes an issue) → Apply bugfix label
  • New feature (non-breaking change which adds functionality) → Apply enhancement label
  • Breaking change (fix or feature that would cause existing functionality to change) → Apply breaking label
  • Documentation / configuration update → Apply maintenance label

How to Test

  1. npm ci && npm ci --prefix test-app
  2. npm --prefix test-app test — runs the full spec suite via Vitest with coverage.
  3. npm run coverage:check — confirms the repo-wide ratcheting coverage floor still passes (it improves).
  4. npm run lint:baseline — confirms no new ESLint warnings beyond the existing baseline.
  5. npm run format:check — confirms Prettier formatting.
  6. 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 on master). Per-control line coverage increases measurably from baseline for every control listed in #631, e.g. checkbox.component.ts 52.7% → 97.3%, date-time.component.ts 56.5% → 100%, autocomplete-search.component.ts 62.5% → 85.7%. Repo-wide coverage gate passes (lines 55.37% vs. floor 52.84%). Lint baseline gate passes at 1630 warnings (baseline 1631, i.e. it improved). format:check passes cleanly.

Screenshots (if appropriate)

N/A — test-only changes, no UI/behavior changes.

Checklist

  • Branch name follows convention (e.g. gh-<number>-<slug>)
  • PR title starts with a verb in the imperative mood
  • I have self-reviewed my own code
  • format:check passes (npm run format:check)
  • lint passes (npm run lint)
  • build passes (cd test-app && npm run build)
  • Tests pass and coverage is reported (cd test-app && npm test)
  • If this change requires a documentation update, I have updated it accordingly
  • If there are dependent changes, they have been merged and published in downstream modules

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.
@fpigeonjr fpigeonjr added the maintenance Repo maintenance / tooling label Aug 27, 2026
@fpigeonjr fpigeonjr self-assigned this Aug 27, 2026
@fpigeonjr
fpigeonjr requested a lite review from Copilot August 27, 2026 22:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 checkbox spec suite and expanded spec coverage for several existing form controls (text, select, textarea, number, date-time, radiobutton, toggle-switch).
  • Added/expanded specs covering SamFormService wiring, blur/focus behaviors, CVA interactions, and key handling.
  • Expanded sam-sds-autocomplete search 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.

Comment thread src/ui-kit/form-controls/number/number.spec.ts
- 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
fpigeonjr marked this pull request as ready for review August 27, 2026 22:19
@fpigeonjr
fpigeonjr requested a review from a team as a code owner August 27, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Repo maintenance / tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add specs for remaining under-covered form controls

2 participants