From 5fb8fc6b8f2de2c45d0d8642756c731ae3314cec Mon Sep 17 00:00:00 2001 From: Andreas Reinhold / reini Date: Tue, 15 Sep 2026 06:10:35 +0200 Subject: [PATCH] Fail when the showcase search skips an example a page renders Plan step 38 review: the index reads example titles out of each section's source with a regex, which once skipped all six Progress examples without a sound; the existing test only checked that indexed anchors exist. A new test renders every section and canonical layout page and requires the index's examples for it to equal the titled examples the page draws, both ways, so a format the regex misses (or an anchor it invents) fails by page. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01Qwx5USif3wFFmxtHg5U1g9 --- tests/Feature/ShowcaseTest.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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);