Skip to content

fix(test): anchor flat-value 5%-floor test dates to DateTime.now()#637

Closed
TaprootFreak wants to merge 1 commit into
stagingfrom
fix/portfolio-chart-test-date-relative
Closed

fix(test): anchor flat-value 5%-floor test dates to DateTime.now()#637
TaprootFreak wants to merge 1 commit into
stagingfrom
fix/portfolio-chart-test-date-relative

Conversation

@TaprootFreak
Copy link
Copy Markdown
Contributor

Problem

The flat-value series still spreads lines via the 5% floor (no Y-collapse) test in test/screens/dashboard/portfolio_chart_cubit_test.dart:64 constructs a PortfolioChartCubit and asserts on horizontalLineValues without calling selectPeriod. The cubit's default period is TimePeriod.threeMonths, which clips visibleSpots to a window anchored at DateTime.now() (lib/screens/dashboard/bloc/portfolio_chart/portfolio_chart_cubit.dart:51).

The previous data points (2026-01-01, 2026-02-01, 2026-03-01) were inside that window when the test was written but fall outside as soon as the wall clock crosses three months past the last point. When that happens, visibleSpots is empty, horizontalLineValues is empty, and the hasLength(6) assertion at line 76 fails on every PR run until someone notices.

This surfaced on 2026-06-02. The last green CI on staging was on 2026-06-01 at 21:56 — the boundary crossed shortly after.

Fix

Anchor the three data points to DateTime.now() (−60 d, −30 d, −1 d) so they stay inside the three-month window regardless of when CI runs. This mirrors the pattern the surrounding selectPeriod to oneWeek / oneMonth / threeMonths / oneYear tests already use (portfolio_chart_cubit_test.dart:131+).

The asserted line values are unchanged because the value math (10000 → average 100 → 5 % floor 5 → nice-number interval 2 → bottom 94) only depends on the magnitudes, not on the timestamps.

A short comment is added next to the now so a future reader sees why the test reaches for the wall clock.

Validation

  • flutter test test/screens/dashboard/portfolio_chart_cubit_test.dart — 13/13 pass locally on 2026-06-02.
  • Unblocks every PR opened on or after 2026-06-02 that runs Analyze & Test.

Out of scope

A more durable fix would inject a Clock into the cubit and pin it to a fixed instant in tests — that's a refactor of PortfolioChartCubit itself and properly belongs in a separate PR.

The "flat-value series still spreads lines via the 5% floor" test in
`portfolio_chart_cubit_test.dart` constructs a `PortfolioChartCubit` and
asserts on `horizontalLineValues` without calling `selectPeriod`. The
cubit's default period is `TimePeriod.threeMonths`, which clips
`visibleSpots` to a window anchored at `DateTime.now()`.

The previous data points (`2026-01-01`, `2026-02-01`, `2026-03-01`)
were inside that window when the test was written but fall outside as
soon as the wall clock crosses three months past the last point — at
which moment `visibleSpots` returns empty, `horizontalLineValues`
returns empty, and the `hasLength(6)` assertion at line 76 fails on
every PR run until someone notices. This first surfaced on 2026-06-02,
the day after the test was still passing.

Anchor the three data points to `DateTime.now()` (-60d, -30d, -1d) so
they stay inside the three-month window regardless of when CI runs. The
asserted line values are unchanged because the value math (10000 →
average 100 → 5% floor 5 → nice-number interval 2 → bottom 94) doesn't
depend on the timestamps.
@TaprootFreak
Copy link
Copy Markdown
Contributor Author

Folded into #635 (this PR's commit is now part of the Tranche A stack). #635's Analyze & Test will pass once the new build picks up the test fix.

@TaprootFreak TaprootFreak deleted the fix/portfolio-chart-test-date-relative branch June 2, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant