Skip to content

test: Flutter test harness + critical notifier/filter unit tests - #181

Merged
grunch merged 2 commits into
mainfrom
test/flutter-base-harness
Jul 17, 2026
Merged

test: Flutter test harness + critical notifier/filter unit tests#181
grunch merged 2 commits into
mainfrom
test/flutter-base-harness

Conversation

@AndreaDiazCorreia

@AndreaDiazCorreia AndreaDiazCorreia commented Jul 14, 2026

Copy link
Copy Markdown
Member

Refs #152 (PR1 of 2 — phased).

First slice of the Flutter test base:

  • ProviderContainer harness with auto-dispose + fake data builders (test/support/).
  • Notifier tests: BackupReminderNotifier/BackupCompletedNotifier (snooze, dismiss, legacy migration) and FirstRunNotifier (loading→data, first-launch default).
  • Filter/derivation tests: filteredOrdersProvider (tabs, ownership, currency/payment/rating/premium, sort) and filteredTradesWithOrderStateProvider (status filter, terminal-status collapse, sort) — Rust-backed providers are overridden with fakes.

29 tests passing; flutter analyze clean. Suite runs in the existing CI flutter test step (no workflow change needed).

Deferred to PR2: DESIGN_SYSTEM golden tests.

Summary by CodeRabbit

  • Tests
    • Added coverage for backup reminders and completion, including load/reconcile behavior, snoozing, dismissal, persistence, and legacy fallback.
    • Added first-run completion notifier tests covering loading, defaults, and persistence.
    • Added Riverpod provider tests for orders and trades filtering, status mapping, sorting, and edge cases (unrated/range orders, terminal status bucketing).
  • Test Support
    • Added deterministic order/trade fixtures, including “fake now” timestamping and range order support.
    • Introduced Riverpod test utilities (container creation and order book harness) to streamline provider-based assertions.

- BackupReminderNotifier: badge visibility, snooze/dismiss/complete flows
- BackupCompletedNotifier: load legacy fallback, mark/reset persistence
- FirstRunNotifier: async load, default false, markFirstRunComplete
- filteredOrdersProvider: tab/currency/payment/rating/premium filters, sort
- filteredTradesWithOrderStateProvider: status filter, terminal collapse, sort
- fake_orders/fake_trades test helpers with controllable timestamps
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 33a52983-9183-45a1-a050-ff70e7e7c79c

📥 Commits

Reviewing files that changed from the base of the PR and between f13b3b5 and 42a424d.

📒 Files selected for processing (4)
  • test/features/home/filtered_orders_provider_test.dart
  • test/features/trades/filtered_trades_provider_test.dart
  • test/support/fake_orders.dart
  • test/support/order_book_harness.dart
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/features/trades/filtered_trades_provider_test.dart
  • test/support/fake_orders.dart

Walkthrough

Adds Flutter and Riverpod tests for account notifiers, first-run persistence, order filtering, and trade filtering, along with deterministic fixtures and provider-container cleanup utilities.

Changes

Account notifier and first-run coverage

Layer / File(s) Summary
Account notifier persistence tests
test/features/account/backup_reminder_provider_test.dart, test/features/walkthrough/first_run_provider_test.dart
Tests SharedPreferences loading, fallback behavior, snoozing, completion, reset, initial values, and asynchronous state reconciliation.

Order filtering coverage

Layer / File(s) Summary
Order filtering test harness
test/support/provider_harness.dart, test/support/fake_orders.dart, test/support/order_book_harness.dart, test/features/home/filtered_orders_provider_test.dart
Adds Riverpod setup and deterministic order fixtures, then tests tab, ownership, status, currency, payment method, rating, premium, range-order, and newest-first filtering behavior.

Trade filtering coverage

Layer / File(s) Summary
Trade filtering coverage
test/support/fake_trades.dart, test/features/trades/filtered_trades_provider_test.dart
Adds configurable trade fixtures and tests status filtering, terminal-status mapping, inclusion, and newest-first ordering.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

  • MostroP2P/app issue 152 — The tests cover the Riverpod harness, notifier behavior, and order/trade providers described by the issue.

Possibly related PRs

  • MostroP2P/app#53: Adds backup reminder logic directly exercised by these notifier tests.
  • MostroP2P/app#54: Introduces the order filtering providers covered by the new order tests.
  • MostroP2P/app#70: Changes the order-book provider bridge exercised by the order-book harness.

Poem

A rabbit hops through tests so neat,
With prefs and filters at its feet.
Orders sort and trades align,
Snoozed reminders keep good time.
“Hop hooray!” the fixtures sing! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: new Flutter test harnesses and notifier/filter unit tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/flutter-base-harness

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AndreaDiazCorreia

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: f13b3b5564

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

ermeme[bot]
ermeme Bot previously approved these changes Jul 14, 2026

@ermeme ermeme Bot 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.

Approved. The added unit tests are well-scoped, use fakes appropriately, and cover the main notifier and filter paths without introducing obvious maintenance or correctness issues.

@grunch

grunch commented Jul 16, 2026

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/features/trades/filtered_trades_provider_test.dart (1)

26-33: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Use unorderedEquals instead of containsAll to ensure exact match.

