71 lines
2.4 KiB
PHP
71 lines
2.4 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)
|
|
->assertSee($title)
|
|
->assertScript('document.querySelectorAll(".wms-page-hero").length === 1');
|
|
}
|
|
|
|
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(<<<JS
|
|
const targetPath = '{$path}';
|
|
const links = Array.from(document.querySelectorAll('.wms-sidebar a'));
|
|
const link = links.find((item) => {
|
|
try {
|
|
return new URL(item.href, window.location.origin).pathname === targetPath;
|
|
} catch (error) {
|
|
return false;
|
|
}
|
|
});
|
|
if (link) {
|
|
link.click();
|
|
} else {
|
|
window.location.href = targetPath;
|
|
}
|
|
JS);
|
|
|
|
$browser->waitForLocation($path, 10);
|
|
}
|
|
|
|
protected function openMobileNavigation(Browser $browser): void
|
|
{
|
|
$browser->resize(390, 844)
|
|
->waitFor('.wms-mobile-header', 10)
|
|
->assertVisible('.wms-mobile-header')
|
|
->assertVisible('[data-wms-mobile-open]')
|
|
->click('[data-wms-mobile-open]')
|
|
->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();')
|
|
->waitUntil('document.documentElement.dataset.wmsMobileSidebar !== "open"', 10)
|
|
->assertAttribute('[data-wms-mobile-open]', 'aria-expanded', 'false');
|
|
}
|
|
}
|