whisper-money/tests/Browser
Víctor Falcón ce9574aa14
perf(accounts): replace client-side API calls with Inertia deferred prop (#144)
## Why

The `/accounts` page was making two extra client-side API calls via the
`useDashboardData()` hook:
- `/api/dashboard/net-worth-evolution` (~14.5s in dev)
- `/api/dashboard/top-categories` (~119ms, completely unused on this
page)

The backend logic itself is fast (~34ms), but the full middleware stack
cost of extra HTTP roundtrips in the dev environment was adding
significant overhead.

## What

### Backend (`AccountController.php`)
- Added `ExchangeRateService` constructor injection
- Added `Inertia::defer()` prop `accountMetrics` to the `index()` action
- Added `getAccountMetrics()`, `formatMonth()`, `convertBalance()`
private methods
- Uses `BalanceLookup::forAccounts()` for efficient batch loading (2 SQL
queries regardless of account count)

### Frontend (`Accounts/Index.tsx`)
- Removed `useDashboardData()` hook import and usage
- Added `accountMetrics` as an optional deferred prop (undefined until
resolved)
- Loading state derived from `!accountMetrics`, which naturally drives
the existing `loading` prop on `AccountListCard` (skeleton UI already
existed)
- Added `handleBalanceUpdated` callback using `router.reload({ only:
['accountMetrics'] })` for targeted refresh

## Verification

### Tests
- 3 new Pest tests covering deferred prop behavior:
- `accounts index defers account metrics` — verifies metrics are missing
from initial response, present after `loadDeferredProps()`, with correct
balance values
- `accounts index deferred metrics includes invested amount for
investment accounts` — verifies invested amount for investment account
types
- `accounts index deferred metrics returns null invested amount for
non-investment accounts` — verifies non-investment accounts get null
invested amount
- All 15 tests in `AccountControllerTest.php` pass
2026-02-23 20:08:41 +01:00
..
assets Improve automation rules and sync error handling 2025-12-01 10:30:22 +01:00
.gitignore Add category type field support (#2) 2025-12-01 20:19:47 +01:00
AccountsPageTest.php perf(accounts): replace client-side API calls with Inertia deferred prop (#144) 2026-02-23 20:08:41 +01:00
AmountInputTest.php Remove encryption from browser tests and demo user (#129) 2026-02-17 11:45:27 +01:00
AuthenticationTest.php feat: Enable email verification on sign up (#97) 2026-02-03 10:15:07 +01:00
AutomationRuleBuilderTest.php Remove encryption from browser tests and demo user (#129) 2026-02-17 11:45:27 +01:00
BankAccountsTest.php Remove encryption from browser tests and demo user (#129) 2026-02-17 11:45:27 +01:00
BudgetCrudTest.php Remove budgets feature flag (#108) 2026-02-12 09:58:01 +01:00
BudgetsFeatureNavigationTest.php Remove budgets feature flag (#108) 2026-02-12 09:58:01 +01:00
CategoriesTest.php User Onboarding Flow (#23) 2025-12-12 13:06:08 +01:00
ImportTransactionsTest.php Remove encryption from browser tests and demo user (#129) 2026-02-17 11:45:27 +01:00
OnboardingFlowTest.php Remove encryption from browser tests and demo user (#129) 2026-02-17 11:45:27 +01:00
TransactionsTest.php Remove encryption from browser tests and demo user (#129) 2026-02-17 11:45:27 +01:00