Files
ppeasy_vg12/tests/Feature/Web/DashboardTest.php
T
2026-10-09 08:21:06 +02:00

65 lines
2.0 KiB
PHP

<?php
use Facades\Tests\Setup\UserFactory;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Testing\TestResponse;
use Inertia\Testing\AssertableInertia as Assert;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->artisan('db:seed');
});
test('dashboard renders for authenticated admin', function () {
$this->actingAsAdmin()
->get('/')
->assertOk()
->assertInertia(fn (Assert $page) => $page
->component('Dashboard')
->has('widgets')
);
});
test('dashboard hides user management widgets from roles without the permission', function () {
$this->be(UserFactory::user()->create());
$components = widgetComponents($this->get('/')->assertOk());
$this->assertNotContains('StatWidget', $components);
$this->assertNotContains('RegistrationHistoryWidget', $components);
$this->assertNotContains('LatestRegistrationsWidget', $components);
$this->assertNotContains('ApprovalNoticeWidget', $components);
$this->assertContains('UserActionsWidget', $components);
});
test('dashboard shows user management widgets to roles holding the permission', function () {
$this->be(UserFactory::withPermissions('users.manage')->create());
$components = widgetComponents($this->get('/')->assertOk());
$this->assertContains('StatWidget', $components);
$this->assertContains('RegistrationHistoryWidget', $components);
$this->assertContains('LatestRegistrationsWidget', $components);
});
/**
* @return array<int, string>
*/
function widgetComponents(TestResponse $response): array
{
return array_column($response->viewData('page')['props']['widgets'], 'component');
}
test('dashboard redirects guest to login', function () {
$this->get('/')->assertRedirect('login');
});
test('dashboard flashes success when email verified session is set', function () {
$this->actingAsAdmin()
->withSession(['verified' => true])
->get('/')
->assertOk()
->assertSessionHas('success', __('E-Mail verified successfully.'));
});