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
121 lines
4.5 KiB
PHP
121 lines
4.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Pages\EnvironmentDashboard;
|
|
use App\Models\ManagedEnvironment;
|
|
use App\Models\User;
|
|
use App\Support\ManagedEnvironmentLinks;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
pest()->browser()->timeout(30_000);
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('Spec374 smokes support and repair diagnostics entrypoints', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner', workspaceRole: 'manager');
|
|
$tenant->forceFill(['name' => 'Spec374 Diagnostics Environment'])->save();
|
|
|
|
$dashboardPath = spec374BrowserPath(EnvironmentDashboard::getUrl(panel: 'admin', tenant: $tenant));
|
|
$repairDiagnosticsPath = spec374BrowserPath(ManagedEnvironmentLinks::diagnosticsUrl($tenant));
|
|
|
|
$page = visit(spec374BrowserLoginUrl($user, $tenant, $dashboardPath))
|
|
->resize(1440, 1100)
|
|
->waitForText($tenant->name)
|
|
->click('[aria-label="More"]')
|
|
->assertSee('Open support diagnostics')
|
|
->assertDontSee('Repair diagnostics')
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoConsoleLogs()
|
|
->screenshot(true, '001-environment-dashboard-diagnostic-entry-after');
|
|
spec374BrowserCopyScreenshot('001-environment-dashboard-diagnostic-entry-after');
|
|
|
|
$page
|
|
->click('Open support diagnostics')
|
|
->waitForText('Support diagnostics')
|
|
->assertSee('Quick support context')
|
|
->assertSee('Recommended first check')
|
|
->assertSee('Redacted support view')
|
|
->assertSee('Environment context')
|
|
->assertSee('Support scope')
|
|
->assertSourceHas('target="_blank"')
|
|
->assertSourceHas('rel="noopener noreferrer"')
|
|
->assertDontSee('Boundary')
|
|
->assertDontSee('Repair diagnostics')
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoConsoleLogs()
|
|
->screenshot(true, '002-support-diagnostics-modal-after');
|
|
spec374BrowserCopyScreenshot('002-support-diagnostics-modal-after');
|
|
|
|
$repairPage = visit($repairDiagnosticsPath)
|
|
->resize(1440, 1100)
|
|
->waitForText('Repair diagnostics')
|
|
->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')
|
|
->assertSee('Open support diagnostics')
|
|
->assertDontSee('Provider connection blocked')
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoConsoleLogs()
|
|
->screenshot(true, '003-environment-repair-diagnostics-after');
|
|
spec374BrowserCopyScreenshot('003-environment-repair-diagnostics-after');
|
|
|
|
$repairPage
|
|
->click('Open support diagnostics')
|
|
->waitForText('Support diagnostics')
|
|
->assertSee('Recommended first check')
|
|
->assertSee('Redacted support view')
|
|
->assertSee('Environment')
|
|
->assertSee('Support scope')
|
|
->assertSourceHas('target="_blank"')
|
|
->assertSourceHas('rel="noopener noreferrer"')
|
|
->assertDontSee('Boundary')
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoConsoleLogs()
|
|
->screenshot(true, '004-environment-repair-diagnostics-support-modal-after');
|
|
spec374BrowserCopyScreenshot('004-environment-repair-diagnostics-support-modal-after');
|
|
});
|
|
|
|
function spec374BrowserLoginUrl(User $user, ManagedEnvironment $tenant, string $redirect): string
|
|
{
|
|
return route('admin.local.smoke-login', [
|
|
'email' => $user->email,
|
|
'tenant' => $tenant->external_id,
|
|
'workspace' => $tenant->workspace->slug,
|
|
'redirect' => $redirect,
|
|
]);
|
|
}
|
|
|
|
function spec374BrowserPath(string $url): string
|
|
{
|
|
$path = parse_url($url, PHP_URL_PATH) ?: '/admin';
|
|
$query = parse_url($url, PHP_URL_QUERY);
|
|
|
|
return is_string($query) && $query !== '' ? $path.'?'.$query : $path;
|
|
}
|
|
|
|
function spec374BrowserCopyScreenshot(string $name): void
|
|
{
|
|
$filename = $name.'.png';
|
|
$source = base_path('tests/Browser/Screenshots/'.$filename);
|
|
$targetDirectory = repo_path('specs/374-diagnostic-entry-point-support-diagnostics-consolidation/artifacts/screenshots');
|
|
|
|
if (! is_dir($targetDirectory)) {
|
|
@mkdir($targetDirectory, 0755, true);
|
|
}
|
|
|
|
if (! is_file($source)) {
|
|
$source = \Pest\Browser\Support\Screenshot::path($filename);
|
|
}
|
|
|
|
for ($attempt = 0; $attempt < 10 && ! is_file($source); $attempt++) {
|
|
usleep(100_000);
|
|
clearstatcache(true, $source);
|
|
}
|
|
|
|
if (is_file($source) && is_dir($targetDirectory) && is_writable($targetDirectory)) {
|
|
@copy($source, $targetDirectory.DIRECTORY_SEPARATOR.$filename);
|
|
}
|
|
}
|