diff --git a/app/Livewire/Suivi/Index.php b/app/Livewire/Suivi/Index.php index 8e13c1b..2212214 100644 --- a/app/Livewire/Suivi/Index.php +++ b/app/Livewire/Suivi/Index.php @@ -199,7 +199,10 @@ class Index extends Component $tracked = $this->trackedForCategoryThisMonth($category, $year, $month); - return [$category->id => min(100, round($tracked / $budget * 100))]; + return [$category->id => [ + 'pct' => min(100, round($tracked / $budget * 100)), + 'remaining' => max(0, $budget - $tracked), + ]]; }); return view('livewire.suivi.index', [ diff --git a/resources/views/livewire/suivi/index.blade.php b/resources/views/livewire/suivi/index.blade.php index d52e62b..6035751 100644 --- a/resources/views/livewire/suivi/index.blade.php +++ b/resources/views/livewire/suivi/index.blade.php @@ -70,13 +70,20 @@ @endif - - {{ $category->name }} + + + {{ $category->name }} + @if ($progress !== null) + {{ $progress['pct'] }}% + @endif + @if ($progress !== null) - {{ $progress }}% + + {{ number_format($progress['remaining'], 0, ',', ' ') }} € restants + @endif diff --git a/tests/Feature/SuiviTest.php b/tests/Feature/SuiviTest.php index 000b44f..dd6e2b0 100644 --- a/tests/Feature/SuiviTest.php +++ b/tests/Feature/SuiviTest.php @@ -184,7 +184,7 @@ it('shows the recurrence again the following month after being confirmed', funct expect($component->viewData('pendingRecurrences')->pluck('id'))->toContain($recurring->id); }); -it('computes the percentage of budget already tracked for a category this month', function (): void { +it('computes the percentage and remaining budget already tracked for a category this month', function (): void { $this->travelTo(now()->setDate(2026, 3, 10)); $user = User::factory()->create(); @@ -198,11 +198,13 @@ it('computes the percentage of budget already tracked for a category this month' ]); $component = Livewire::actingAs($user)->test(Index::class); + $progress = $component->viewData('categoryProgress')[$category->id]; - expect($component->viewData('categoryProgress')[$category->id])->toBe(60.0); + expect($progress['pct'])->toBe(60.0); + expect($progress['remaining'])->toBe(400.0); }); -it('caps the category progress percentage at 100', function (): void { +it('caps the category progress percentage at 100 and floors remaining at 0', function (): void { $this->travelTo(now()->setDate(2026, 3, 10)); $user = User::factory()->create(); @@ -216,8 +218,10 @@ it('caps the category progress percentage at 100', function (): void { ]); $component = Livewire::actingAs($user)->test(Index::class); + $progress = $component->viewData('categoryProgress')[$category->id]; - expect($component->viewData('categoryProgress')[$category->id])->toBe(100); + expect($progress['pct'])->toBe(100); + expect($progress['remaining'])->toBe(0); }); it('returns no progress for a category without a budget defined', function (): void {