Loheide-eu-mitarbeiterplatt.../tests/Feature/DashboardCustomizationTest.php
Friederich Loheide ee8dde93c0
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m18s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m21s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m40s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m34s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 3m8s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 3m6s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m43s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m47s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m1s
Feste Profilfelder in Formularen, Geburtstage, anpassbare Startseite
- Formulare: Felder fest aus dem Profil (nicht änderbar, Server setzt den
  Profilwert ein), Hinweis bei fehlender Profilangabe
- Geburtstage (optionales Plugin, standardmäßig aus): Tag und Monat freiwillig
  im Profil, Kachel, Liste /geburtstage, Pagebuilder-Block, Glückwunsch am
  eigenen Geburtstag; Sichtbarkeit alle/Abteilung/Standort
- Startseite: Kacheln je Bereich sortieren und ausblenden; eigene Kacheln
  (Bild mit Link, Text, Hinweis) mit Zeitraum und Zielgruppe
- Kern: optionale mitgelieferte Plugins, Startseitenbereich „top“,
  Profilabschnitte für Plugins, Kachel-Bezeichnungen

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 09:51:19 +00:00

95 lines
4.3 KiB
PHP

<?php
namespace Tests\Feature;
use App\Filament\Pages\DashboardSettings;
use App\Filament\Resources\DashboardTiles\Pages\ManageDashboardTiles;
use App\Models\DashboardTile;
use App\Models\User;
use App\Support\Permissions\Audiences;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use Tests\TestCase;
class DashboardCustomizationTest extends TestCase
{
use RefreshDatabase;
private function keys(User $user, string $area): array
{
$widgets = $this->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' => '<p>14 Uhr <script>x</script></p>', '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();
}
}