<?php

use App\Filament\Pages\Tenancy\RegisterTenant;
use Filament\Facades\Filament;

describe('Register tenant page authorization', function () {
    it('is not visible for readonly members', function () {
        [$user, $tenant] = createUserWithTenant(role: 'readonly');

        $this->actingAs($user);
        $tenant->makeCurrent();

        Filament::setCurrentPanel(Filament::getPanel('tenant'));

        expect(RegisterTenant::canView())->toBeFalse();

        Filament::setCurrentPanel(null);
    });

    it('is visible for owner members', function () {
        [$user, $tenant] = createUserWithTenant(role: 'owner');

        $this->actingAs($user);
        $tenant->makeCurrent();

        Filament::setCurrentPanel(Filament::getPanel('tenant'));

        expect(RegisterTenant::canView())->toBeTrue();

        Filament::setCurrentPanel(null);
    });
});
