Files
livewire-material/tests/Feature/Components/ChoicesTest.php
T
Andreas Reinhold / reiniandClaude Sonnet 5 925d9a4439 Fold layout.css and components.css into all.css
Plan step 37: all.css replaces the two interim import lists with one
entry for an application that wants everything — the foundation, every
layout stylesheet and every component stylesheet, grouped under the
same block comments components.css used, plus a Layout block. It also
directly imports the three files nothing imported by name before
(layout/spacing.css, layout/visibility.css, components/selection.css),
so every file under components/ and layout/ is now one @import away.

Every test that read a block of components.css or layout.css now reads
the matching block of all.css through one shared helper (allCssBlock(),
in tests/Pest.php so it loads for any test run) instead of repeating
the same substr() search in each file. StylesheetsTest.php's shape,
Tailwind-free and breakpoint checks, previously run twice (once for
the foundation, once for the layout tree), now run once over the whole
tree all.css reaches, since every component and layout stylesheet is
plain CSS after step 36; a new test asserts all.css imports everything
under components/ and layout/ exactly once. The Workbench imports
all.css in place of layout.css and components.css.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qwx5USif3wFFmxtHg5U1g9
2026-09-15 02:49:29 +02:00

111 lines
4.4 KiB
PHP

<?php
use Livewire\Component;
use Livewire\Livewire;
it('lays every option out as a filter chip', function () {
$html = (string) $this->blade('<x-choices label="Days" hint="Pick any" :value="[2]" :options="[[\'id\' => 1, \'name\' => \'Mon\'], [\'id\' => 2, \'name\' => \'Tue\'], [\'id\' => 3, \'name\' => \'Wed\', \'disabled\' => true]]" />');
expect($html)
->toMatch('/<div\\s+data-md-choices\\s/')
->not->toContain('data-md-searchable')
->toContain('role="group"')
->toContain('Days')
->toContain('Pick any')
->toContain('x-modelable="selection"')
->toContain('x-on:click="toggle(0)"')
->toContain('x-bind:aria-pressed="selected(2).toString()"')
->and(substr_count($html, 'aria-pressed="true"'))->toBe(1)
->and(substr_count($html, 'aria-pressed="false"'))->toBe(2)
->and($html)->toContain('disabled');
});
it('entangles the selection with its Livewire property and renders it as the property says', function () {
Livewire::component('choices-probe', new class extends Component
{
/** @var list<int> */
public array $days = [1, 3];
public function render(): string
{
return '<div><x-choices wire:model.live="days" :options="[[\'id\' => 1, \'name\' => \'Mon\'], [\'id\' => 2, \'name\' => \'Tue\'], [\'id\' => 3, \'name\' => \'Wed\']]" /></div>';
}
});
$html = Livewire::test('choices-probe')->html();
expect($html)
->toContain(".entangle('days').live")
->not->toContain('x-modelable')
->and(substr_count($html, 'aria-pressed="true"'))->toBe(2);
});
it('draws a searchable combobox with a popover list', function () {
$html = (string) $this->blade('<x-choices id="zone" label="Time zone" searchable icon="public" value="Europe/Zurich" :options="[[\'id\' => \'Europe/Zurich\', \'name\' => \'Zurich\']]" />');
expect($html)
->toMatch('/<div\\s+data-md-choices\\s+data-md-searchable\\s/')
->toContain('role="combobox"')
->toContain('aria-controls="zone-list"')
->toContain('aria-expanded="false"')
->toContain('<ul')
->toContain('id="zone-list"')
->toContain('role="listbox"')
->toContain('popover="manual"')
->toMatch('/anchor-name: (--material-choices-[a-z0-9]{10})/')
->toContain('x-modelable="value"')
->toContain('data-md-field-arrow')
// WAI-ARIA's combobox keyboard, Home and End included.
->toContain('x-on:keydown.home="jump($event, false)"')
->toContain('x-on:keydown.end="jump($event, true)"')
->toContain('<li x-show="filtered.length === 0" data-md-choices-empty>Nothing matches</li>')
->toContain('data-md-field-menu')
->toContain('data-md-field-option')
->not->toContain('class=');
preg_match('/anchor-name: (--material-choices-[a-z0-9]{10})/', $html, $anchor);
expect($html)->toContain("position-anchor: {$anchor[1]}");
});
it('shows the errors for the property and its items', function () {
Livewire::component('choices-errors', new class extends Component
{
/** @var list<int> */
public array $days = [];
public ?string $zone = null;
public function mount(): void
{
$this->addError('days.0', 'Mon is not a working day.');
$this->addError('zone', 'Choose a time zone.');
}
public function render(): string
{
return <<<'BLADE'
<div>
<x-choices wire:model="days" :options="[['id' => 1, 'name' => 'Mon']]" />
<x-choices wire:model="zone" searchable :options="[['id' => 'UTC', 'name' => 'UTC']]" />
</div>
BLADE;
}
});
expect(Livewire::test('choices-errors')->html())
->toContain('Mon is not a working day.')
->toContain('Choose a time zone.')
->toContain('aria-invalid="true"');
});
it('brings the stylesheets of what it renders, and draws its empty row', function () {
$css = (string) file_get_contents(__DIR__.'/../../../resources/css/components/choices.css');
expect($css)->toContain("@import './field.css';")
->toContain("@import './chip-set.css';")
->toContain("@import './chip.css';")
->toContain('[data-md-choices-empty] {')
->and((string) file_get_contents(__DIR__.'/../../../resources/css/all.css'))->toContain("@import './components/choices.css';");
});