Files
livewire-material/tests/Feature/ShowcaseTest.php
T
Andreas Reinhold / reiniandClaude Opus 5 889f8a8aa1
tests / lint (push) Has been cancelled
tests / feature (8.4) (push) Has been cancelled
tests / feature (8.5) (push) Has been cancelled
tests / browser (chrome, chromium) (push) Has been cancelled
tests / browser (firefox, firefox) (push) Has been cancelled
tests / browser (safari, webkit) (push) Has been cancelled
Put the showcase in the app shell, with a page per section
The showcase is now an overview and one page per section behind a
grouped navigation rail, moved between with wire:navigate, instead of
one long page under a scrolling top bar. The switch exposed a WebKit
bug in the menu: inside a focusable region, WebKit moves focus out of
the closing popover before its toggle event, so Escape no longer
returned focus to the trigger. The menu now reads it on beforetoggle.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V9NnLxnPp8vaaurb3Z1MFy
2026-09-13 09:30:26 +02:00

103 lines
3.4 KiB
PHP

<?php
use Illuminate\Support\Facades\File;
use NoNameWeb\LivewireMaterial\Showcase\Sections;
use NoNameWeb\LivewireMaterial\Support\SvgFile;
/**
* Reboot the application with the showcase switched on or off. The routes are mounted
* while the provider boots, so the flag has to be in the environment before that.
*/
function rebootWithShowcase(bool $enabled): void
{
$value = $enabled ? 'true' : 'false';
putenv("MATERIAL_SHOWCASE={$value}");
$_ENV['MATERIAL_SHOWCASE'] = $_SERVER['MATERIAL_SHOWCASE'] = $value;
test()->refreshApplication();
}
afterEach(function () {
rebootWithShowcase(true);
});
it('mounts the showcase when enabled', function () {
$this->withoutVite()
->get('/material')
->assertOk()
->assertSee('Livewire Material');
});
it('gives every section a page of its own, linked from the overview and the rail', function () {
$overview = $this->withoutVite()->get('/material')->assertOk();
foreach (Sections::all() as $key => $section) {
$overview->assertSee(route('livewire-material.section', $key), false);
$this->withoutVite()
->get("/material/{$key}")
->assertOk()
->assertSee("<title>{$section['title']} · Livewire Material</title>", false)
->assertSee('id="'.$key.'"', false);
}
$this->get('/material/not-a-section')->assertNotFound();
});
it('does not mount the showcase when disabled', function () {
rebootWithShowcase(false);
$this->get('/material')->assertNotFound();
});
it('serves a symbol for the icon search', function () {
$this->get('/material/symbols/filled/favorite.svg')
->assertOk()
->assertHeader('Content-Type', 'image/svg+xml')
->assertSee('viewBox="0 -960 960 960"', false);
});
it('answers 404 for a symbol or style that does not exist', function () {
$this->get('/material/symbols/outlined/not_a_symbol_at_all.svg')->assertNotFound();
$this->get('/material/symbols/sharp/favorite.svg')->assertNotFound();
});
it('lists the symbol names for the icon search', function () {
$this->getJson('/material/symbols.json')
->assertOk()
->assertJsonFragment(['calendar_month'])
->assertJsonCount(count(SvgFile::symbolNames()));
});
it('previews an error page through the exception handler', function () {
$this->withoutVite()
->get('/material/errors/404')
->assertNotFound()
->assertSee('Page not found');
$this->get('/material/errors/418')->assertNotFound();
});
it('previews a sample mail in the package theme', function () {
$this->get('/material/mail')
->assertOk()
->assertSee('class="button button-primary"', false)
->assertSee('border-radius: 9999px', false)
->assertSee('Unsubscribe');
});
it('shows every component somewhere in the showcase', function () {
$showcase = collect(File::allFiles(__DIR__.'/../../resources/views/showcase'))
->map(fn (SplFileInfo $file): string => $file->getContents())
->implode("\n");
$absent = collect(File::files(__DIR__.'/../../resources/views/components'))
->map(fn (SplFileInfo $file): string => $file->getBasename('.blade.php'))
->reject(fn (string $name): bool => preg_match('/(?:<|&lt;)x-(?:livewire-material::)?'.preg_quote($name, '/').'(?:[\s\/>]|&gt;)/', $showcase) === 1)
->values()
->all();
expect($absent)->toBe([]);
});