fix(test): anchor flat-value 5%-floor test dates to DateTime.now()#637
Closed
TaprootFreak wants to merge 1 commit into
Closed
fix(test): anchor flat-value 5%-floor test dates to DateTime.now()#637TaprootFreak wants to merge 1 commit into
TaprootFreak wants to merge 1 commit into
Conversation
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.
Contributor
Author
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.
Problem
The
flat-value series still spreads lines via the 5% floor (no Y-collapse)test intest/screens/dashboard/portfolio_chart_cubit_test.dart:64constructs aPortfolioChartCubitand asserts onhorizontalLineValueswithout callingselectPeriod. The cubit's default period isTimePeriod.threeMonths, which clipsvisibleSpotsto a window anchored atDateTime.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,visibleSpotsis empty,horizontalLineValuesis empty, and thehasLength(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 surroundingselectPeriod to oneWeek / oneMonth / threeMonths / oneYeartests already use (portfolio_chart_cubit_test.dart:131+).The asserted line values are unchanged because the value math (
10000→ average100→ 5 % floor5→ nice-number interval2→ bottom94) only depends on the magnitudes, not on the timestamps.A short comment is added next to the
nowso 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.Analyze & Test.Out of scope
A more durable fix would inject a
Clockinto the cubit and pin it to a fixed instant in tests — that's a refactor ofPortfolioChartCubititself and properly belongs in a separate PR.