TenantAtlas/tests/Feature/Filament/BackupItemsBulkRemoveTest.php
Ahmed Darrazi 5f1f3b0bfd feat: improve backup policy picker UX
- Replace Add Policies picker with a modal table (filters + multi-select + select-all filtered)

- Add has-versions filter and external id short display

- Group row actions and add bulk remove for backup items

- Add/adjust tests for picker and bulk remove
2026-01-02 14:58:10 +01:00

75 lines
2.3 KiB
PHP

<?php
use App\Filament\Resources\BackupSetResource\RelationManagers\BackupItemsRelationManager;
use App\Models\BackupItem;
use App\Models\BackupSet;
use App\Models\Policy;
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
uses(RefreshDatabase::class);
test('backup items table can bulk remove selected items', function () {
$tenant = Tenant::factory()->create();
$tenant->makeCurrent();
$user = User::factory()->create();
$backupSet = BackupSet::factory()->create([
'tenant_id' => $tenant->id,
'name' => 'Test backup',
'item_count' => 0,
]);
$policyA = Policy::factory()->create([
'tenant_id' => $tenant->id,
'ignored_at' => null,
'last_synced_at' => now(),
]);
$policyB = Policy::factory()->create([
'tenant_id' => $tenant->id,
'ignored_at' => null,
'last_synced_at' => now(),
]);
$itemA = BackupItem::factory()->create([
'tenant_id' => $tenant->id,
'backup_set_id' => $backupSet->id,
'policy_id' => $policyA->id,
'policy_identifier' => $policyA->external_id,
'policy_type' => $policyA->policy_type,
'platform' => $policyA->platform,
]);
$itemB = BackupItem::factory()->create([
'tenant_id' => $tenant->id,
'backup_set_id' => $backupSet->id,
'policy_id' => $policyB->id,
'policy_identifier' => $policyB->external_id,
'policy_type' => $policyB->policy_type,
'platform' => $policyB->platform,
]);
$backupSet->update(['item_count' => $backupSet->items()->count()]);
expect($backupSet->refresh()->item_count)->toBe(2);
Livewire::actingAs($user)
->test(BackupItemsRelationManager::class, [
'ownerRecord' => $backupSet,
'pageClass' => \App\Filament\Resources\BackupSetResource\Pages\ViewBackupSet::class,
])
->callTableBulkAction('bulk_remove', collect([$itemA, $itemB]))
->assertHasNoTableBulkActionErrors();
$backupSet->refresh();
expect($backupSet->items()->count())->toBe(0);
expect($backupSet->item_count)->toBe(0);
$this->assertSoftDeleted('backup_items', ['id' => $itemA->id]);
$this->assertSoftDeleted('backup_items', ['id' => $itemB->id]);
});