Skip to content

test(dashboard+settings): chart cubits + dashboard_bloc + settings_bloc (+22 tests)#333

Merged
TaprootFreak merged 1 commit into
developfrom
test/dashboard-charts-and-settings-bloc
May 15, 2026
Merged

test(dashboard+settings): chart cubits + dashboard_bloc + settings_bloc (+22 tests)#333
TaprootFreak merged 1 commit into
developfrom
test/dashboard-charts-and-settings-bloc

Conversation

@TaprootFreak
Copy link
Copy Markdown
Contributor

Summary

Stage 9 of the coverage push. Adds 22 unit tests for the remaining dashboard cubits/bloc plus the global settings bloc.

Cubit / Bloc under test Test file Cases
`dashboard/bloc/price_chart/price_chart_cubit.dart` `test/screens/dashboard/price_chart_cubit_test.dart` 4
`dashboard/bloc/portfolio_chart/portfolio_chart_cubit.dart` `test/screens/dashboard/portfolio_chart_cubit_test.dart` 5
`dashboard/bloc/dashboard_transaction_history_cubit.dart` `test/screens/dashboard/dashboard_transaction_history_cubit_test.dart` 4
`dashboard/bloc/dashboard_bloc.dart` `test/screens/dashboard/dashboard_bloc_test.dart` 3
`settings/bloc/settings_bloc.dart` `test/screens/settings/settings_bloc_test.dart` 6

What each file covers

  • price_chart_cubit: empty-input zero-window state, all-period spots scaled by 100 + 10% Y-padding, `selectPeriod`-same is a no-op (no emit), `oneWeek` filter narrows to recent points.
  • portfolio_chart_cubit: empty-input zero-window state, all-period scaling + 6 horizontal-line values, flat-value series spreads via the 5% floor (no Y-collapse — pins the `average * 0.05` lower bound and the rounding to nice numbers `{1,2,5,10}`), `selectPeriod`-same no-op, `oneWeek` narrows visibleSpots.
  • dashboard_transaction_history_cubit: initial empty list, subscribes to `watchTransactionsOfAssets` with limit `3`, forwards every stream emission into state, `close()` cancels the subscription.
  • dashboard_bloc: initial state carries the supplied currency, the constructor `refresh()` populates price + priceChart + portfolioHistory via the services, `CurrencyChangedEvent` updates state and re-fetches all three datasets in the new currency.
  • settings_bloc: initial state reads through the repo, `SetLanguageEvent` writes `'de'` + emits, `SetCurrencyEvent` writes `'EUR'` + emits, `SetNetworkModeEvent` writes + calls `getNewAuthToken` + emits, `ToggleHideAmountEvent` flips both ways, a single toggle sets `hideAmounts=true`.

Notes

  • The `dashboard_bloc` CurrencyChangedEvent test attaches a listener BEFORE adding the event because `Bloc.stream` is broadcast (no replay) and the event-driven re-fetch can complete before a follow-on `firstWhere` subscribes — same constraint we've now hit a few times in this push.

