diff --git a/tests/Feature/Components/ActionStylesheetsTest.php b/tests/Feature/Components/ActionStylesheetsTest.php index 4d1a050c..8fa0e8d5 100644 --- a/tests/Feature/Components/ActionStylesheetsTest.php +++ b/tests/Feature/Components/ActionStylesheetsTest.php @@ -7,10 +7,11 @@ use NoNameWeb\LivewireMaterial\Tests\Support\ViewClasses; /** * The actions and communication components, rewritten without Tailwind (plan step 36): each view * renders `data-md-*` attributes and no class list of its own beyond the interaction and text - * classes (tests/Support/ViewClasses.php), and each has a stylesheet in - * `material.components` that imports the stylesheets of the components its view renders, writes - * its values from the tokens and its breakpoints as px range queries, and is imported from the - * "Actions and communication" block of all.css. + * classes (tests/Support/ViewClasses.php), writes its values from the tokens and its breakpoints + * as px range queries, and is imported from the "Actions and communication" block of all.css. + * Every component stylesheet importing the stylesheets its view renders is + * tests/Feature/StylesheetsTest.php's now, folded into one dataset over every component view (step + * 42) rather than kept once per group. * * `icon` and `shape` are the two foundation components (``, ``) — no group's view * renders them exclusively, so they were in no group's dataset at all. They follow the same shape, @@ -57,20 +58,6 @@ it('draws the component from a stylesheet shaped like every package stylesheet', } })->with('action components'); -it('imports the stylesheet of every component its view renders', function (string $name) { - preg_match_all('/unique() - // A rendered tag that is not a components/ stylesheet at all (a layout component's, e.g. - // ) has no import of its own to check here. - ->filter(fn (string $tag): bool => is_file(ComponentStylesheet::path($tag)) && str_contains(File::get(ComponentStylesheet::path($tag)), '@layer material.components')) - ->map(fn (string $tag): string => "./{$tag}.css") - ->values() - ->all(); - - expect(array_values(array_diff($rendered, ComponentStylesheet::read($name)->imports())))->toBe([]); -})->with('action components'); - it('writes no class list into the view but the interaction and text classes', function (string $name) { expect(ViewClasses::violations(File::get(__DIR__."/../../../resources/views/components/{$name}.blade.php")))->toBe([]); })->with('action components'); diff --git a/tests/Feature/Components/ContainmentStylesheetsTest.php b/tests/Feature/Components/ContainmentStylesheetsTest.php index afa7d382..6f8b5425 100644 --- a/tests/Feature/Components/ContainmentStylesheetsTest.php +++ b/tests/Feature/Components/ContainmentStylesheetsTest.php @@ -7,9 +7,11 @@ use NoNameWeb\LivewireMaterial\Tests\Support\ViewClasses; /** * The containment components, rewritten without Tailwind (plan step 36): each view renders * `data-md-*` attributes and no class list of its own beyond the interaction and text classes - * (tests/Support/ViewClasses.php), and each has a stylesheet in `material.components` that imports - * the stylesheets of the components its view renders, writes its values from the tokens and its - * breakpoints as px range queries, and is imported from the "Containment" block of all.css. + * (tests/Support/ViewClasses.php), writes its values from the tokens and its breakpoints as px + * range queries, and is imported from the "Containment" block of all.css. Every component + * stylesheet importing the stylesheets its view renders is tests/Feature/StylesheetsTest.php's + * now, folded into one dataset over every component view (step 42) rather than kept once per + * group. * * The dataset grew by one name per component commit, the same rule InputStylesheetsTest.php and * ActionStylesheetsTest.php follow. The error layout, whose view is not a component, has the same @@ -86,20 +88,6 @@ it('draws the component from a stylesheet shaped like every package stylesheet', } })->with('containment components'); -it('imports the stylesheet of every component its view renders', function (string $name) { - preg_match_all('/unique() - // A rendered tag that is not a components/ stylesheet at all (a layout component's, e.g. - // ) has no import of its own to check here. - ->filter(fn (string $tag): bool => is_file(ComponentStylesheet::path($tag)) && str_contains(File::get(ComponentStylesheet::path($tag)), '@layer material.components')) - ->map(fn (string $tag): string => "./{$tag}.css") - ->values() - ->all(); - - expect(array_values(array_diff($rendered, ComponentStylesheet::read($name)->imports())))->toBe([]); -})->with('containment components'); - it('writes no class list into the view but the interaction and text classes', function (string $name) { expect(ViewClasses::violations(File::get(__DIR__."/../../../resources/views/components/{$name}.blade.php")))->toBe([]); })->with('containment components'); diff --git a/tests/Feature/Components/InputStylesheetsTest.php b/tests/Feature/Components/InputStylesheetsTest.php index 6c5d8feb..4054bc37 100644 --- a/tests/Feature/Components/InputStylesheetsTest.php +++ b/tests/Feature/Components/InputStylesheetsTest.php @@ -7,15 +7,16 @@ use NoNameWeb\LivewireMaterial\Tests\Support\ViewClasses; /** * The inputs, selection and data components, rewritten without Tailwind (plan step 36): each view * renders `data-md-*` attributes and no class list of its own beyond the interaction and text - * classes (tests/Support/ViewClasses.php), and each has a stylesheet in - * `material.components` that imports the stylesheets of the components its view renders, writes - * its values from the tokens and its breakpoints as px range queries, and is imported from the - * "Inputs, selection and data" block of all.css. + * classes (tests/Support/ViewClasses.php), writes its values from the tokens and its breakpoints + * as px range queries, and is imported from the "Inputs, selection and data" block of all.css. + * Every component stylesheet importing the stylesheets its view renders is + * tests/Feature/StylesheetsTest.php's now, folded into one dataset over every component view (step + * 42) rather than kept once per group. * * `pagination` is not in this dataset: its four views live in `resources/views/pagination/**`, not - * `resources/views/components/`, so the two checks that read a single `resources/views/components/ - * {name}.blade.php` file do not apply to it. It gets the three checks that do not depend on that - * path below, and its own small versions of the other two. + * `resources/views/components/`, so the check that reads a single `resources/views/components/ + * {name}.blade.php` file does not apply to it. It gets the two checks that do not depend on that + * path below, and its own small version of the third. */ function inputComponents(): array { @@ -132,20 +133,6 @@ it('draws the component from a stylesheet shaped like every package stylesheet', } })->with('input stylesheets'); -it('imports the stylesheet of every component its view renders', function (string $name) { - preg_match_all('/unique() - // A rendered tag that is not a components/ stylesheet at all (a layout component's, e.g. - // ) has no import of its own to check here. - ->filter(fn (string $tag): bool => is_file(ComponentStylesheet::path($tag)) && str_contains(File::get(ComponentStylesheet::path($tag)), '@layer material.components')) - ->map(fn (string $tag): string => "./{$tag}.css") - ->values() - ->all(); - - expect(array_values(array_diff($rendered, ComponentStylesheet::read($name)->imports())))->toBe([]); -})->with('input components'); - it('writes no class list into the view but the interaction and text classes', function (string $name) { expect(ViewClasses::violations(File::get(__DIR__."/../../../resources/views/components/{$name}.blade.php")))->toBe([]); })->with('input components'); diff --git a/tests/Feature/Components/NavigationStylesheetsTest.php b/tests/Feature/Components/NavigationStylesheetsTest.php index c014164c..6dbcc8ab 100644 --- a/tests/Feature/Components/NavigationStylesheetsTest.php +++ b/tests/Feature/Components/NavigationStylesheetsTest.php @@ -7,15 +7,14 @@ use NoNameWeb\LivewireMaterial\Tests\Support\ViewClasses; /** * The navigation components, rewritten without Tailwind (plan step 36, the last audit group): each * view renders `data-md-*` attributes and no class list of its own beyond the interaction and text - * classes (tests/Support/ViewClasses.php), and each has a stylesheet in `material.components` that - * imports the stylesheets of the components its view renders, writes its values from the tokens - * and its breakpoints as px range queries, and is imported from the "Navigation" block of - * all.css. + * classes (tests/Support/ViewClasses.php), writes its values from the tokens and its breakpoints + * as px range queries, and is imported from the "Navigation" block of all.css. Every component + * stylesheet importing the stylesheets its view renders is tests/Feature/StylesheetsTest.php's + * now, folded into one dataset over every component view (step 42, `tabs`/`tab`'s N-16 pairing + * included) rather than kept once per group. * * The dataset grows by one name per component commit, the same rule ContainmentStylesheetsTest.php - * and the earlier groups follow. `` and `` share one stylesheet (tabs.css) and one - * commit, so `navigationViews()` maps the 'tabs' entry onto both blade views; every other entry is - * one view, one stylesheet, as usual. `navigation-bar` rejoined the dataset with the scaffold's own + * and the earlier groups follow. `navigation-bar` rejoined the dataset with the scaffold's own * rewrite: its one rule reading `--material-bottom-bar` stayed unlayered only while `` * published that variable through a Tailwind utility, which no layered rule could outrank; now * scaffold.css sets it in `material.layout`, which this file's `material.components` always beats, @@ -120,24 +119,6 @@ it('draws the component from a stylesheet shaped like every package stylesheet', } })->with('navigation stylesheets'); -it('imports the stylesheet of every component its view renders', function (string $name) { - $rendered = collect(navigationViews($name)) - ->flatMap(function (string $view): array { - preg_match_all('/unique() - // A rendered tag that is not a components/ stylesheet at all (a layout component's, e.g. - // ) has no import of its own to check here. - ->filter(fn (string $tag): bool => is_file(ComponentStylesheet::path($tag)) && str_contains(File::get(ComponentStylesheet::path($tag)), '@layer material.components')) - ->map(fn (string $tag): string => "./{$tag}.css") - ->values() - ->all(); - - expect(array_values(array_diff($rendered, ComponentStylesheet::read($name)->imports())))->toBe([]); -})->with('navigation components'); - it('writes no class list into the view but the interaction and text classes', function (string $name) { foreach (navigationViews($name) as $view) { expect(ViewClasses::violations(File::get(__DIR__."/../../../resources/views/components/{$view}.blade.php")))->toBe([]); diff --git a/tests/Feature/StylesheetsTest.php b/tests/Feature/StylesheetsTest.php index ab086f55..dffe1a27 100644 --- a/tests/Feature/StylesheetsTest.php +++ b/tests/Feature/StylesheetsTest.php @@ -471,6 +471,53 @@ it('gives every component view a stylesheet, or lists it on a short, documented } }); +/** + * Every component view the four group stylesheet tests (Action/Input/Containment/Navigation) used + * to check one at a time, in one dataset instead: every `resources/views/components/*.blade.php` + * backed by a `components/*.css` file of its own, `tabs` and `tab` folded into the one entry + * `imports…()` below already special-cases (they share tabs.css, N-16), `theme-script` (no + * stylesheet at all) and every layout component (the test above covers those) left out. + * + * @return list + */ +function componentStylesheetViews(): array +{ + // Plain glob(), not the File facade: dataset() below runs while the file is parsed, before + // Pest has booted the application the facade needs. + return collect(glob(__DIR__.'/../../resources/views/components/*.blade.php')) + ->map(fn (string $file): string => basename($file, '.blade.php')) + ->reject(fn (string $name): bool => in_array($name, ['theme-script', 'tab'], true)) + ->filter(fn (string $name): bool => is_file(__DIR__."/../../resources/css/components/{$name}.css")) + ->values() + ->all(); +} + +dataset('component stylesheet views', componentStylesheetViews()); + +it('imports, from every component stylesheet, the stylesheet of each component its view renders', function (string $name) { + // tabs.css is shared by two views, tabs.blade.php and tab.blade.php (N-16); every other + // component stylesheet in this dataset has exactly one view of its own name. + $views = $name === 'tabs' ? ['tabs', 'tab'] : [$name]; + + $rendered = collect($views) + ->flatMap(function (string $view): array { + preg_match_all('/unique() + // A rendered tag that is not a components/ stylesheet at all (a layout component's, e.g. + // ) has no import of its own to check here. + ->filter(fn (string $tag): bool => is_file(stylesheetPath("components/{$tag}.css")) && str_contains(File::get(stylesheetPath("components/{$tag}.css")), '@layer material.components')) + ->map(fn (string $tag): string => "./{$tag}.css") + ->values() + ->all(); + + $imports = stylesheetImports(stylesheetPath("components/{$name}.css")); + + expect(array_values(array_diff($rendered, $imports)))->toBe([]); +})->with('component stylesheet views'); + it('imports a stylesheet for every layout component from all.css, each beside its view', function () { $imports = array_values(array_filter( stylesheetImports(stylesheetPath('all.css')),