containsAll verifies that the specified items are present but does not fail if unexpected items are also present. Since the goal is to assert the exact set of returned trades (and order isn't strictly important for this specific test), unorderedEquals is a stronger assertion.

♻️ Proposed fix
     test('"All" returns every trade', () async {
       final container = _tradesWith([
         fakeTrade(id: 'a', status: OrderStatus.active),
         fakeTrade(id: 'b', status: OrderStatus.pending),
       ]);
 
-      expect(await _orderIds(container), containsAll(['order-a', 'order-b']));
+      expect(await _orderIds(container), unorderedEquals(['order-a', 'order-b']));
     });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/features/trades/filtered_trades_provider_test.dart` around lines 26 -
33, Update the “All” test’s assertion in `_orderIds` to use `unorderedEquals`
with `['order-a', 'order-b']`, ensuring the result contains exactly those trade
IDs while remaining order-independent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/features/trades/filtered_trades_provider_test.dart`:
- Around line 47-59: Update the terminal-status test’s expectation in
`test('terminal protocol statuses collapse into the success filter')` to use
`unorderedEquals` with exactly `['order-success', 'order-settled']`, ensuring
`order-canceled` is excluded while preserving order-independent matching.

---

Nitpick comments:
In `@test/features/trades/filtered_trades_provider_test.dart`:
- Around line 26-33: Update the “All” test’s assertion in `_orderIds` to use
`unorderedEquals` with `['order-a', 'order-b']`, ensuring the result contains
exactly those trade IDs while remaining order-independent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d4397656-d06b-43cc-970a-a771b706a1cc

📥 Commits

Reviewing files that changed from the base of the PR and between 32b748f and f13b3b5.

📒 Files selected for processing (7)
  • test/features/account/backup_reminder_provider_test.dart
  • test/features/home/filtered_orders_provider_test.dart
  • test/features/trades/filtered_trades_provider_test.dart
  • test/features/walkthrough/first_run_provider_test.dart
  • test/support/fake_orders.dart
  • test/support/fake_trades.dart
  • test/support/provider_harness.dart

Comment thread test/features/trades/filtered_trades_provider_test.dart

@grunch grunch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Strict Review

Actionable comments: 9 (1 high, 4 medium, 4 low) · Verdict: Approve with observations — no blocking issues; the HIGH is a one-line matcher fix worth doing before merge.

Verification performed

  • ✅ Every assertion cross-checked against the actual provider sources (backup_reminder_provider.dart, home_order_providers.dart, trades_providers.dart, first_run_provider.dart) — they reflect implemented behavior (prefs keys, snooze semantics, terminal-status collapse, default-range guards).
  • flutter analyze run locally on this branch in an isolated worktree: clean.
  • ✅ CI green (Flutter analyze/test, Rust, CodeRabbit); the 29-test count in the PR body checks out (12+9+4+4).

What's solid

  • createContainer + addTearDown(container.dispose) is the canonical Riverpod test harness; zero state leakage between tests (setMockInitialValues resets prefs per test).
  • Rust-backed providers correctly isolated via overrideWith — no native bridge involved.
  • kFakeNow anchored timestamps make sort assertions deterministic.
  • Behavior-descriptive test names, consistent AAA structure, legacy fallback covered (BackupCompletedNotifier → dismissed flag), and the non-obvious initialValue + live-snooze reconciliation case is tested.
  • Fits existing CI with no workflow change; accurate PR description.

Summary of findings (details inline)

Severity File Issue
🔴 High filtered_trades_provider_test.dart Terminal-collapse test uses containsAll — cannot fail for the exact regression it targets
🟠 Medium filtered_trades_provider_test.dart "All" test: containsAll doesn't assert length
🟠 Medium filtered_trades_provider_test.dart orderStatusToFilter has 15 arms; only the success bucket is partially covered
🟠 Medium filtered_orders_provider_test.dart Default-range guard semantics (!= defaultRatingRange) unpinned
🟠 Medium fake_orders.dart Builder cannot produce range-shaped orders
🟡 Low filtered_orders_provider_test.dart Latent autoDispose fragility in _bookWith
🟡 Low filtered_orders_provider_test.dart ProviderContainerHelper could live in test/support/
🟡 Low fake_trades.dart Fixture pairs status: active with TradeStep.disputed()
🟡 Low backup_reminder_provider_test.dart Wall-clock dependence in snooze fixtures (noted, not blocking)

Comment thread test/features/trades/filtered_trades_provider_test.dart Outdated
Comment thread test/features/trades/filtered_trades_provider_test.dart Outdated
Comment thread test/features/trades/filtered_trades_provider_test.dart
Comment thread test/features/home/filtered_orders_provider_test.dart
Comment thread test/features/home/filtered_orders_provider_test.dart Outdated
Comment thread test/features/home/filtered_orders_provider_test.dart Outdated
Comment thread test/support/fake_orders.dart Outdated
Comment thread test/support/fake_trades.dart
Comment thread test/features/account/backup_reminder_provider_test.dart
- add tests for unrated orders and range orders in filteredOrdersProvider
- add orderStatusToFilter exhaustiveness test in filtered_trades_provider_test
- extract bookWith/OrderBookHarness from filtered_orders_provider_test to
  support/order_book_harness.dart with autoDispose keepAlive fix
- fakeOrder now supports range orders via fiatAmountMin/fiatAmountMax params
- replace containsAll with unorderedEquals in filtered_trades

@grunch grunch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All High/Medium comments resolved and verified against the actual code:

  • 🔴 High (success test did not verify exclusion) → unorderedEquals + the fixture keeps the canceled trade, so it now fails if one leaks into the success bucket.
  • 🟠 containsAllunorderedEquals, exhaustive orderStatusToFilter test with a length guard, coverage for unrated/range orders, and fakeOrder now supports range orders.
  • 🟡 autoDispose keepAlive + helper extracted to test/support/order_book_harness.dart.

CI green (Flutter, Rust, CodeRabbit). The two remaining Low nits (active+disputed fixture in fake_trades, wall-clock in backup_reminder) are optional follow-ups. LGTM ✅

@grunch
grunch merged commit b8514f5 into main Jul 17, 2026
3 checks passed
@grunch
grunch deleted the test/flutter-base-harness branch July 17, 2026 13:28
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.

2 participants