Excluded (and why)

  • `dashboard_bloc` refresh after a service throw — non-trivial to test cleanly because the bloc lets the exception propagate out of the handler (which then surfaces as an unhandled bloc error in tests). Leaving as a follow-up.
  • `transaction_history_receipt_cubit`, `transaction_history_multi_receipt_cubit`, `settings_tax_report_cubit` — all use `getTemporaryDirectory()` + real `File` IO.
  • Buy / sell / sell_bitbox / hardware_connect_bitbox cubits — touched by the still-open PRs (fix: keep dashboard buy actions visible #321 dashboard buy actions, fix(bitbox): harden multi-page sign and KYC routing #332 bitbox sign hardening); held back to avoid review conflicts.
  • `settings_user_data_cubit` — coordinates 3 services + country-lookup branches; deserves its own focused PR.

Test plan

  • `flutter analyze` on all five new files — clean
  • `flutter test` — 22 / 22 passing locally
  • CI green

… (+22 tests)

Stage 9 of the coverage push.

- price_chart_cubit (4): empty-input shape, all-period spots scaled
  by 100 with 10% Y-padding, selectPeriod-same no-op, oneWeek filter
  narrows to recent
- portfolio_chart_cubit (5): empty-input shape, all-period scaling
  + 6 horizontal-line values, flat-value series spreads via the 5%
  floor (no Y-collapse), selectPeriod-same no-op, oneWeek narrows
- dashboard_transaction_history_cubit (4): initial empty list,
  subscribes to watchTransactionsOfAssets with limit 3, forwards
  stream emissions, close cancels subscription
- dashboard_bloc (3): initial state carries supplied currency,
  refresh populates price+chart+history via the services,
  CurrencyChangedEvent updates state and re-fetches all three
- settings_bloc (6): initial state reads through repo, SetLanguage
  writes 'de'/emits, SetCurrency writes 'EUR'/emits,
  SetNetworkMode writes + calls getNewAuthToken + emits,
  ToggleHideAmount flips both ways, single toggle sets true
@TaprootFreak TaprootFreak marked this pull request as ready for review May 15, 2026 09:17
@TaprootFreak TaprootFreak merged commit d2d9bff into develop May 15, 2026
1 check passed
@TaprootFreak TaprootFreak deleted the test/dashboard-charts-and-settings-bloc branch May 15, 2026 09:17
TaprootFreak added a commit that referenced this pull request May 15, 2026
…ts) (#336)

## Summary
Stage 12 of the coverage push. Covers the previously-deferred
\`settings_user_data_cubit\` (3-service coordination + Country lookups)
and the read-side of \`transaction_history_service\`.

| File under test | Test file | Cases |
| --- | --- | --- |
| \`lib/screens/settings_user_data/cubit/settings_user_data_cubit.dart\`
| \`test/screens/settings_user_data/settings_user_data_cubit_test.dart\`
| 6 |
| \`lib/packages/service/transaction_history_service.dart\`
(\`fetchPendingTransactions\` only) |
\`test/packages/service/transaction_history_service_test.dart\` | 6 |

## What each file covers
- **settings_user_data_cubit:** the cubit fans out to
\`RealUnitWalletService.getWalletStatus\` and
\`DfxKycService.getKycStatus\` in parallel, then either falls back to
\`getUser\` (when userData is missing) or runs two more
\`getCountryBySymbol\` lookups. Tests pin:
- Full Success when userData is present (with nationality +
addressCountry country lookups resolved to distinct \`Country\`
instances).
- \`pendingSteps\` only contains the three change steps
(name/address/phone) that are in \`inReview\` — other inReview steps
(e.g. \`contactData\`) are ignored.
- \`userData == null\` + \`getUser\` returns mail → \`Success(email)\`,
no country lookups happen.
- \`userData == null\` + \`getUser\` throws → \`Success()\` with both
userData and email null.
- Failure when \`getWalletStatus\` throws (the \`Future.wait\`
propagation).
- Failure when \`getCountryBySymbol\` throws on a userData with a
country code.
- **transaction_history_service.fetchPendingTransactions:** no auth
token short-circuits to \`[]\` without any HTTP call (verified via a
MockClient that records calls); GET shape with the Bearer JWT to
\`/v1/transaction/detail\`; non-200 returns \`[]\` (does not throw —
intentional UX); filters out \`Completed\`/\`Failed\`/\`Returned\`
(\`isPending=false\` per the enum extension); filters out transactions
whose \`sourceAccount\` / \`targetAccount\` don't match the current
wallet; wallet-match is **case-insensitive** (covers the lower-casing on
both sides).

## Notes
- \`RealUnitUserDataDto.type\` must use \`'HUMAN'\` / \`'CORPORATION'\`
(the jsonName values of \`RegistrationUserType\`), not a friendly label
— \`fromName\` throws \`StateError\` otherwise.
- Mocktail's \`stream.firstWhere\` pattern is reused for the cubit
(constructor fires \`getUserData\` synchronously, so we can't use
\`blocTest\`'s sequence model reliably here — same as #329, #330, #333).

## Excluded (and why)
- \`transaction_history_service.apiBasedSync\` — writes through
\`TransactionRepository.insertDfxTransaction\`/\`updateTransaction\` and
depends on \`AppStore.primaryAddress\` + \`apiConfig.asset.chainId\`.
Doable but adds repository mock plumbing for a method that's almost
entirely orchestration; will be its own focused PR.
- Buy / sell cubits — still held while #321 (dashboard buy actions) and
#332 (bitbox sign hardening) are open.

## Test plan
- [x] \`flutter analyze\` on the two new files — clean
- [x] \`flutter test\` — 12 / 12 passing locally
- [ ] CI green
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