diff --git a/tests/Feature/ShowcaseTest.php b/tests/Feature/ShowcaseTest.php index 059a2acd..ef174f5e 100644 --- a/tests/Feature/ShowcaseTest.php +++ b/tests/Feature/ShowcaseTest.php @@ -90,6 +90,33 @@ it('indexes every section, example and component for the search, each linking to }); }); +it('indexes exactly the examples each page renders, so an example the index misses fails here', function () { + $index = collect($this->getJson('/material/search.json')->assertOk()->json())->where('kind', 'Example'); + $pages = collect(Sections::all())->keys()->map(fn (string $key): string => route('livewire-material.section', $key, false)) + ->merge(collect(Sections::layoutPages())->except('layout')->pluck('url')); + + foreach ($pages as $page) { + $html = $this->withoutVite()->get($page)->assertOk()->getContent(); + + preg_match_all('/<[a-z]+\b[^>]*\bdata-md-showcase-example\b[^>]*>/', $html, $tags); + + $rendered = collect($tags[0]) + ->map(fn (string $tag): ?string => preg_match('/\bid="([^"]+)"/', $tag, $id) === 1 ? $id[1] : null) + ->filter() + ->sort() + ->values() + ->all(); + + $indexed = $index->filter(fn (array $entry): bool => strtok($entry['url'], '#') === $page) + ->map(fn (array $entry): string => substr($entry['url'], strpos($entry['url'], '#') + 1)) + ->sort() + ->values() + ->all(); + + expect($indexed)->toBe($rendered, "{$page}: the search index and the page disagree on its examples"); + } +}); + it('does not mount the showcase when disabled', function () { rebootWithShowcase(false);