<?php

use App\Enums\UserRole;
use App\Filament\Widgets\TotalUsersOverview;
use App\Models\User;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;

uses(RefreshDatabase::class);

beforeEach(function () {
    app()->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');
});
