TenantAtlas/tests/Feature/Filament/BackupItemsBulkRemoveTest.php
ahmido 76e10fc404 015-policy-picker-ux (#21)
Replaces the “Add Policies” picker with a modal table (search, pagination, multi-select).
Adds filters: policy type, platform, last synced, ignored, has versions; “Select all” applies to the current filtered results.
Improves identifiers shown (short external id), and fixes has-versions filtering behavior.
Backup set items table: groups row actions (View policy / Remove) into an action group.
Adds bulk action to remove multiple backup items at once.
Updates/adds tests covering the picker table bulk add and backup items bulk remove.

Co-authored-by: Ahmed Darrazi <ahmeddarrazi@adsmac.local>
Reviewed-on: #21
2026-01-02 13:59:15 +00: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]);
});