Skip to content

Add specs for date, date-range, date-time, and time form controls - #651

Merged
fpigeonjr merged 3 commits into
masterfrom
gh-629-date-time-specs
Aug 28, 2026
Merged

Add specs for date, date-range, date-time, and time form controls#651
fpigeonjr merged 3 commits into
masterfrom
gh-629-date-time-specs

Conversation

@fpigeonjr

Copy link
Copy Markdown
Contributor

Description

Raises unit-test coverage for the date-related form controls
(src/ui-kit/form-controls/{date,date-range,date-time,time}/), which
were the largest coverage gap tracked under the test-coverage epic
(#576).

All new specs test through the public component API only — the
ControlValueAccessor methods (writeValue/registerOnChange/
registerOnTouched/setDisabledState), @Input/@Output bindings
via template-driven TestBed fixtures, and the two exported static
validators (SamDateComponent.dateRequired/dateValidation,
SamDateRangeComponent.dateRangeValidation/dateRangeRequired). No
new tests reach into private (_-prefixed) methods; a couple of
pre-existing private-method tests were left untouched rather than
refactored mid-PR.

Line coverage, before → after:

Component Before After
date.component.ts 56.25% 98.61%
date-range.component.ts 68.27% 97.93%
date-time.component.ts 56.52% 97.82%
time.component.ts 40.62% 97.65%

What's covered now that wasn't:

  • date.component.ts — static validators (dateRequired/
    dateValidation), ngAfterViewInit control-wiring branches
    (useFormService on/off, SamFormService submit/reset events),
    paste-handler edge cases (month/day/year clamping), getMaxDate/
    getNumJumpThreshold (leap year, 30-day months), digit-typing
    auto-advance-focus behavior, onChangeHandler branches (empty,
    invalid year length, invalid date, valid date), touch/blur/naming
    helpers, and full ControlValueAccessor round-tripping.
  • date-range.component.tsdateRangeValidation/
    dateRangeRequired static validators (valid/invalid ranges, the
    "Invalid date" sentinel-skip branches, hasFocus suppression),
    ngOnInit control-wiring, date-time type's start/end time output,
    and blur/focus handlers.
  • date-time.component.ts — the name-required guard, parseValueString's
    invalid-value branch, all three onInputChange outcomes (empty →
    undefined / valid → combined string / inconsistent → "Invalid Date Time"), and control wiring.
  • time.component.ts — 24→12-hour conversion (PM and midnight cases),
    formatHours am/pm branches, hour/minute keypress typing and
    auto-advance-focus, isValid/getTime, and control wiring.

Also cleaned up several stale/incidental lint findings surfaced while
touching these spec files (unused imports, any typings replaced
with ComponentFixture<T>) — this lowers the ESLint warning count
from 1631 to 1618 without editing the ratcheting eslint-baseline.json
file itself (per repo convention, only lint:baseline:bump may do
that, and it's a strict decrease here so no bump was needed).

Motivation and Context

Closes #629

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. node scripts/check-coverage.mjs test-app/coverage/coverage-summary.json — confirms the coverage floor gate still passes (and now clears it with more headroom: statements 57.05%/branches 46.61%/functions 52.75%/lines 56.42% vs. floors 53.56/39.77/50.31/52.84%).
  4. npm run lint:baseline — confirms the ESLint warning count (1618) is at or below the baseline (1631).
  5. npm run format:check — confirms the new/changed spec files are Prettier-formatted.
  6. cd test-app && npm run build — confirms the app still builds.

Expected result: Test Files 106 passed (106) / Tests 776 passed (776) (up from 667 before this PR), coverage gate passes, lint baseline gate passes, format check passes, build succeeds.

Screenshots (if appropriate)

N/A — test-only change, no UI/behavioral 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

Raises unit-test coverage for the date-related form controls by testing
through the public ControlValueAccessor API, template-driven fixtures,
and the exported static validators:

- date.component.ts: 56.25% -> 98.61% line coverage
- date-range.component.ts: 68.27% -> 97.93% line coverage
- date-time.component.ts: 56.52% -> 97.82% line coverage
- time.component.ts: 40.62% -> 97.65% line coverage

Also cleans up several stale imports/types flagged during the work,
lowering the ESLint warning count from 1631 to 1618 without touching
the ratcheting baseline file.

Closes #629
@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 28, 2026 14:26

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 PR raises unit-test coverage for the date-related form controls in src/ui-kit/form-controls/ by expanding and modernizing the existing spec suites (primarily exercising ControlValueAccessor flows, validator helpers, and UI interaction handlers) to close a major coverage gap tracked in #629/#576.

Changes:

  • Expanded date, date-range, date-time, and time spec coverage across validators, CVA wiring, and key user-interaction branches.
  • Cleaned up spec typing and imports (e.g., using ComponentFixture<T> and adding FormControl where needed).
  • Added additional control-wiring tests around SamFormService submit/reset behavior and useFormService toggling.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/ui-kit/form-controls/time/time.spec.ts Adds extensive CVA, parsing/formatting, typing, and control-wiring specs for SamTimeComponent.
src/ui-kit/form-controls/date/date.spec.ts Adds validator specs plus broader interaction coverage (paste handlers, blur/touch behaviors, CVA flows, wiring branches).
src/ui-kit/form-controls/date-time/date-time.spec.ts Adds specs for parsing, emission rules, name-required guard, CVA behavior, and control wiring.
src/ui-kit/form-controls/date-range/date-range.spec.ts Adds static validator coverage, required-field validation behavior, and additional emitted-value/focus/wiring specs.
Suppressed comments (1)

src/ui-kit/form-controls/time/time.spec.ts:307

  • This spec is currently codifying a real bug in SamTimeComponent.getTime(): hourV.nativeElement.value is a string in the DOM, but getTime() treats it as a number (if (hours === 12) and hours += 12), which results in string concatenation for PM hours (e.g. "5" + 12 → "512") and an invalid Moment.

Instead of asserting "Invalid date" here, it would be better to fix getTime() to coerce hours (and minutes) to numbers and then update this test to expect a valid formatted time (e.g. 17:30). This avoids locking in incorrect behavior that would affect real users.

      component.amPm = "pm";
      component.hourV.nativeElement.value = "5";
      component.minuteV.nativeElement.value = "30";
      const time = component.getTime();
      expect(time.format(component.OUTPUT_FORMAT)).toBe("Invalid date");

💡 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/time/time.spec.ts Outdated
Comment thread src/ui-kit/form-controls/date/date.spec.ts
- time.spec.ts: capture separate beforeHour/beforeMinute values in the
  'ignores c/v key presses' test instead of comparing both fields
  against a single hour-derived 'before' value (was accidentally
  passing because both fields started empty).
- date.spec.ts: assert real behavior in the window.clipboardData
  fallback test — verify getData('text') was called and preventDefault
  was not invoked for a valid pasted value, instead of a no-op
  expect(true).toBe(true).
@fpigeonjr
fpigeonjr marked this pull request as ready for review August 28, 2026 15:08
@fpigeonjr
fpigeonjr requested a review from a team as a code owner August 28, 2026 15:08
# Conflicts:
#	src/ui-kit/form-controls/date-time/date-time.spec.ts
@fpigeonjr
fpigeonjr merged commit e75689d into master Aug 28, 2026
7 checks passed
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 date, date-range, date-time, and time form controls

3 participants