Plan step 36 (navigation group, second batch, cleanup). Every leftover data-navigation-*, data-tall, data-hide-on-scroll, data-hidden, data-width, data-align, data-divider, data-fill and component-level data-open reference outside the rewritten stylesheets and views moves to data-md-*, in the files the two component commits left alone: tests/Feature/Components/ScaffoldTest.php (the scaffold's own rewrite is a later batch, but it renders the bar and the rail today and asserts their hooks); tests/Browser/NavigationTest.php, ShowcaseTest.php and ColourProfilesTest.php (selectors only — document-level attributes, data-rail, data-rail-auto and data-app-shell*, keep their names). NavigationTest.php also gets the browser tests the plan owed this group (docs/plans/material-3-browser-tests.md § Navigation): a tall bar's vertical layout at a width where the short bar would go horizontal; hide-on-scroll never firing while a pinned snackbar is on screen; a narrow rail's 80px width and centred destinations; a rail that hides when collapsed leaving the layout and coming back only through an application's own menu button. resources/css/components/navigation.css and its import in tailwind.css are deleted now that nothing imports the file any more (the previous commit's message said this already happened there; it did not — this is where it actually lands). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qwx5USif3wFFmxtHg5U1g9
89 lines
3.8 KiB
PHP
89 lines
3.8 KiB
PHP
<?php
|
|
|
|
use NoNameWeb\LivewireMaterial\Support\Scheme;
|
|
|
|
use function Orchestra\Testbench\workbench_path;
|
|
|
|
/*
|
|
* The Workbench's three profiles (baseline, teal, rose), generated into its stylesheet. Tests other
|
|
* than these run without profiles, so each one here points the package at the scheme file.
|
|
*/
|
|
|
|
beforeEach(function () {
|
|
config(['livewire-material.scheme' => workbench_path('resources/css/material-scheme.json')]);
|
|
|
|
$this->profiles = json_decode(file_get_contents(workbench_path('resources/css/material-scheme.json')), true)['profiles'];
|
|
});
|
|
|
|
afterEach(function () {
|
|
Scheme::resolveProfileUsing(null);
|
|
});
|
|
|
|
/**
|
|
* A #rrggbb hex as the rgb() a computed style reports.
|
|
*/
|
|
function rgb(string $hex): string
|
|
{
|
|
[$red, $green, $blue] = sscanf($hex, '#%02x%02x%02x');
|
|
|
|
return "rgb({$red}, {$green}, {$blue})";
|
|
}
|
|
|
|
/**
|
|
* The page's primary colour role, as <html> resolves it.
|
|
*/
|
|
function pagePrimary(): string
|
|
{
|
|
return "getComputedStyle(document.documentElement).getPropertyValue('--md-sys-color-primary').trim()";
|
|
}
|
|
|
|
function profilesReady(mixed $page): mixed
|
|
{
|
|
return $page->waitForEvent('networkidle')
|
|
->assertScript("document.readyState === 'complete' && typeof window.Alpine !== 'undefined' && typeof window.Livewire !== 'undefined'");
|
|
}
|
|
|
|
it('draws each profile in light and dark, and the default without the attribute', function () {
|
|
$page = profilesReady(visit('/material/colour')->inLightMode())
|
|
->assertScript("document.documentElement.getAttribute('data-scheme') === 'baseline'")
|
|
->assertScript(pagePrimary()." === '{$this->profiles['baseline']['light']['primary']}'");
|
|
|
|
$page->script("document.documentElement.setAttribute('data-scheme', 'teal')");
|
|
$page->assertScript(pagePrimary()." === '{$this->profiles['teal']['light']['primary']}'");
|
|
|
|
$page->script("document.documentElement.setAttribute('data-theme', 'dark')");
|
|
$page->assertScript(pagePrimary()." === '{$this->profiles['teal']['dark']['primary']}'")
|
|
// A panel that sets its own theme keeps the page's profile.
|
|
->assertScript("getComputedStyle(document.querySelector('#colour [data-theme=\"light\"] .bg-primary')).backgroundColor === '".rgb($this->profiles['teal']['light']['primary'])."'");
|
|
|
|
$page->script("document.documentElement.removeAttribute('data-scheme')");
|
|
$page->assertScript(pagePrimary()." === '{$this->profiles['baseline']['dark']['primary']}'")
|
|
->assertNoJavaScriptErrors();
|
|
});
|
|
|
|
it('previews a profile from the picker and the showcase menu, and keeps it through wire:navigate', function () {
|
|
$page = profilesReady(visit('/material/colour')->inLightMode());
|
|
|
|
$page->click('#colour [data-scheme-option="rose"]')
|
|
->assertScript("document.documentElement.getAttribute('data-scheme') === 'rose'")
|
|
->assertScript(pagePrimary()." === '{$this->profiles['rose']['light']['primary']}'")
|
|
->assertScript("window.eval(\"Alpine.store('theme').scheme\") === 'rose'");
|
|
|
|
$page->click('[data-test="showcase-profiles"] [aria-haspopup="menu"]')
|
|
->click('[data-scheme-preview="teal"]')
|
|
->assertScript("document.documentElement.getAttribute('data-scheme') === 'teal'");
|
|
|
|
$page->click('[data-md-navigation-rail-panel] a[href$="/material/buttons"]')
|
|
->assertScript("location.pathname.endsWith('/material/buttons')")
|
|
->assertScript("document.documentElement.getAttribute('data-scheme') === 'teal'")
|
|
->assertNoJavaScriptErrors();
|
|
});
|
|
|
|
it('paints the profile the application resolves from the first frame', function () {
|
|
Scheme::resolveProfileUsing(fn (): string => 'rose');
|
|
|
|
profilesReady(visit('/material')->inDarkMode())
|
|
->assertScript("document.documentElement.getAttribute('data-scheme') === 'rose'")
|
|
->assertScript(pagePrimary()." === '{$this->profiles['rose']['dark']['primary']}'");
|
|
});
|