56 - Add browser test for logout

This commit is contained in:
myrmidex 2026-08-20 21:45:28 +02:00
parent c3a5532028
commit 95c5a72294
2 changed files with 44 additions and 0 deletions

View file

@ -0,0 +1,31 @@
<?php
it('logs out and lands on the login page', function () {
$page = loginAs(createPlanner());
logout($page)
->assertPathIs('/login')
->assertSee('Sign In');
});
it('blocks protected routes after logging out', function (string $path) {
$page = loginAs(createPlanner());
logout($page)
->assertPathIs('/login')
->navigate($path)
->assertPathIs('/login')
->assertSee('Sign In');
})->with(['/dashboard', '/dishes', '/schedule', '/users']);
it('does not restore an authenticated view via the back button', function () {
$planner = createPlanner();
$page = loginAs($planner)->assertSee($planner->name);
logout($page)
->assertPathIs('/login')
->back()
->assertPathIs('/login')
->assertDontSee('Logout');
});

View file

@ -3,6 +3,7 @@
use App\Models\Planner;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Hash;
use Pest\Browser\Api\AwaitableWebpage;
use Pest\Browser\Api\Webpage;
use Tests\BrowserTestCase;
use Tests\TestCase;
@ -62,3 +63,15 @@ function loginAndGoToSchedule()
{
return loginAs(createPlanner(), '/schedule');
}
/**
* Open the account dropdown and submit the logout form.
*
* @return Webpage
*/
function logout(Webpage|AwaitableWebpage $page)
{
return $page
->click('button[\@click="open = !open"]')
->click('.sm\:flex form[action$="/logout"] button[type="submit"]');
}