Files
WMS/tests/Browser/Concerns/InteractsWithWmsBrowser.php
T
2026-06-15 11:59:41 +01:00

82 lines
2.5 KiB
PHP

<?php
namespace Tests\Browser\Concerns;
use Laravel\Dusk\Browser;
trait InteractsWithWmsBrowser
{
protected function assertSingleProfessionalHeader(Browser $browser, string $title): void
{
$browser->waitFor('.wms-page-hero', 10)
->assertScript('document.querySelectorAll(".wms-page-hero").length === 1');
if ($title !== '') {
$browser->assertSee($title);
}
}
protected function assertSingleProfessionalHeaderExists(Browser $browser): void
{
$browser->waitFor('.wms-page-hero', 10)
->assertScript('document.querySelectorAll(".wms-page-hero").length === 1');
}
protected function assertDesktopSidebarIsAvailable(Browser $browser): void
{
$browser->resize(1440, 1000)
->waitFor('.wms-sidebar', 10)
->assertVisible('.wms-sidebar')
->assertPresent('[data-wms-sidebar-toggle]')
->assertVisible('.wms-content');
}
protected function clickSidebarHref(Browser $browser, string $path): void
{
$browser->script(sprintf(
<<<'JS'
const expectedPath = %s;
const links = Array.from(document.querySelectorAll('a'));
const link = links.find((candidate) => {
const href = candidate.getAttribute('href') || '';
try {
return new URL(href, window.location.origin).pathname === expectedPath;
} catch (error) {
return href === expectedPath || href.endsWith(expectedPath);
}
});
if (link) {
link.click();
} else {
window.location.href = expectedPath;
}
JS,
json_encode($path, JSON_THROW_ON_ERROR)
));
$browser->waitForLocation($path, 15);
}
protected function openMobileNavigation(Browser $browser): void
{
$browser->resize(390, 844)
->waitFor('.wms-mobile-header', 10)
->assertVisible('.wms-mobile-header')
->assertPresent('[data-wms-mobile-open]');
$browser->script('document.querySelector("[data-wms-mobile-open]")?.click();');
$browser->waitUntil('document.documentElement.dataset.wmsMobileSidebar === "open"', 10)
->assertAttribute('[data-wms-mobile-open]', 'aria-expanded', 'true');
}
protected function closeMobileNavigation(Browser $browser): void
{
$browser->script('document.querySelector("[data-wms-mobile-close]")?.click();');
$browser->waitUntil('document.documentElement.dataset.wmsMobileSidebar !== "open"', 10)
->assertAttribute('[data-wms-mobile-open]', 'aria-expanded', 'false');
}
}