81 lines
3.0 KiB
PHP
81 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Resources\ProviderConnectionResource\Pages\EditProviderConnection;
|
|
use App\Models\ProviderConnection;
|
|
use Filament\Actions\Action;
|
|
use Filament\Facades\Filament;
|
|
use Livewire\Livewire;
|
|
|
|
describe('Edit provider connection actions UI enforcement', function () {
|
|
it('shows enable connection action as visible but disabled for readonly members', function () {
|
|
[$user, $tenant] = createUserWithTenant(role: 'readonly');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$connection = ProviderConnection::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
'status' => 'disabled',
|
|
]);
|
|
|
|
Livewire::test(EditProviderConnection::class, ['record' => $connection->getRouteKey()])
|
|
->assertActionVisible('enable_connection')
|
|
->assertActionDisabled('enable_connection')
|
|
->assertActionExists('enable_connection', function (Action $action): bool {
|
|
return $action->getTooltip() === 'You do not have permission to manage provider connections.';
|
|
})
|
|
->mountAction('enable_connection')
|
|
->callMountedAction()
|
|
->assertSuccessful();
|
|
|
|
$connection->refresh();
|
|
expect($connection->status)->toBe('disabled');
|
|
});
|
|
|
|
it('shows disable connection action as visible but disabled for readonly members', function () {
|
|
[$user, $tenant] = createUserWithTenant(role: 'readonly');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$connection = ProviderConnection::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
'status' => 'connected',
|
|
]);
|
|
|
|
Livewire::test(EditProviderConnection::class, ['record' => $connection->getRouteKey()])
|
|
->assertActionVisible('disable_connection')
|
|
->assertActionDisabled('disable_connection')
|
|
->assertActionExists('disable_connection', function (Action $action): bool {
|
|
return $action->getTooltip() === 'You do not have permission to manage provider connections.';
|
|
})
|
|
->mountAction('disable_connection')
|
|
->callMountedAction()
|
|
->assertSuccessful();
|
|
|
|
$connection->refresh();
|
|
expect($connection->status)->toBe('connected');
|
|
});
|
|
|
|
it('shows enable connection action as enabled for owner members', function () {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$connection = ProviderConnection::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
'status' => 'disabled',
|
|
]);
|
|
|
|
Livewire::test(EditProviderConnection::class, ['record' => $connection->getRouteKey()])
|
|
->assertActionVisible('enable_connection')
|
|
->assertActionEnabled('enable_connection');
|
|
});
|
|
});
|