Teren-app/tests/Feature/Reports/ReportsShowTest.php
Simon Pocrnjič 63e0958b66 Dev branch
2025-11-02 12:31:01 +01:00

38 lines
1.4 KiB
PHP

<?php
use App\Models\Permission;
use App\Models\Role;
use App\Models\User;
it('shows a single report page', function (): void {
$user = User::factory()->create();
$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.show', 'field-jobs-completed'));
$response->assertSuccessful();
$response->assertInertia(fn ($page) => $page
->component('Reports/Show')
->where('slug', 'field-jobs-completed')
->has('inputs')
->has('columns')
);
});
it('returns data json for report', function (): void {
$user = User::factory()->create();
$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.data', 'field-jobs-completed'));
$response->assertSuccessful();
$json = $response->json();
expect($json)->toHaveKeys(['data', 'total', 'current_page', 'last_page']);
});