<?php

use App\Filament\Resources\FindingResource\Pages\ListFindings;
use App\Models\Finding;
use Filament\Facades\Filament;
use Livewire\Livewire;

test('readonly users cannot triage findings', function () {
    [$user, $tenant] = createUserWithTenant(role: 'readonly');
    $this->actingAs($user);
    Filament::setTenant($tenant, true);

    $finding = Finding::factory()->for($tenant)->create([
        'finding_type' => Finding::FINDING_TYPE_DRIFT,
        'status' => Finding::STATUS_NEW,
    ]);

    Livewire::test(ListFindings::class)
        ->assertTableActionDisabled('triage', $finding)
        ->callTableAction('triage', $finding);

    $finding->refresh();
    expect($finding->status)->toBe(Finding::STATUS_NEW);
});
