TenantAtlas/apps/platform/tests/Feature/Filament/Spec344CustomerReviewWorkspaceDensityTest.php
Ahmed Darrazi 0e9af1de55
Some checks failed
PR Fast Feedback / fast-feedback (pull_request) Failing after 3m43s
polish: customer-review workspace density and hierarchy (spec 344)
Refactored the customer-review workspace to emphasize the Operator Summary, tightening the hierarchy. Readiness flow and acknowledgment details were adjusted, and supporting proof panels moved to secondary visual weight.
2026-06-02 02:27:58 +02:00

109 lines
5.0 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Pages\Reviews\CustomerReviewWorkspace;
use App\Models\EnvironmentReview;
use App\Models\EvidenceSnapshot;
use App\Models\ManagedEnvironment;
use App\Models\User;
use App\Support\EnvironmentReviewStatus;
use App\Support\Workspaces\WorkspaceContext;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
uses(RefreshDatabase::class);
it('prioritizes acknowledgement inside the operator summary before supporting details', function (): void {
$environment = ManagedEnvironment::factory()->create(['name' => 'Spec344 Operator Summary']);
[$user, $environment] = createUserWithTenant(tenant: $environment, role: 'owner', workspaceRole: 'manager');
$snapshot = seedEnvironmentReviewEvidence($environment, findingCount: 0, driftCount: 0);
spec344CreatePublishedReview($environment, $user, $snapshot);
$this->actingAs($user);
setAdminPanelContext();
session()->put(WorkspaceContext::SESSION_KEY, (int) $environment->workspace_id);
$component = Livewire::actingAs($user)->test(CustomerReviewWorkspace::class)
->assertSee(__('localization.review.review_acknowledgement'));
$html = $component->html();
expect($html)->toContain('data-testid="customer-review-operator-summary"')
->and($html)->toContain('data-testid="customer-review-supporting-details"');
$operatorSummaryStart = strpos($html, 'data-testid="customer-review-operator-summary"');
$supportingDetailsStart = strpos($html, 'data-testid="customer-review-supporting-details"');
expect($operatorSummaryStart)->not->toBeFalse()
->and($supportingDetailsStart)->not->toBeFalse()
->and($operatorSummaryStart)->toBeLessThan($supportingDetailsStart);
$operatorSummaryHtml = substr($html, $operatorSummaryStart, $supportingDetailsStart - $operatorSummaryStart);
expect($operatorSummaryHtml)->toContain('data-testid="customer-review-decision-card"')
->and($operatorSummaryHtml)->toContain('data-testid="customer-review-acknowledgement-card"')
->and($operatorSummaryHtml)->toContain('data-testid="customer-review-findings-summary"');
$acknowledgementCardPosition = strpos($html, 'data-testid="customer-review-acknowledgement-card"');
$readinessFlowPosition = strpos($html, 'data-testid="customer-review-readiness-flow"');
expect($acknowledgementCardPosition)->not->toBeFalse()
->and($readinessFlowPosition)->not->toBeFalse()
->and($acknowledgementCardPosition)->toBeLessThan($readinessFlowPosition);
expect($html)->toContain('data-testid="customer-review-diagnostics"')
->and($html)->not->toContain('data-testid="customer-review-diagnostics" open');
});
it('shows the environment filter chip when environment_id is present', function (): void {
$environment = ManagedEnvironment::factory()->create(['name' => 'Spec344 Environment Filter']);
[$user, $environment] = createUserWithTenant(tenant: $environment, role: 'owner', workspaceRole: 'manager');
$snapshot = seedEnvironmentReviewEvidence($environment, findingCount: 0, driftCount: 0);
spec344CreatePublishedReview($environment, $user, $snapshot);
$this->actingAs($user)
->withSession([WorkspaceContext::SESSION_KEY => (int) $environment->workspace_id])
->get(CustomerReviewWorkspace::environmentFilterUrl($environment))
->assertOk()
->assertSee('Environment filter:')
->assertSee('Spec344 Environment Filter')
->assertDontSee('/admin/t', false)
->assertDontSee('tenant_id=', false);
});
it('disables the acknowledgement action when the actor lacks acknowledge permissions', function (): void {
$environment = ManagedEnvironment::factory()->create(['name' => 'Spec344 Ack Disabled']);
[$publisher, $environment] = createUserWithTenant(tenant: $environment, role: 'owner', workspaceRole: 'manager');
[$actor] = createUserWithTenant(tenant: $environment, role: 'readonly');
$snapshot = seedEnvironmentReviewEvidence($environment, findingCount: 0, driftCount: 0);
spec344CreatePublishedReview($environment, $publisher, $snapshot);
$this->actingAs($actor);
setAdminPanelContext();
session()->put(WorkspaceContext::SESSION_KEY, (int) $environment->workspace_id);
$component = Livewire::actingAs($actor)->test(CustomerReviewWorkspace::class);
$payload = $component->instance()->latestReviewConsumptionPayload();
expect(data_get($payload, 'acknowledgement.action_name'))->toBe('acknowledgeReview')
->and(data_get($payload, 'acknowledgement.action_disabled'))->toBeTrue();
});
function spec344CreatePublishedReview(ManagedEnvironment $environment, User $user, EvidenceSnapshot $snapshot): EnvironmentReview
{
$review = composeEnvironmentReviewForTest($environment, $user, $snapshot);
$review->forceFill([
'status' => EnvironmentReviewStatus::Published->value,
'generated_at' => now(),
'published_at' => now(),
'published_by_user_id' => (int) $user->getKey(),
])->save();
return $review->refresh();
}