create(['first_name' => 'Ada', 'last_name' => 'Lovelace']); $this->actingAs($user) ->get('/') ->assertOk() ->assertInertia(fn (Assert $page) => $page ->component('Dashboard') ->where('auth.user.name', 'Ada Lovelace') ->where('auth.user.initials', 'AL') ->where('auth.user.avatar_url', null) ->where('auth.user.is_admin', false) ->has('branding.portal_name') ->has('branding.primary_color')); } public function test_profile_redirects_to_own_person_page(): void { $user = User::factory()->create(); $this->actingAs($user)->get('/profil')->assertRedirect("/personen/{$user->id}"); } public function test_colleague_profile_is_shown(): void { $colleague = User::factory()->create(['job_title' => 'Pflegedienstleitung']); $this->actingAs(User::factory()->create()) ->get("/personen/{$colleague->id}") ->assertOk() ->assertInertia(fn (Assert $page) => $page ->component('Profile/Show') ->where('person.job_title', 'Pflegedienstleitung') ->where('isOwnProfile', false)); } public function test_inactive_profiles_are_hidden(): void { $inactive = User::factory()->inactive()->create(); $this->actingAs(User::factory()->create()) ->get("/personen/{$inactive->id}") ->assertNotFound(); } public function test_own_profile_can_be_updated(): void { $user = User::factory()->create(); $this->actingAs($user) ->put('/profil', [ 'first_name' => 'Grete', 'last_name' => 'Müller', 'email' => 'grete@example.com', 'job_title' => 'Mitarbeitervertretung', 'department' => 'MAV', 'location' => 'Hamburg', 'phone' => '040 123', 'mobile' => null, 'about' => 'Ansprechpartnerin für alle Fragen rund um die MAV.', ]) ->assertRedirect() ->assertSessionHasNoErrors(); $user->refresh(); $this->assertSame('Grete Müller', $user->name); $this->assertSame('MAV', $user->department); $this->assertSame('grete@example.com', $user->email); } public function test_profile_update_cannot_change_account_flags(): void { $user = User::factory()->create(); $this->actingAs($user)->put('/profil', [ 'first_name' => 'Eve', 'last_name' => 'Evil', 'email' => $user->email, 'is_admin' => true, 'is_active' => false, ]); $user->refresh(); $this->assertFalse($user->is_admin); $this->assertTrue($user->is_active); } public function test_email_must_be_unique(): void { User::factory()->create(['email' => 'vergeben@example.com']); $user = User::factory()->create(); $this->actingAs($user) ->put('/profil', ['first_name' => 'A', 'last_name' => 'B', 'email' => 'vergeben@example.com']) ->assertSessionHasErrors('email'); } public function test_theme_preference_is_saved_and_validated(): void { $user = User::factory()->create(); $this->actingAs($user)->put('/profil/darstellung', ['theme' => 'dark'])->assertRedirect(); $this->assertSame('dark', $user->fresh()->theme); $this->actingAs($user)->put('/profil/darstellung', ['theme' => 'pink'])->assertSessionHasErrors('theme'); } }