diff --git a/app/Filament/Widgets/TotalUsersOverview.php b/app/Filament/Widgets/TotalUsersOverview.php new file mode 100644 index 0000000..fbc8f8b --- /dev/null +++ b/app/Filament/Widgets/TotalUsersOverview.php @@ -0,0 +1,30 @@ + + */ + protected function getStats(): array + { + return [ + Stat::make(__('admin.widgets.total_users.label'), User::query()->count()) + ->description(__('admin.widgets.total_users.description')) + ->icon(Heroicon::Users) + ->color('primary'), + ]; + } +} diff --git a/lang/en/admin.php b/lang/en/admin.php index d3344d9..2c4f05d 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -1,6 +1,12 @@ [ + 'total_users' => [ + 'label' => 'Users', + 'description' => 'Total application user accounts.', + ], + ], 'users' => [ 'navigation' => [ 'label' => 'Users', diff --git a/lang/fr/admin.php b/lang/fr/admin.php index 3324e3e..352afd8 100644 --- a/lang/fr/admin.php +++ b/lang/fr/admin.php @@ -1,6 +1,12 @@ [ + 'total_users' => [ + 'label' => 'Utilisateurs', + 'description' => 'Nombre total de comptes utilisateurs.', + ], + ], 'users' => [ 'navigation' => [ 'label' => 'Utilisateurs', diff --git a/tests/Feature/FilamentDashboardTest.php b/tests/Feature/FilamentDashboardTest.php new file mode 100644 index 0000000..ba0458d --- /dev/null +++ b/tests/Feature/FilamentDashboardTest.php @@ -0,0 +1,34 @@ +setLocale('fr'); + + Filament::setCurrentPanel(Filament::getPanel('dashboard')); +}); + +it('shows the total users count on the filament dashboard widget', function () { + $admin = User::factory()->create([ + 'role' => UserRole::ADMIN, + ]); + + User::factory()->count(2)->create(); + + $this->actingAs($admin); + + expect(Filament::getPanel('dashboard')->getWidgets()) + ->toContain(TotalUsersOverview::class); + + Livewire::test(TotalUsersOverview::class) + ->assertSee('Utilisateurs') + ->assertSee('Nombre total de comptes utilisateurs.') + ->assertSee('3'); +});