37 lines
1.3 KiB
PHP
37 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Tests\Browser;
|
||
|
|
|
||
|
|
use Laravel\Dusk\Browser;
|
||
|
|
|
||
|
|
trait LoginHelpers
|
||
|
|
{
|
||
|
|
protected function loginAndNavigate(Browser $browser, string $page = '/dashboard'): Browser
|
||
|
|
{
|
||
|
|
// Clear browser session and cookies to start fresh
|
||
|
|
$browser->driver->manage()->deleteAllCookies();
|
||
|
|
|
||
|
|
return $browser->visit('http://dishplanner_app:8000/login')
|
||
|
|
->waitFor('input[id="email"]', 10)
|
||
|
|
->clear('input[id="email"]')
|
||
|
|
->type('input[id="email"]', 'admin@test.com')
|
||
|
|
->clear('input[id="password"]')
|
||
|
|
->type('input[id="password"]', 'password')
|
||
|
|
->press('Login')
|
||
|
|
->waitForLocation('/dashboard', 10) // Wait for successful login redirect
|
||
|
|
->pause(1000) // Brief pause for any initialization
|
||
|
|
->visit('http://dishplanner_app:8000' . $page)
|
||
|
|
->pause(2000); // Let Livewire components initialize
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function loginAndGoToDishes(Browser $browser): Browser
|
||
|
|
{
|
||
|
|
return $this->loginAndNavigate($browser, '/dishes');
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function loginAndGoToUsers(Browser $browser): Browser
|
||
|
|
{
|
||
|
|
return $this->loginAndNavigate($browser, '/users');
|
||
|
|
}
|
||
|
|
}
|