create(['first_name' => 'Clara', 'last_name' => 'Chefin']); $head = User::factory()->create(['first_name' => 'Holger', 'last_name' => 'Leiter', 'manager_id' => $ceo->id]); $nurse = User::factory()->create(['first_name' => 'Nina', 'last_name' => 'Pflege', 'manager_id' => $head->id]); User::factory()->inactive()->create(['manager_id' => $head->id]); User::factory()->create(); // ohne Vorgesetzte und ohne Team $this->actingAs($nurse)->get('/personen/organigramm')->assertOk()->assertInertia(fn (Assert $p) => $p ->component('People/Organigram') ->where('roots.0.id', $ceo->id) ->where('roots.0.reports', 1) ->has('roots', 1) ->where('unassigned', 1) ->where('path', []) ->where('open', [$ceo->id, $head->id]) ->where("teams.{$ceo->id}.0.id", $head->id) ->where("teams.{$head->id}.0.id", $nurse->id)); $this->getJson("/personen/organigramm/{$head->id}/team")->assertOk() ->assertJsonPath('team.0.id', $nurse->id) ->assertJsonCount(1, 'team'); // Weg zur gesuchten Person ist aufgeklappt. $this->get('/personen/organigramm?person='.$nurse->id)->assertInertia(fn (Assert $p) => $p ->where('path', [$ceo->id, $head->id, $nurse->id]) ->where("teams.{$head->id}.0.id", $nurse->id)); } public function test_focus_view_starts_at_the_top_and_shows_contact_details(): void { $ceo = User::factory()->create(['first_name' => 'Clara', 'last_name' => 'Chefin', 'phone' => '+49 40 1']); $head = User::factory()->create(['manager_id' => $ceo->id]); User::factory()->create(['manager_id' => $head->id]); $this->actingAs($head)->get('/personen/organigramm?ansicht=fokus')->assertInertia(fn (Assert $p) => $p ->where('view', 'fokus') ->where('focus', $ceo->id) ->where('details.phone', '+49 40 1') ->where('stats', ['people' => 3, 'leaders' => 2])); $this->get('/personen/organigramm?ansicht=unsinn')->assertInertia(fn (Assert $p) => $p->where('view', 'baum')->where('details', null)); } public function test_admin_sets_managers_without_cycles(): void { $this->actingAs(User::factory()->admin()->create()); $boss = User::factory()->create(); $employee = User::factory()->create(['manager_id' => $boss->id]); Livewire::test(EditUser::class, ['record' => $boss->getRouteKey()]) ->fillForm(['manager_id' => $employee->id]) ->call('save') ->assertHasFormErrors(['manager_id']); $other = User::factory()->create(); Livewire::test(EditUser::class, ['record' => $employee->getRouteKey()]) ->fillForm(['manager_id' => $other->id]) ->call('save') ->assertHasNoFormErrors(); $this->assertSame($other->id, $employee->fresh()->manager_id); } }