<?php

declare(strict_types=1);

use App\Filament\Resources\ProviderConnectionResource\Pages\ListProviderConnections;
use Filament\Actions\Action;
use Filament\Facades\Filament;
use Livewire\Livewire;

it('does not authorize provider connection create CTA for non-members', function (): void {
    [$user, $tenant] = createUserWithTenant(role: 'owner');
    $user->tenants()->detach((int) $tenant->getKey());
    app(\App\Services\Auth\CapabilityResolver::class)->clearCache();

    $this->actingAs($user);
    $tenant->makeCurrent();
    Filament::setTenant($tenant, true);

    Livewire::test(ListProviderConnections::class)
        ->assertActionExists('create', function (Action $action): bool {
            return $action->isAuthorized() === false;
        });
});
