actingAs($user)->get('/')->viewData('page')['props']['widgets']; return array_values(array_column(array_filter($widgets, fn ($w) => $w['area'] === $area), 'key')); } public function test_admin_adds_an_image_tile_with_link(): void { Storage::fake('uploads'); $admin = User::factory()->admin()->create(); $this->actingAs($admin); Livewire::test(ManageDashboardTiles::class) ->callAction('create', [ 'name' => 'Betriebsrat-Banner', 'type' => 'image', 'area' => 'aside', 'image_path' => UploadedFile::fake()->image('banner.jpg', 800, 600), 'url' => 'intranet.example.org/aktion', 'alt' => 'Aktion Gesundheit', 'is_active' => true, ]) ->assertHasNoActionErrors(); $tile = DashboardTile::query()->sole(); $this->assertSame('https://intranet.example.org/aktion', $tile->url); $props = $this->dashboardWidget($this->get('/'), $tile->widgetKey()); $this->assertSame('image', $props['tile']['type']); $this->assertSame('Aktion Gesundheit', $props['tile']['alt']); $this->assertNotNull($props['tile']['image_url']); } public function test_tiles_respect_period_and_audience(): void { $nurse = User::factory()->create(['department' => 'Pflege']); $clerk = User::factory()->create(['department' => 'Verwaltung']); $notice = DashboardTile::query()->create(['name' => 'Hinweis', 'type' => 'notice', 'area' => 'top', 'title' => 'Heute Betriebsversammlung', 'body' => '

14 Uhr

', 'variant' => 'info']); $expired = DashboardTile::query()->create(['name' => 'Alt', 'type' => 'text', 'area' => 'aside', 'body' => 'x', 'ends_at' => now()->subDay()]); $inactive = DashboardTile::query()->create(['name' => 'Aus', 'type' => 'text', 'area' => 'aside', 'body' => 'x', 'is_active' => false]); Audiences::sync('dashboard_tile', $notice->id, ['department' => ['Pflege']]); $this->assertSame(['tile.'.$notice->id], $this->keys($nurse, 'top')); $this->assertSame([], $this->keys($clerk, 'top')); $this->assertNotContains($expired->widgetKey(), $this->keys($nurse, 'aside')); $this->assertNotContains($inactive->widgetKey(), $this->keys($nurse, 'aside')); $this->assertStringNotContainsString('script', $notice->fresh()->body_html); } public function test_admin_reorders_and_hides_tiles(): void { $admin = User::factory()->admin()->create(); $tile = DashboardTile::query()->create(['name' => 'Banner', 'type' => 'text', 'area' => 'aside', 'body' => 'Hallo']); $default = $this->keys($admin, 'aside'); $this->assertSame('core.greeting', $default[0]); $this->assertSame($tile->widgetKey(), end($default), 'Neue eigene Kacheln stehen zunächst am Ende.'); $page = Livewire::actingAs($admin)->test(DashboardSettings::class); $aside = collect($page->get('data.aside'))->values(); $this->assertContains('Eigene Kachel: Banner', $aside->pluck('label')); // Eigene Kachel nach oben, „Personen finden“ ausblenden $reordered = $aside->sortBy(fn ($item) => $item['key'] === $tile->widgetKey() ? 0 : 1)->values() ->map(fn ($item) => $item['key'] === 'core.people-search' ? [...$item, 'visible' => false] : $item)->all(); $page->set('data.aside', $reordered)->call('save')->assertHasNoErrors(); $keys = $this->keys($admin, 'aside'); $this->assertSame($tile->widgetKey(), $keys[0]); $this->assertNotContains('core.people-search', $keys); $this->actingAs(User::factory()->create())->get('/admin/startseite')->assertForbidden(); } public function test_admin_moves_quick_links_to_sidebar(): void { $admin = User::factory()->admin()->create(); $this->assertContains('core.quick-links', $this->keys($admin, 'main')); $page = Livewire::actingAs($admin)->test(DashboardSettings::class); $main = collect($page->get('data.main'))->values() ->map(fn ($item) => $item['key'] === 'core.quick-links' ? [...$item, 'area' => 'aside'] : $item)->all(); $page->set('data.main', $main)->call('save')->assertHasNoErrors(); $this->assertNotContains('core.quick-links', $this->keys($admin, 'main')); $this->assertContains('core.quick-links', $this->keys($admin, 'aside')); $this->assertContains('core.quick-links', collect($page->get('data.aside'))->pluck('key'), 'Formular zeigt die Kachel im neuen Bereich'); // Nicht verschiebbare Kacheln bleiben, wo sie hingehören $this->assertSame(['main', 'aside'], collect(app(Widgets::class)->forAdmin('aside'))->firstWhere('key', 'core.quick-links')['areas']); $aside = collect($page->get('data.aside'))->values() ->map(fn ($item) => $item['key'] === 'core.greeting' ? [...$item, 'area' => 'main'] : $item)->all(); $page->set('data.aside', $aside)->call('save'); $this->assertContains('core.greeting', $this->keys($admin, 'aside')); } }