<?php

use App\Filament\Resources\PolicyResource;
use App\Models\Policy;
use App\Models\ManagedEnvironment;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;

uses(RefreshDatabase::class);
test('policies bulk actions are available for authenticated users', function () {
    $tenant = ManagedEnvironment::factory()->create();
    [$user, $tenant] = createUserWithTenant($tenant, role: 'owner');

    setAdminPanelContext($tenant);
    $policies = Policy::factory()->count(2)->create(['managed_environment_id' => $tenant->id]);

    Livewire::actingAs($user)
        ->test(PolicyResource\Pages\ListPolicies::class)
        ->callTableBulkAction('bulk_sync', $policies)
        ->assertHasNoTableBulkActionErrors();
});
