54 lines
1.7 KiB
PHP
54 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Browser\Layout;
|
|
|
|
use App\Models\User;
|
|
use Laravel\Dusk\Browser;
|
|
use Tests\DuskTestCase;
|
|
|
|
class FixedSidebarScrollTest extends DuskTestCase
|
|
{
|
|
/**
|
|
* Ensure only the main content area scrolls while the desktop sidebar stays fixed.
|
|
*/
|
|
public function test_only_main_content_area_scrolls_while_sidebar_remains_fixed(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$this->browse(function (Browser $browser) use ($user): void {
|
|
$browser
|
|
->loginAs($user)
|
|
->visit('/dashboard')
|
|
->waitFor('[data-test="desktop-sidebar"]')
|
|
->waitFor('[data-test="main-content"]');
|
|
|
|
$browser->script(<<<'JS'
|
|
const main = document.querySelector('[data-test="main-content"]');
|
|
const filler = document.createElement('div');
|
|
|
|
filler.setAttribute('data-test', 'scroll-filler');
|
|
filler.style.height = '2200px';
|
|
|
|
main.appendChild(filler);
|
|
main.scrollTop = 900;
|
|
JS);
|
|
|
|
$sidebarTop = $browser->script(
|
|
'return Math.round(document.querySelector("[data-test=\"desktop-sidebar\"]").getBoundingClientRect().top);'
|
|
)[0];
|
|
|
|
$bodyScrollTop = $browser->script(
|
|
'return Math.round(document.scrollingElement.scrollTop);'
|
|
)[0];
|
|
|
|
$mainScrollTop = $browser->script(
|
|
'return Math.round(document.querySelector("[data-test=\"main-content\"]").scrollTop);'
|
|
)[0];
|
|
|
|
$this->assertSame(0, $sidebarTop);
|
|
$this->assertSame(0, $bodyScrollTop);
|
|
$this->assertGreaterThan(0, $mainScrollTop);
|
|
});
|
|
}
|
|
}
|