<?php

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

test('a finding can be triaged via table action', function () {
    [$user, $tenant] = createUserWithTenant(role: 'manager');
    $this->actingAs($user);
    Filament::setTenant($tenant, true);

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

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

    $finding->refresh();

    expect($finding->status)->toBe(Finding::STATUS_TRIAGED);
    expect($finding->triaged_at)->not->toBeNull();
});
