Certified/tests/Feature/DashboardTest.php
Joël van de Wouw ac340d125c
Some checks failed
linter / quality (push) Failing after 13s
tests / ci (8.3) (push) Failing after 2s
tests / ci (8.4) (push) Failing after 2s
tests / ci (8.5) (push) Failing after 3s
Initial commit
Certificate manager built on Laravel 13, Livewire 4, and Flux.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-12 14:44:58 +02:00

57 lines
No EOL
1.9 KiB
PHP

<?php
use App\Models\Certificate;
use App\Models\User;
use Livewire\Livewire;
test('guests are redirected to the login page', function () {
$response = $this->get(route('dashboard'));
$response->assertRedirect(route('login'));
});
test('authenticated users can visit the dashboard', function () {
$user = User::factory()->create();
$this->actingAs($user);
$response = $this->get(route('dashboard'));
$response->assertOk();
});
test('the dashboard computes certificate stats for the user', function () {
$user = User::factory()->create(['reminder_months_before' => 1]);
Certificate::factory()->for($user)->create(['expires_at' => today()->addYear()]); // valid
Certificate::factory()->for($user)->create(['expires_at' => today()->addWeeks(2)]); // expiring soon
Certificate::factory()->for($user)->expired()->create(); // expired
$this->actingAs($user);
Livewire::test('pages::dashboard')
->assertSet('stats', fn ($stats) => $stats['total'] === 3
&& $stats['valid'] === 1
&& $stats['expiringSoon'] === 1
&& $stats['expired'] === 1);
});
test('the dashboard only reflects the authenticated user data', function () {
$user = User::factory()->create();
Certificate::factory()->for($user)->create(['title' => 'My Certificate', 'expires_at' => today()->addWeek()]);
$other = User::factory()->create();
Certificate::factory()->for($other)->create(['title' => 'Someone Elses', 'expires_at' => today()->addWeek()]);
$this->actingAs($user);
$this->get(route('dashboard'))
->assertOk()
->assertSee('My Certificate')
->assertDontSee('Someone Elses');
});
test('the dashboard shows an empty state with no certificates', function () {
$this->actingAs(User::factory()->create());
$this->get(route('dashboard'))
->assertOk()
->assertSee('No certificates yet');
});