TenantAtlas/tests/Feature/TenantReview/TenantReviewUiContractTest.php
ahmido 807d574d31 feat: add tenant governance aggregate contract and action surface follow-ups (#199)
## Summary
- amend the operator UI constitution and related SpecKit templates for the new UI/UX governance rules
- add Spec 168 artifacts plus the tenant governance aggregate implementation used by the tenant dashboard, banner, and baseline compare landing surfaces
- normalize Filament action surfaces around clickable-row inspection, grouped secondary actions, and explicit action-surface declarations across enrolled resources and pages
- fix post-suite regressions in membership cache priming, finding workflow state refresh, tenant review derived-state invalidation, and tenant-bound backup-set related navigation

## Commit Series
- `docs: amend operator UI constitution`
- `spec: add tenant governance aggregate contract`
- `feat: add tenant governance aggregate contract`
- `refactor: normalize filament action surfaces`
- `fix: resolve post-suite state regressions`

## Testing
- `vendor/bin/sail artisan test --compact`
- Result: `3176 passed, 8 skipped (17384 assertions)`

## Notes
- Livewire v4 / Filament v5 stack remains unchanged
- no provider registration changes; `bootstrap/providers.php` remains the relevant location
- no new global-search resources or asset-registration changes in this branch

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #199
2026-03-29 21:14:17 +00:00

133 lines
5.4 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Pages\Reviews\ReviewRegister;
use App\Filament\Resources\TenantReviewResource;
use App\Filament\Resources\TenantReviewResource\Pages\ListTenantReviews;
use App\Filament\Resources\TenantReviewResource\Pages\ViewTenantReview;
use App\Models\Tenant;
use App\Models\TenantReview;
use App\Models\User;
use App\Services\TenantReviews\TenantReviewLifecycleService;
use App\Support\Workspaces\WorkspaceContext;
use Livewire\Livewire;
it('disables tenant-review global search while keeping the view page available for resource inspection', function (): void {
$reflection = new ReflectionClass(TenantReviewResource::class);
expect($reflection->getStaticPropertyValue('isGloballySearchable'))->toBeFalse()
->and(array_keys(TenantReviewResource::getPages()))->toContain('view');
});
it('keeps tenant review list and canonical register empty states to a single CTA', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner');
$this->actingAs($user);
setTenantPanelContext($tenant);
Livewire::actingAs($user)
->test(ListTenantReviews::class)
->assertTableEmptyStateActionsExistInOrder(['create_first_review'])
->assertSee('No tenant reviews yet')
->mountAction('create_review')
->assertActionMounted('create_review');
setAdminPanelContext();
session()->put(WorkspaceContext::SESSION_KEY, (int) $tenant->workspace_id);
Livewire::actingAs($user)
->test(ReviewRegister::class)
->searchTable('no-such-review')
->assertTableEmptyStateActionsExistInOrder(['clear_filters_empty'])
->assertSee('No review records match this view');
});
it('keeps tenant review list inspection on row click and reserves the row action for executive export', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner');
$review = composeTenantReviewForTest($tenant, $user);
$this->actingAs($user);
setTenantPanelContext($tenant);
$livewire = Livewire::actingAs($user)
->test(ListTenantReviews::class)
->assertCanSeeTableRecords([$review]);
$table = $livewire->instance()->getTable();
$rowActionNames = collect($table->getActions())
->map(static fn ($action): ?string => $action->getName())
->filter()
->values()
->all();
expect($rowActionNames)->toEqualCanonicalizing(['export_executive_pack'])
->and($table->getBulkActions())->toBeEmpty()
->and($table->getRecordUrl($review))->toBe(TenantReviewResource::tenantScopedUrl('view', ['record' => $review], $tenant));
});
it('requires confirmation for destructive tenant-review actions and preserves disabled management visibility for readonly users', function (): void {
$tenant = Tenant::factory()->create();
[$owner, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner');
[$readonly] = createUserWithTenant(tenant: $tenant, user: User::factory()->create(), role: 'readonly');
$review = composeTenantReviewForTest($tenant, $owner);
setTenantPanelContext($tenant);
Livewire::actingAs($readonly)
->test(ViewTenantReview::class, ['record' => $review->getKey()])
->assertActionVisible('refresh_review')
->assertActionDisabled('refresh_review')
->assertActionVisible('publish_review')
->assertActionDisabled('publish_review')
->assertActionVisible('export_executive_pack')
->assertActionDisabled('export_executive_pack')
->assertActionVisible('archive_review')
->assertActionDisabled('archive_review');
Livewire::actingAs($owner)
->test(ViewTenantReview::class, ['record' => $review->getKey()])
->mountAction('refresh_review')
->assertActionMounted('refresh_review');
Livewire::actingAs($owner)
->test(ViewTenantReview::class, ['record' => $review->getKey()])
->mountAction('publish_review')
->assertActionMounted('publish_review');
$published = app(TenantReviewLifecycleService::class)->publish($review, $owner);
Livewire::actingAs($owner)
->test(ViewTenantReview::class, ['record' => $published->getKey()])
->mountAction('archive_review')
->assertActionMounted('archive_review');
});
it('shows publication truth and next-step guidance when a review is not yet publishable', function (): void {
$tenant = Tenant::factory()->create();
[$owner, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner');
$snapshot = seedTenantReviewEvidence($tenant);
$review = TenantReview::query()->create([
'tenant_id' => (int) $tenant->getKey(),
'workspace_id' => (int) $tenant->workspace_id,
'evidence_snapshot_id' => (int) $snapshot->getKey(),
'initiated_by_user_id' => (int) $owner->getKey(),
'status' => 'draft',
'completeness_state' => 'complete',
'summary' => [
'publish_blockers' => ['Review the approval note before publication.'],
'section_state_counts' => ['complete' => 6, 'partial' => 0, 'missing' => 0, 'stale' => 0],
],
'fingerprint' => hash('sha256', 'tenant-review-ui-contract'),
'generated_at' => now(),
]);
$this->actingAs($owner)
->get(TenantReviewResource::tenantScopedUrl('view', ['record' => $review], $tenant))
->assertOk()
->assertSee('Artifact truth')
->assertSee('Publication blocked')
->assertSee('Resolve the review blockers before publication');
});