Plan step 36 ("Interaction is the shared classes", the user, 2026-09-14).
The dismiss button hand-rolled md-state-layer, md-focus-ring and
md-touch-target, and alert.css's own header said so; it now renders the
classes and keeps only its own size, offset and colour.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qwx5USif3wFFmxtHg5U1g9
70 lines
3.3 KiB
PHP
70 lines
3.3 KiB
PHP
<?php
|
|
|
|
use NoNameWeb\LivewireMaterial\Tests\Support\ComponentStylesheet;
|
|
|
|
it('states a notice in its state\'s container, with the state\'s icon', function () {
|
|
$html = (string) $this->blade('<x-alert title="Storage almost full" description="3.8 of 4 GB" color="warning" />');
|
|
|
|
expect($html)
|
|
->toContain('role="status"')
|
|
->toContain('data-md-alert')
|
|
->toContain('data-md-color="warning"')
|
|
->toContain('Storage almost full')
|
|
->toContain('3.8 of 4 GB')
|
|
->toContain('<svg')
|
|
->and(ComponentStylesheet::read('alert')->declarations("[data-md-alert][data-md-color='warning']"))->toBe([
|
|
'background-color' => 'var(--md-sys-color-warning-container)',
|
|
'color' => 'var(--md-sys-color-on-warning-container)',
|
|
]);
|
|
});
|
|
|
|
it('is a status whatever its colour, and interrupts only when asked to', function () {
|
|
expect((string) $this->blade('<x-alert description="Saved." tone="success" />'))->toContain('role="status"')->toContain('data-md-color="success"')
|
|
->and((string) $this->blade('<x-alert description="Heads up." />'))->toContain('role="status"')->toContain('data-md-color="info"')
|
|
->and((string) $this->blade('<x-alert description="Broken." color="error" />'))->toContain('role="status"')
|
|
->and((string) $this->blade('<x-alert description="Broken." color="error" assertive />'))->toContain('role="alert"');
|
|
});
|
|
|
|
it('falls back to info for an unknown colour', function () {
|
|
expect((string) $this->blade('<x-alert description="Odd." color="purple" />'))->toContain('data-md-color="info"');
|
|
});
|
|
|
|
it('takes actions, drops its icon on request, and can be dismissed', function () {
|
|
$html = (string) $this->blade(<<<'BLADE'
|
|
<x-alert :icon="false" dismissible>
|
|
The connection dropped.
|
|
<x-slot:actions><x-button label="Try again" /></x-slot:actions>
|
|
</x-alert>
|
|
BLADE);
|
|
|
|
expect($html)
|
|
->toContain('The connection dropped.')
|
|
->toContain('data-md-alert-actions')
|
|
->toContain('Try again')
|
|
->toContain('x-data="{ shown: true }"')
|
|
->toContain('data-md-alert-dismiss')
|
|
->toContain('aria-label="Dismiss"')
|
|
->and(substr_count($html, '<svg'))->toBe(1);
|
|
});
|
|
|
|
it('reaches 48px from its 40px dismiss button, from the foundation\'s class, not a copy', function () {
|
|
$css = ComponentStylesheet::read('alert');
|
|
|
|
expect($css->declarations('[data-md-alert-dismiss]'))->toMatchArray([
|
|
'width' => 'var(--md-sys-measurement-space500)',
|
|
'height' => 'var(--md-sys-measurement-space500)',
|
|
])
|
|
->and($css->has('[data-md-alert-dismiss]::after'))->toBeFalse()
|
|
->and($css->has('[data-md-alert-dismiss]::before'))->toBeFalse()
|
|
->and((string) $this->blade('<x-alert description="Draft." dismissible />'))
|
|
->toMatch('/class="md-state-layer md-focus-ring md-touch-target" data-md-alert-dismiss/');
|
|
});
|
|
|
|
it('draws neutral in surface-container-high, on-surface', function () {
|
|
expect((string) $this->blade('<x-alert description="Draft." color="neutral" />'))->toContain('data-md-color="neutral"')
|
|
->and(ComponentStylesheet::read('alert')->declarations("[data-md-alert][data-md-color='neutral']"))->toBe([
|
|
'background-color' => 'var(--md-sys-color-surface-container-high)',
|
|
'color' => 'var(--md-sys-color-on-surface)',
|
|
]);
|
|
});
|