Laravel 11 + Livewire 3/Volt + Alpine.js + Tailwind app for household budget planning, transaction tracking, and financial dashboards. - Multi-tenant households with member invites - Plan: monthly/yearly budget per category with overrides - Suivi: transaction log with running balance (desktop + mobile quick-entry) - Dashboard: budget vs tracked breakdown + Chart.js donuts - Flux: Sankey diagram of income allocation - WCAG 2.1 AA color tokens, dark mode, accessible tables/forms - 50 Pest tests Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
77 lines
3.1 KiB
PHP
77 lines
3.1 KiB
PHP
<?php
|
|
|
|
use App\Livewire\Dashboard\Index;
|
|
use App\Models\User;
|
|
use Livewire\Livewire;
|
|
|
|
it('shows budget vs tracked totals for the selected year', function (): void {
|
|
$user = User::factory()->create();
|
|
$household = $user->currentHousehold;
|
|
$category = $household->categories()->create(['name' => 'Loyer', 'type' => 'depense', 'position' => 1]);
|
|
|
|
$category->budgetLines()->create(['household_id' => $household->id, 'year' => 2026, 'month' => null, 'amount' => 1200]);
|
|
|
|
$household->transactions()->create([
|
|
'category_id' => $category->id, 'user_id' => $user->id,
|
|
'date' => '2026-03-01', 'date_effective' => '2026-03-01', 'amount' => 1200,
|
|
]);
|
|
|
|
$component = Livewire::actingAs($user)->test(Index::class)->set('year', 2026)->set('period', 'year');
|
|
|
|
$sections = $component->viewData('sections');
|
|
|
|
expect($sections['depense']['totals']['budget'])->toBe(14400.0); // 1200 * 12
|
|
expect($sections['depense']['totals']['tracked'])->toBe(1200.0);
|
|
});
|
|
|
|
it('defaults to the current month instead of the full year', function (): void {
|
|
$user = User::factory()->create();
|
|
|
|
$component = Livewire::actingAs($user)->test(Index::class);
|
|
|
|
expect($component->get('period'))->toBe((string) now()->month);
|
|
expect($component->get('year'))->toBe((int) now()->year);
|
|
});
|
|
|
|
it('filters tracked and budget to a single month when a period is selected', function (): void {
|
|
$user = User::factory()->create();
|
|
$household = $user->currentHousehold;
|
|
$category = $household->categories()->create(['name' => 'Assurances', 'type' => 'depense', 'position' => 1]);
|
|
|
|
$category->budgetLines()->create(['household_id' => $household->id, 'year' => 2026, 'month' => null, 'amount' => 189.89]);
|
|
$category->budgetLines()->create(['household_id' => $household->id, 'year' => 2026, 'month' => 8, 'amount' => 270]);
|
|
|
|
$component = Livewire::actingAs($user)->test(Index::class)
|
|
->set('year', 2026)
|
|
->set('period', '8');
|
|
|
|
$sections = $component->viewData('sections');
|
|
|
|
expect($sections['depense']['totals']['budget'])->toBe(270.0);
|
|
});
|
|
|
|
it('excludes zero-tracked categories from chart data and caps it at 6', function (): void {
|
|
$user = User::factory()->create();
|
|
$household = $user->currentHousehold;
|
|
|
|
$tracked = collect();
|
|
for ($i = 1; $i <= 8; $i++) {
|
|
$category = $household->categories()->create(['name' => "Cat{$i}", 'type' => 'depense', 'position' => $i]);
|
|
$household->transactions()->create([
|
|
'category_id' => $category->id, 'user_id' => $user->id,
|
|
'date' => '2026-01-01', 'date_effective' => '2026-01-01', 'amount' => $i * 10,
|
|
]);
|
|
$tracked->push($category);
|
|
}
|
|
|
|
$zero = $household->categories()->create(['name' => 'CatZero', 'type' => 'depense', 'position' => 99]);
|
|
|
|
$component = Livewire::actingAs($user)->test(Index::class)->set('year', 2026)->set('period', 'year');
|
|
|
|
$chartData = $component->viewData('chartData');
|
|
|
|
expect($chartData['depense']['labels'])->toHaveCount(6);
|
|
expect($chartData['depense']['labels'])->not->toContain('CatZero');
|
|
expect($chartData['depense']['labels']->first())->toBe('Cat8'); // highest tracked first
|
|
});
|