60 lines
2.0 KiB
PHP
60 lines
2.0 KiB
PHP
<?php
|
|
|
|
use App\Filament\Resources\PolicyResource\Pages\ListPolicies;
|
|
use App\Support\Rbac\UiTooltips;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Support\Facades\Queue;
|
|
use Livewire\Livewire;
|
|
|
|
/**
|
|
* Tests for destructive action behavior in UiEnforcement
|
|
*
|
|
* These tests verify that:
|
|
* - Destructive actions are configured with confirmation modal
|
|
* - Modal heading/description are set correctly
|
|
* - Action only executes after confirmation
|
|
*/
|
|
describe('Destructive actions require confirmation', function () {
|
|
beforeEach(function () {
|
|
Queue::fake();
|
|
bindFailHardGraphClient();
|
|
});
|
|
|
|
it('mounts sync action for modal confirmation', function () {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
// mountAction shows the confirmation modal
|
|
// assertActionMounted confirms it was mounted (awaiting confirmation)
|
|
Livewire::test(ListPolicies::class)
|
|
->assertActionVisible('sync')
|
|
->assertActionEnabled('sync')
|
|
->mountAction('sync')
|
|
->assertActionMounted('sync');
|
|
});
|
|
|
|
it('does not execute destructive action without calling confirm', function () {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
// Mount but don't call - verify no side effects
|
|
Livewire::test(ListPolicies::class)
|
|
->mountAction('sync');
|
|
|
|
// No job should be dispatched yet
|
|
Queue::assertNothingPushed();
|
|
});
|
|
|
|
it('has confirmation modal configured with correct title', function () {
|
|
// Verify UiTooltips constants are set correctly
|
|
expect(UiTooltips::DESTRUCTIVE_CONFIRM_TITLE)->toBe('Are you sure?');
|
|
expect(UiTooltips::DESTRUCTIVE_CONFIRM_DESCRIPTION)->toBe('This action cannot be undone.');
|
|
});
|
|
});
|