TenantAtlas/apps/platform/tests/Feature/Filament/PolicyProviderMissingUiTest.php
ahmido feeaadd5ad feat: add provider-missing policy visibility and restore continuity (#316)
## Summary
- separate provider-missing policy presence from local ignore semantics by introducing `missing_from_provider_at`
- update policy, backup, and restore surfaces so current-state capture stays honest while historical restore continuity remains available
- add focused sync, Filament, backup, restore, localization, and badge coverage for the new provider-missing behavior

## Scope
- policy sync and model truth
- policy resource visibility, badges, labels, and action gating
- backup/export eligibility and restore continuity messaging
- spec 261 artifacts and focused tests

## Validation
- feature-specific Pest coverage is included in the branch
- validation was not re-run as part of this commit/push/PR handoff

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #316
2026-05-01 20:18:27 +00:00

76 lines
2.5 KiB
PHP

<?php
use App\Filament\Resources\PolicyResource\Pages\ListPolicies;
use App\Models\Policy;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\App;
use Livewire\Livewire;
uses(RefreshDatabase::class);
it('filters active, ignored, and provider-missing policy states distinctly', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner');
$this->actingAs($user);
$tenant->makeCurrent();
Filament::setTenant($tenant, true);
$active = Policy::factory()->create([
'tenant_id' => $tenant->getKey(),
'display_name' => 'Active policy',
'ignored_at' => null,
'missing_from_provider_at' => null,
]);
$missing = Policy::factory()->create([
'tenant_id' => $tenant->getKey(),
'display_name' => 'Provider missing policy',
'ignored_at' => null,
'missing_from_provider_at' => now()->subHour(),
]);
$combined = Policy::factory()->create([
'tenant_id' => $tenant->getKey(),
'display_name' => 'Ignored missing policy',
'ignored_at' => now()->subDay(),
'missing_from_provider_at' => now()->subHour(),
]);
Livewire::actingAs($user)
->test(ListPolicies::class)
->assertCanSeeTableRecords([$active])
->assertCanNotSeeTableRecords([$missing, $combined])
->set('tableFilters.visibility.value', 'provider_missing')
->assertCanSeeTableRecords([$missing, $combined])
->assertCanNotSeeTableRecords([$active])
->set('tableFilters.visibility.value', 'ignored')
->assertCanSeeTableRecords([$combined])
->assertCanNotSeeTableRecords([$active, $missing]);
});
it('keeps provider-missing sync retry available and current export disabled', function (): void {
App::setLocale('en');
[$user, $tenant] = createUserWithTenant(role: 'owner');
$this->actingAs($user);
$tenant->makeCurrent();
Filament::setTenant($tenant, true);
$policy = Policy::factory()->create([
'tenant_id' => $tenant->getKey(),
'display_name' => 'Provider missing policy',
'ignored_at' => null,
'missing_from_provider_at' => now()->subHour(),
]);
Livewire::actingAs($user)
->test(ListPolicies::class)
->set('tableFilters.visibility.value', 'provider_missing')
->assertCanSeeTableRecords([$policy])
->assertSee(__('localization.policy.badges.source_unavailable'))
->assertTableActionEnabled('sync', $policy)
->assertTableActionDisabled('export', $policy);
});