browser()->timeout(60_000); function spec369BrowserScreenshotName(string $name): string { return 'spec369-baseline-profile-decision-view-'.$name; } function spec369CopyBrowserScreenshot(string $name): void { $filename = spec369BrowserScreenshotName($name).'.png'; $source = base_path('tests/Browser/Screenshots/'.$filename); $targetDirectory = repo_path('specs/369-baseline-profile-decision-view/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.$name.'.png'); } } it('smokes the Baseline Profile decision-first detail view in Spec369', function (): void { $this->withoutVite(); [$user, $tenant] = createUserWithTenant(role: 'owner'); [$profile] = seedActiveBaselineForTenant($tenant); $profile->forceFill([ 'name' => 'Spec369 Browser Decision Baseline', 'capture_mode' => BaselineCaptureMode::Opportunistic->value, ])->save(); $this->actingAs($user)->withSession([ WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id, ]); session()->put(WorkspaceContext::SESSION_KEY, (int) $tenant->workspace_id); $path = parse_url( BaselineProfileResource::getUrl('view', ['record' => $profile], panel: 'admin'), PHP_URL_PATH, ); $page = visit(is_string($path) ? $path : '/admin/baseline-profiles/'.$profile->getKey()) ->waitForText('Decision') ->assertSee('Ready to compare') ->assertSee('Assignment signal') ->assertSee('Assigned to 1 environment with compare access.') ->assertSee('Dominant next action') ->assertSee('Compare now') ->assertSee('Related context') ->assertScript( "(() => { const text = document.body.innerText; return text.indexOf('Decision') !== -1 && text.indexOf('Decision') < text.indexOf('Normalization lineage') && text.indexOf('Decision') < text.indexOf('Metadata') && text.indexOf('Ready to compare') < text.indexOf('Scope'); })()", true, ) ->assertNoJavaScriptErrors() ->assertNoConsoleLogs(); $page->screenshot(true, spec369BrowserScreenshotName('decision-first-detail')); spec369CopyBrowserScreenshot('decision-first-detail'); });