<?php

use App\Models\Permission;
use App\Models\Role;
use App\Models\User;

it('shows reports index', function (): void {
    $user = User::factory()->create();
    // grant reports-view permission
    $role = Role::create(['name' => 'Reporter', 'slug' => 'reporter']);
    $perm = Permission::firstOrCreate(['slug' => 'reports-view'], ['name' => 'Reports View']);
    $role->permissions()->syncWithoutDetaching($perm->id);
    $role->users()->syncWithoutDetaching($user->id);
    $this->actingAs($user);

    $response = $this->get(route('reports.index'));
    $response->assertSuccessful();
    $response->assertInertia(fn ($page) => $page
        ->component('Reports/Index')
        ->has('reports')
    );
});
