create(['department' => 'Werkstatt']); User::factory()->create(['first_name' => 'Sommer', 'last_name' => 'Fest']); NewsPost::factory()->create(['title' => 'Sommerfest 2026: Jetzt anmelden', 'body' => '
Musik und Essen
']); NewsPost::factory()->draft()->create(['title' => 'Sommerfest intern (Entwurf)']); $care = NewsCategory::query()->create(['name' => 'Pflege intern', 'slug' => 'pflege-intern']); Audiences::sync('news_category', $care->id, ['department' => ['Pflege']]); NewsPost::factory()->create(['title' => 'Sommerfest nur für die Pflege', 'category_id' => $care->id]); Event::factory()->create(['title' => 'Sommerfest am See', 'is_published' => true, 'starts_at' => now()->addWeek()]); $groups = collect($this->actingAs($user)->getJson('/suche/live?q=sommerfest')->assertOk()->json('groups'))->keyBy('key'); $this->assertSame(['Sommerfest 2026: Jetzt anmelden'], array_column($groups['news']['items'], 'title')); $this->assertSame(['Sommerfest am See'], array_column($groups['events']['items'], 'title')); $this->assertArrayNotHasKey('people', $groups->all()); } public function test_all_terms_must_match_and_short_queries_return_nothing(): void { $user = User::factory()->create(); NewsPost::factory()->create(['title' => 'Neue Software für die Dienstplanung', 'body' => 'Ab Juni
']); NewsPost::factory()->create(['title' => 'Neue Kantine', 'body' => 'Ab Juni
']); $groups = $this->actingAs($user)->getJson('/suche/live?q='.urlencode('neue dienstplanung'))->json('groups'); $this->assertSame(['Neue Software für die Dienstplanung'], array_column($groups[0]['items'], 'title')); $this->actingAs($user)->getJson('/suche/live?q=n')->assertJson(['groups' => []]); } public function test_results_page_and_broken_source_does_not_break_search(): void { app(GlobalSearch::class)->add('kaputt', 'Kaputt', 'bug', fn () => throw new \RuntimeException('weg')); NewsPost::factory()->create(['title' => 'Blühwiese am Standort']); $this->actingAs(User::factory()->create())->get('/suche?q=blühwiese')->assertOk()->assertInertia(fn (Assert $page) => $page ->component('Search/Index') ->where('query', 'blühwiese') ->has('groups', 1) ->where('groups.0.items.0.title', 'Blühwiese am Standort')); } public function test_search_page_without_query_opens_empty(): void { // Lupe im Kopf (Handy) führt ohne Suchbegriff auf die Seite $this->actingAs(User::factory()->create())->get('/suche')->assertOk()->assertInertia(fn (Assert $page) => $page ->component('Search/Index')->where('query', '')->where('groups', [])); $this->actingAs(User::factory()->create())->getJson('/suche/live')->assertOk()->assertJson(['groups' => []]); } public function test_excerpt_centers_on_the_match(): void { $text = str_repeat('Füllwort ', 60).'Hier steht der Treffer Dienstplan im Text. '.str_repeat('Ende ', 40); $excerpt = GlobalSearch::excerpt("{$text}
", 'dienstplan'); $this->assertStringStartsWith('… ', $excerpt); $this->assertStringContainsString('Treffer Dienstplan', $excerpt); } public function test_people_cards_show_the_configured_fields(): void { app(Settings::class)->set(ContactCards::PEOPLE_SEARCH_FIELDS, ['email', 'phone']); User::factory()->create(['first_name' => 'Friederich', 'last_name' => 'Loheide', 'job_title' => 'Leitung', 'department' => 'IT', 'phone' => '05482 72-295', 'email' => 'f.loheide@example.com']); User::factory()->inactive()->create(['first_name' => 'Alt', 'last_name' => 'Loheide']); $data = $this->actingAs(User::factory()->create())->getJson('/personen/karten?q=loheide')->assertOk()->json(); $this->assertSame(1, $data['total']); $this->assertSame('Leitung · IT', $data['people'][0]['subtitle']); $this->assertSame(['email', 'phone'], array_column($data['people'][0]['fields'], 'key')); $this->assertSame('phone', $data['people'][0]['fields'][1]['type']); } }