TenantAtlas/apps/platform/tests/Feature/Filament/Spec374DiagnosticEntrypointTest.php
ahmido 0a1ecf99c9 feat(ui): implement diagnostic entry point consolidation (#445)
Applied diagnostic surface contract rules to Audit Log inspect modal and Support Diagnostics action context, consolidating raw diagnostic data into safe modals according to Spec 374.

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #445
2026-06-13 01:16:00 +00:00

145 lines
5.7 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Pages\EnvironmentDashboard;
use App\Filament\Pages\EnvironmentDiagnostics;
use App\Support\ManagedEnvironmentLinks;
use App\Support\Ui\ActionSurface\ActionSurfaceExemptions;
use App\Support\Ui\ActionSurface\Enums\ActionSurfaceSlot;
use Filament\Actions\Action;
use Filament\Actions\ActionGroup;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Features\SupportTesting\Testable;
use Livewire\Livewire;
uses(RefreshDatabase::class);
/**
* @return array{0: \App\Models\User, 1: \App\Models\ManagedEnvironment, 2: Testable}
*/
function spec374DashboardComponent(): array
{
[$user, $tenant] = createUserWithTenant(role: 'owner', workspaceRole: 'manager');
test()->actingAs($user);
setAdminEnvironmentContext($tenant);
bindFailHardGraphClient();
return [
$user,
$tenant,
Livewire::actingAs($user)->test(EnvironmentDashboard::class),
];
}
/**
* @return array<Action|ActionGroup>
*/
function spec374DashboardHeaderActions(Testable $component): array
{
$instance = $component->instance();
if ($instance->getCachedHeaderActions() === []) {
$instance->cacheInteractsWithHeaderActions();
}
return $instance->getCachedHeaderActions();
}
/**
* @return list<string>
*/
function spec374DashboardPrimaryActionNames(Testable $component): array
{
return collect(spec374DashboardHeaderActions($component))
->reject(static fn ($action): bool => $action instanceof ActionGroup)
->map(static fn ($action): ?string => $action instanceof Action ? $action->getName() : null)
->filter()
->values()
->all();
}
/**
* @return list<string>
*/
function spec374DashboardMoreActionNames(Testable $component): array
{
$moreGroup = collect(spec374DashboardHeaderActions($component))
->first(static fn ($action): bool => $action instanceof ActionGroup && in_array($action->getLabel(), ['More', 'Mehr'], true));
return collect($moreGroup?->getActions() ?? [])
->map(static fn ($action): ?string => $action instanceof Action ? $action->getName() : null)
->filter()
->values()
->all();
}
it('keeps support diagnostics as the dashboard quick diagnostics entrypoint', function (): void {
[, $tenant, $component] = spec374DashboardComponent();
$component
->assertActionVisible('openSupportDiagnostics')
->assertActionEnabled('openSupportDiagnostics')
->assertActionExists('openSupportDiagnostics', fn (Action $action): bool => $action->getLabel() === 'Open support diagnostics')
->mountAction('openSupportDiagnostics')
->assertMountedActionModalSee('Support diagnostics')
->assertMountedActionModalSee('Quick support context')
->assertMountedActionModalSee('Recommended first check')
->assertMountedActionModalSee('Redacted support view')
->assertMountedActionModalSee('Environment context')
->assertMountedActionModalSee('Support scope')
->assertMountedActionModalDontSee('Boundary')
->assertMountedActionModalDontSee('Repair diagnostics');
expect(spec374DashboardPrimaryActionNames($component))
->not->toContain('openSupportDiagnostics')
->not->toContain('openRepairDiagnostics')
->and(spec374DashboardMoreActionNames($component))
->toContain('openSupportDiagnostics')
->not->toContain('openRepairDiagnostics')
->and(ManagedEnvironmentLinks::diagnosticsUrl($tenant))->toEndWith('/diagnostics');
});
it('frames the direct diagnostics route as repair-only in the no-action state', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner', workspaceRole: 'manager');
$this->actingAs($user);
setAdminEnvironmentContext($tenant);
bindFailHardGraphClient();
Livewire::test(EnvironmentDiagnostics::class)
->assertSee('Repair diagnostics')
->assertSee('Checks supported TenantPilot access and membership repair conditions only')
->assertSee('No repair diagnostics are active')
->assertSee('No supported access or membership repair is active')
->assertSee('not a generic environment health hub')
->assertSee('Use Open support diagnostics')
->assertActionVisible('openSupportDiagnostics')
->assertActionEnabled('openSupportDiagnostics')
->assertActionExists('openSupportDiagnostics', fn (Action $action): bool => $action->getLabel() === 'Open support diagnostics')
->assertDontSee('All good')
->assertDontSee('No known issues detected')
->assertDontSee('provider connection blocked')
->assertActionHidden('bootstrapOwner')
->assertActionHidden('mergeDuplicateMemberships')
->mountAction('openSupportDiagnostics')
->assertMountedActionModalSee('Support diagnostics')
->assertMountedActionModalSee('Recommended first check')
->assertMountedActionModalSee('Redacted support view')
->assertMountedActionModalSee('Support scope')
->assertMountedActionModalDontSee('Boundary')
->assertMountedActionModalDontSee('default-redacted');
});
it('keeps repair diagnostics action-surface metadata aligned with the rendered noun', function (): void {
$surface = ActionSurfaceExemptions::spec193MonitoringSurface(EnvironmentDiagnostics::class);
$declaration = EnvironmentDiagnostics::actionSurfaceDeclaration();
expect($surface['canonicalNoun'] ?? null)->toBe('Repair diagnostics')
->and($surface['exceptionReason'] ?? null)->toContain('membership/access repair surface')
->and((string) ($declaration->exemption(ActionSurfaceSlot::InspectAffordance)?->reason ?? ''))
->toContain('Repair diagnostics')
->toContain('singleton repair diagnostics surface');
});