assertOk() ->assertInertia(fn ($page) => $page ->component('auth/login') ); }); it('redirects to dashboard if already authenticated', function () { $user = User::factory()->create(); actingAs($user) ->get(route('login')) ->assertRedirect(); }); }); describe('Authentication - Login Actions', function () { it('can login with valid credentials', function () { $user = User::factory()->create([ 'email' => 'test@example.com', 'password' => bcrypt('password123'), ]); post(route('login'), [ 'login' => 'test@example.com', 'password' => 'password123', ])->assertRedirect(); assertAuthenticated(); }); it('cannot login with invalid password', function () { $user = User::factory()->create([ 'email' => 'test@example.com', 'password' => bcrypt('password123'), ]); post(route('login'), [ 'login' => 'test@example.com', 'password' => 'wrongpassword', ])->assertSessionHasErrors(['login']); // Fortify typically returns error on username field assertGuest(); }); it('cannot login with non-existent email', function () { post(route('login'), [ 'login' => 'notfound@example.com', 'password' => 'password123', ])->assertSessionHasErrors(['login']); assertGuest(); }); }); describe('Authentication - Logout Actions', function () { it('can logout successfully', function () { $user = User::factory()->create(); actingAs($user); assertAuthenticated(); post(route('logout'))->assertRedirect('/'); assertGuest(); }); });