lernschiff/tests/Feature/Livewire/PerPageSkeletonTest.php

56 lines
2.8 KiB
PHP

<?php
/**
* Each Livewire page must declare its OWN page-specific placeholder view
* (not a generic skeleton) so the loading shape matches the final layout
* and Alpine x-data states (e.g. PhotoHelp `preview`) are present from
* the very first paint.
*/
use App\Livewire\Dashboard\Index as DashboardIndex;
use App\Livewire\Notifications\Index as NotificationsIndex;
use App\Livewire\PhotoHelp\Index as PhotoHelpIndex;
use App\Livewire\Progress\Index as ProgressIndex;
use App\Livewire\Rewards\Index as RewardsIndex;
use App\Livewire\Settings\Index as SettingsIndex;
use App\Livewire\Subjects\Index as SubjectsIndex;
use App\Livewire\Tasks\Index as TasksIndex;
$placeholderMap = [
DashboardIndex::class => ['view' => 'livewire.dashboard.placeholder', 'marker' => 'dashboard-skeleton'],
SubjectsIndex::class => ['view' => 'livewire.subjects.placeholder', 'marker' => 'subjects-skeleton'],
TasksIndex::class => ['view' => 'livewire.tasks.placeholder', 'marker' => 'tasks-skeleton'],
PhotoHelpIndex::class => ['view' => 'livewire.photo-help.placeholder', 'marker' => 'photo-help-skeleton'],
RewardsIndex::class => ['view' => 'livewire.rewards.placeholder', 'marker' => 'rewards-skeleton'],
ProgressIndex::class => ['view' => 'livewire.progress.placeholder', 'marker' => 'progress-skeleton'],
NotificationsIndex::class => ['view' => 'livewire.notifications.placeholder', 'marker' => 'notifications-skeleton'],
SettingsIndex::class => ['view' => 'livewire.settings.placeholder', 'marker' => 'settings-skeleton'],
];
foreach ($placeholderMap as $class => $meta) {
it("{$class} returns its OWN placeholder view ({$meta['view']})", function () use ($class, $meta) {
$view = $class::placeholder([]);
expect($view->getName())->toBe($meta['view']);
});
it("placeholder for {$class} has unique data-testid (\"{$meta['marker']}\")", function () use ($class, $meta) {
$html = $class::placeholder([])->render();
expect($html)->toContain($meta['marker']);
});
}
it('photo-help placeholder pre-declares Alpine x-data with preview state', function () {
// Fixes "Alpine Expression Error: preview is not defined" during Lazy
// hydration — placeholder must mount the same x-data scope as the real view.
$html = PhotoHelpIndex::placeholder([])->render();
expect($html)->toContain('x-data');
expect($html)->toContain('preview');
});
it('skeleton blade components exist for composition', function () {
foreach (['stat-tile', 'subject-card', 'table-row', 'header', 'card'] as $component) {
$path = "resources/views/components/skeleton/{$component}.blade.php";
expect(file_exists(base_path($path)))->toBeTrue("Missing skeleton component: {$path}");
}
});