Automated PR created by Codex via Gitea API. Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #467
180 lines
6.2 KiB
PHP
180 lines
6.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\OperationRun;
|
|
use App\Models\PlatformUser;
|
|
use App\Support\Auth\PlatformCapabilities;
|
|
use App\Support\OperationRunOutcome;
|
|
use App\Support\OperationRunStatus;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
pest()->browser()->timeout(60_000);
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('Spec396 smokes the authenticated TenantPilot System panel surfaces', function (): void {
|
|
$platformUser = PlatformUser::factory()->create([
|
|
'capabilities' => [
|
|
PlatformCapabilities::ACCESS_SYSTEM_PANEL,
|
|
PlatformCapabilities::CONSOLE_VIEW,
|
|
PlatformCapabilities::OPERATIONS_VIEW,
|
|
],
|
|
'is_active' => true,
|
|
]);
|
|
|
|
auth('web')->logout();
|
|
$this->flushSession();
|
|
$this->actingAs($platformUser, 'platform');
|
|
|
|
visit('/system')
|
|
->resize(1440, 1100)
|
|
->waitForText('TenantPilot System')
|
|
->assertTitleContains('TenantPilot System')
|
|
->assertSee('Ready')
|
|
->assertScript(<<<'JS'
|
|
() => {
|
|
const hasVisibleDirectText = (needle) => Array.from(document.querySelectorAll('body *')).some((element) => {
|
|
const style = window.getComputedStyle(element);
|
|
const rect = element.getBoundingClientRect();
|
|
const isVisible = style.display !== 'none'
|
|
&& style.visibility !== 'hidden'
|
|
&& Number(style.opacity) !== 0
|
|
&& rect.width > 0
|
|
&& rect.height > 0
|
|
&& rect.bottom > 0
|
|
&& rect.right > 0
|
|
&& rect.top < window.innerHeight
|
|
&& rect.left < window.innerWidth;
|
|
|
|
return isVisible
|
|
&& Array.from(element.childNodes).some((node) => node.nodeType === Node.TEXT_NODE && node.textContent?.includes(needle));
|
|
});
|
|
|
|
return ! hasVisibleDirectText('System dashboard');
|
|
}
|
|
JS)
|
|
->assertDontSee('All systems healthy')
|
|
->assertDontSee('Healthy')
|
|
->assertDontSee('Laravel')
|
|
->assertDontSee('Laravel Debugbar')
|
|
->assertDontSee('Vite Error')
|
|
->assertDontSee('Exception')
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoConsoleLogs()
|
|
->screenshot(true, spec396BrowserScreenshot('001-system-dashboard'));
|
|
spec396BrowserCopyScreenshot('001-system-dashboard');
|
|
|
|
visit('/system')
|
|
->resize(778, 784)
|
|
->waitForText('TenantPilot System')
|
|
->assertScript(<<<'JS'
|
|
() => {
|
|
const trigger = document.querySelector('[data-testid="tenantpilot-locale-switcher-trigger"]');
|
|
|
|
if (! trigger) {
|
|
return false;
|
|
}
|
|
|
|
const rect = trigger.getBoundingClientRect();
|
|
|
|
return trigger.textContent?.trim() === 'EN'
|
|
&& rect.width >= 52
|
|
&& rect.height <= 44;
|
|
}
|
|
JS, true)
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoConsoleLogs();
|
|
|
|
visit('/system/ops/runs')
|
|
->resize(1440, 1100)
|
|
->waitForText('Operations')
|
|
->assertSee('No operations yet')
|
|
->assertDontSee('Laravel Debugbar')
|
|
->assertDontSee('Vite Error')
|
|
->assertDontSee('Exception')
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoConsoleLogs()
|
|
->screenshot(true, spec396BrowserScreenshot('002-system-operations'));
|
|
spec396BrowserCopyScreenshot('002-system-operations');
|
|
|
|
visit('/system/security/access-logs')
|
|
->resize(1440, 1100)
|
|
->waitForText('Access logs')
|
|
->assertSee('No access logs found')
|
|
->assertDontSee('Laravel Debugbar')
|
|
->assertDontSee('Vite Error')
|
|
->assertDontSee('Exception')
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoConsoleLogs()
|
|
->screenshot(true, spec396BrowserScreenshot('003-system-access-logs'));
|
|
spec396BrowserCopyScreenshot('003-system-access-logs');
|
|
|
|
OperationRun::factory()->create([
|
|
'status' => OperationRunStatus::Completed->value,
|
|
'outcome' => OperationRunOutcome::Failed->value,
|
|
'created_at' => now()->subMinutes(10),
|
|
]);
|
|
|
|
visit('/system')
|
|
->resize(1440, 1100)
|
|
->waitForText('Needs attention')
|
|
->assertSee('Needs attention')
|
|
->assertDontSee('All systems healthy')
|
|
->assertDontSee('Warning')
|
|
->assertDontSee('Laravel Debugbar')
|
|
->assertDontSee('Vite Error')
|
|
->assertDontSee('Exception')
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoConsoleLogs();
|
|
});
|
|
|
|
it('Spec396 smokes the TenantPilot System login surface without default framework branding', function (): void {
|
|
auth('web')->logout();
|
|
auth('platform')->logout();
|
|
$this->flushSession();
|
|
|
|
visit('/system/login')
|
|
->resize(1440, 1100)
|
|
->waitForText('TenantPilot System')
|
|
->assertSee('Email')
|
|
->assertDontSee('System dashboard')
|
|
->assertDontSee('Laravel')
|
|
->assertDontSee('Laravel Debugbar')
|
|
->assertDontSee('Vite Error')
|
|
->assertDontSee('Exception')
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoConsoleLogs()
|
|
->screenshot(true, spec396BrowserScreenshot('004-system-login'));
|
|
spec396BrowserCopyScreenshot('004-system-login');
|
|
});
|
|
|
|
function spec396BrowserScreenshot(string $name): string
|
|
{
|
|
return $name;
|
|
}
|
|
|
|
function spec396BrowserCopyScreenshot(string $name): void
|
|
{
|
|
$filename = spec396BrowserScreenshot($name).'.png';
|
|
$source = base_path('tests/Browser/Screenshots/'.$filename);
|
|
$targetDirectory = repo_path('specs/396-system-panel-branding/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);
|
|
}
|
|
}
|