TenantAtlas/tests/Feature/TenantReview/TenantReviewUiContractTest.php
ahmido a4f2629493 feat: add tenant review layer (#185)
## Summary
- add the tenant review domain with tenant-scoped review library, canonical workspace review register, lifecycle actions, and review-derived executive pack export
- extend review pack, operations, audit, capability, and badge infrastructure to support review composition, publication, export, and recurring review cycles
- add product backlog and audit documentation updates for tenant review and semantic-clarity follow-up candidates

## Testing
- `vendor/bin/sail bin pint --dirty --format agent`
- `vendor/bin/sail artisan test --compact --filter="TenantReview"`
- `CI=1 vendor/bin/sail artisan test --compact`

## Notes
- Livewire v4+ compliant via existing Filament v5 stack
- panel providers remain in `bootstrap/providers.php` via existing Laravel 12 structure; no provider registration moved to `bootstrap/app.php`
- `TenantReviewResource` is not globally searchable, so the Filament edit/view global-search constraint does not apply
- destructive review actions use action handlers with confirmation and policy enforcement

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #185
2026-03-21 22:03:01 +00:00

81 lines
3.3 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\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('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');
});