Baue die redaktionellen Karten aus: formatierte Beschreibung, Dachzeile, Verteilung, Symbollage und Gestaltung
Widget cards, Version 2: - Beschreibung im Editor des Fließtexts (Webprofil). Version 1 (Klartext) wird beim Lesen angehoben: Leerzeile = Absatz, Zeilenumbruch = <br>. - Dachzeile über dem Titel (nur gespeichert, wenn ausgefüllt). - Verteilung: Karten vergrößern sich (Vorgabe, auto-fit statt auto-fill) oder Abstände gleichen aus (feste Kartenbreite, gleich breite Spalten). - Symbol über, links oder rechts neben dem Text, senkrecht oben/Mitte/unten. - Pinselstrich unter dem Titel, Trennstrich (flache Karten), Hervorhebung unter der Maus und bei Fokus (ohne Bewegung bei reduzierter Bewegung). - Hervorgehobene Variante umbricht per Flex, damit die übrigen Karten die Zeile teilen. Links in der Beschreibung liegen über dem gestreckten Titellink; Textfarben in hellen Karten gelten wie auf hellen Flächen. - Symbolfeld: Duplizieren einer Karte mit Symbol warf einen Skriptfehler (Vorlage noch nicht als Referenz da); behoben. Test angepasst: CmsHeadingIntroTest prüft den Selektor mit .widget-cards (Prosa-Regeln gelten jetzt auch in Karten). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c8d44caa75
commit
ef876465f0
24 files changed
+752
-62
No files matched your search
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Domain\Cms\Widgets\Types\CardsWidget;
|
||||
use App\Domain\Cms\Widgets\WidgetErrors;
|
||||
use App\Domain\Cms\Widgets\WidgetRegistry;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Redaktionelle Karten, Version 2: Beschreibung als formatierter Text, Dachzeile, Verteilung, Lage und senkrechte Ausrichtung
|
||||
* des Symbols, Pinselstrich, Trennstrich und Hervorhebung. Die bisherigen Einstellungen und die Ausgabe ohne neue
|
||||
* Einstellungen bleiben unverändert.
|
||||
*/
|
||||
class CmsEditorialCardsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @param array<string, mixed> $settings
|
||||
*/
|
||||
private function publish(string $path, array $data, array $settings = [], string $variant = 'standard', int $version = 2): string
|
||||
{
|
||||
$page = Page::query()->create(['path' => $path]);
|
||||
$service = app(PageService::class);
|
||||
$sections = [['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'cards', 'v' => $version, 'variant' => $variant, 'settings' => $settings, 'data' => $data]]]];
|
||||
$service->publish($page, $service->saveRevision($page, $sections, null, null, null));
|
||||
|
||||
return $this->get($path)->assertOk()->getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function card(array $extra = []): array
|
||||
{
|
||||
return ['items' => [['title' => 'Karte', 'url' => '/a'] + $extra]];
|
||||
}
|
||||
|
||||
public function test_version_one_texts_are_lifted_to_formatted_text_with_paragraphs_and_line_breaks(): void
|
||||
{
|
||||
$widget = app(WidgetRegistry::class)->upcast(['type' => 'cards', 'v' => 1, 'variant' => 'standard', 'data' => ['items' => [
|
||||
['title' => 'Eins', 'text' => "Erste Zeile\nzweite Zeile\n\nNeuer Absatz & <b>nicht fett</b>"],
|
||||
['title' => 'Zwei', 'text' => null],
|
||||
['title' => 'Drei'],
|
||||
]]]);
|
||||
|
||||
$this->assertSame(2, $widget['v']);
|
||||
$this->assertSame('<p>Erste Zeile<br>zweite Zeile</p><p>Neuer Absatz & <b>nicht fett</b></p>', $widget['data']['items'][0]['text']);
|
||||
$this->assertNull($widget['data']['items'][1]['text']);
|
||||
$this->assertArrayNotHasKey('text', $widget['data']['items'][2]);
|
||||
}
|
||||
|
||||
public function test_the_description_is_rendered_as_formatted_text_and_empty_ones_are_dropped(): void
|
||||
{
|
||||
$html = $this->publish('/karten-text', ['items' => [
|
||||
['title' => 'Mit Text', 'text' => '<p>Ein <strong>fetter</strong> Satz.</p><p style="text-align: center">Mitte</p><ul><li>Punkt</li></ul>'],
|
||||
['title' => 'Leer', 'text' => '<p></p>'],
|
||||
]]);
|
||||
|
||||
$this->assertStringContainsString('<div class="prose card-text"><p>Ein <strong>fetter</strong> Satz.</p><p class="ta-center">Mitte</p><ul><li><p>Punkt</p></li></ul></div>', $html);
|
||||
$this->assertSame(1, substr_count($html, 'card-text'), 'Eine leere Beschreibung erzeugt keinen Block.');
|
||||
}
|
||||
|
||||
public function test_the_description_field_is_the_website_editor_and_the_eyebrow_a_short_text_field(): void
|
||||
{
|
||||
$fields = app(WidgetRegistry::class)->get('cards')->dataFields();
|
||||
$repeater = $fields[0];
|
||||
$this->assertInstanceOf(Repeater::class, $repeater);
|
||||
|
||||
$children = collect($repeater->getDefaultChildComponents())->keyBy(fn ($field) => $field->getName());
|
||||
$this->assertInstanceOf(RichEditor::class, $children['text']);
|
||||
$this->assertSame(['eyebrow', 'title', 'symbol', 'text', 'url'], $children->keys()->take(5)->all());
|
||||
}
|
||||
|
||||
public function test_the_eyebrow_stands_above_the_title_and_is_only_stored_when_filled(): void
|
||||
{
|
||||
$html = $this->publish('/karten-dachzeile', ['items' => [
|
||||
['title' => 'Mit', 'eyebrow' => ' Thema ', 'url' => '/a'],
|
||||
['title' => 'Ohne', 'eyebrow' => ' ', 'url' => '/b'],
|
||||
]]);
|
||||
|
||||
$this->assertMatchesRegularExpression('~<p class="card-eyebrow">Thema</p>\s*<h3 class="card-title">\s*<a href="/a">Mit</a>~', $html);
|
||||
$this->assertSame(1, substr_count($html, 'card-eyebrow'));
|
||||
|
||||
[$clean] = app(WidgetRegistry::class)->get('cards')->clean(['items' => [['title' => 'Ohne', 'eyebrow' => '', 'text' => '', 'url' => '']]], [], new WidgetErrors);
|
||||
$this->assertSame(['title' => 'Ohne', 'text' => null, 'url' => null, 'image' => null], $clean['items'][0]);
|
||||
}
|
||||
|
||||
public function test_without_new_settings_the_list_markup_is_unchanged(): void
|
||||
{
|
||||
$html = $this->publish('/karten-vorgabe', $this->card(['text' => '<p>Text</p>', 'symbol' => 'buch']));
|
||||
|
||||
$this->assertStringContainsString('<ul class="cards cards-grid">', $html);
|
||||
$this->assertStringNotContainsString('card-row', $html);
|
||||
$this->assertStringNotContainsString('card-eyebrow', $html);
|
||||
$this->assertStringNotContainsString('lf-card__brush', $html);
|
||||
$this->assertMatchesRegularExpression('~<div class="card-body">\s*<svg[^>]*class="brand-symbol lf-card__symbol"~s', $html);
|
||||
}
|
||||
|
||||
public function test_each_new_setting_adds_its_class_only_when_it_deviates_from_the_default(): void
|
||||
{
|
||||
$cases = [
|
||||
['distribution' => 'space', 'cards--spaced'],
|
||||
['distribution' => 'grow', null],
|
||||
['divider' => 'line', 'cards--lines'],
|
||||
['hover' => 'lift', 'cards--hover'],
|
||||
['symbol_position' => 'left', 'cards--symbol-left'],
|
||||
['symbol_position' => 'right', 'cards--symbol-right'],
|
||||
['symbol_position' => 'top', null],
|
||||
];
|
||||
|
||||
foreach ($cases as $index => $case) {
|
||||
$class = array_pop($case);
|
||||
$html = $this->publish('/karten-einstellung-'.$index, $this->card(['symbol' => 'buch']), $case);
|
||||
|
||||
if ($class === null) {
|
||||
$this->assertStringContainsString('<ul class="cards cards-grid">', $html, json_encode($case));
|
||||
} else {
|
||||
$this->assertStringContainsString($class, $html, json_encode($case));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function test_the_symbol_beside_the_text_wraps_symbol_and_text_in_a_row_and_aligns_vertically(): void
|
||||
{
|
||||
$items = ['items' => [
|
||||
['title' => 'Mit', 'eyebrow' => 'Thema', 'text' => '<p>Text</p>', 'symbol' => 'buch', 'url' => '/a'],
|
||||
['title' => 'Ohne', 'url' => '/b'],
|
||||
]];
|
||||
|
||||
$html = $this->publish('/karten-links', $items, ['symbol_position' => 'left', 'symbol_align' => 'center']);
|
||||
$this->assertStringContainsString('<ul class="cards cards-grid cards--symbol-left cards--symbol-v-center">', $html);
|
||||
$this->assertSame(1, substr_count($html, 'card-row'), 'Nur die Karte mit Symbol hat eine Zeile.');
|
||||
$this->assertMatchesRegularExpression('~<div class="card-row">\s*<svg[^>]*lf-card__symbol[^>]*>.*?</svg>\s*<div class="card-main">\s*<p class="card-eyebrow">Thema</p>\s*<h3 class="card-title">.*?<div class="prose card-text"><p>Text</p></div>\s*</div>\s*</div>\s*</div>\s*</li>~s', $html);
|
||||
|
||||
$unaligned = $this->publish('/karten-links-oben', $items, ['symbol_position' => 'right']);
|
||||
$this->assertStringContainsString('<ul class="cards cards-grid cards--symbol-right">', $unaligned, 'Oben ist die Vorgabe und braucht keine Klasse.');
|
||||
|
||||
$above = $this->publish('/karten-oben-mittig', $items, ['symbol_align' => 'center']);
|
||||
$this->assertStringNotContainsString('symbol-v-', $above, 'Die senkrechte Lage wirkt nur neben dem Text.');
|
||||
}
|
||||
|
||||
public function test_the_brush_stands_under_each_title(): void
|
||||
{
|
||||
$html = $this->publish('/karten-pinsel', ['items' => [['title' => 'Eins', 'url' => '/a'], ['title' => 'Zwei', 'url' => '/b']]], ['accent' => 'brush']);
|
||||
|
||||
$this->assertSame(2, substr_count($html, 'lf-card__brush'));
|
||||
$this->assertMatchesRegularExpression('~</h3>\s*<svg[^>]*lf-heading-brush lf-card__brush~', $html);
|
||||
}
|
||||
|
||||
public function test_the_divider_is_not_offered_to_the_compact_list(): void
|
||||
{
|
||||
$data = ['items' => [['title' => 'Eins'], ['title' => 'Zwei']]];
|
||||
|
||||
$this->assertStringContainsString('cards--lines', $this->publish('/karten-linien', $data, ['divider' => 'line']));
|
||||
$this->assertStringNotContainsString('cards--lines', $this->publish('/karten-linien-liste', $data, ['divider' => 'line'], 'compact'));
|
||||
}
|
||||
|
||||
public function test_the_layout_ignores_invalid_values(): void
|
||||
{
|
||||
$layout = CardsWidget::layout(['distribution' => 'wild', 'symbol_position' => 'oben', 'symbol_align' => 'mitte', 'divider' => 'dick', 'hover' => 'zoom', 'accent' => 'bunt']);
|
||||
|
||||
$this->assertSame(['align' => 'left', 'size' => 'medium', 'position' => 'top', 'valign' => 'top', 'distribution' => 'grow', 'divider' => false, 'brush' => false, 'hover' => false], $layout);
|
||||
}
|
||||
|
||||
public function test_unknown_values_are_rejected_when_saving(): void
|
||||
{
|
||||
foreach ([['distribution' => 'wild'], ['symbol_position' => 'unten'], ['symbol_align' => 'mitte'], ['hover' => 'zoom']] as $index => $settings) {
|
||||
try {
|
||||
$this->publish('/karten-falsch-'.$index, $this->card(), $settings);
|
||||
$this->fail("Fall $index wurde angenommen.");
|
||||
} catch (ValidationException $exception) {
|
||||
$this->assertNotEmpty($exception->errors(), "Fall $index");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function test_the_stylesheet_keeps_links_clickable_and_colors_readable_on_light_cards(): void
|
||||
{
|
||||
$css = (string) file_get_contents(resource_path('css/widgets.css'));
|
||||
|
||||
// Der gestreckte Titellink legt sich über die Karte; Links in der Beschreibung müssen darüber liegen.
|
||||
$this->assertMatchesRegularExpression('/\.card \.prose a \{\s*position: relative;\s*z-index: 1;/', $css);
|
||||
// Die Karte bleibt auf dunklen und grünen Abschnitten hell; die aufgehellten Textfarben dürfen dort nicht gelten.
|
||||
$this->assertMatchesRegularExpression('/\.cards:not\(\.cards-compact, \.cards--lines\) \.card \.prose \{\s*--tc-marine: var\(--lf-navy\);/', $css);
|
||||
// Beide Verteilungen behalten gleich breite Spalten, damit die Trennstriche in der Mitte der Lücke liegen.
|
||||
$this->assertStringNotContainsString('justify-content: space-between', substr($css, (int) strpos($css, 'Redaktionelle Karten: Dachzeile')));
|
||||
$this->assertStringContainsString(':is(.widget-prose, .widget-heading, .widget-cards) .prose p', $css);
|
||||
$this->assertStringContainsString('prefers-reduced-motion', substr($css, (int) strpos($css, '.cards--hover .card {')));
|
||||
}
|
||||
|
||||
public function test_the_symbol_field_survives_duplicating_a_card(): void
|
||||
{
|
||||
// Beim Duplizieren wertet das Feld die Vorschau aus, bevor die Vorlage als Referenz bereitsteht (Skriptfehler
|
||||
// „Cannot read properties of undefined (reading 'innerHTML')“). Der Zugriff darf deshalb nicht auf $refs.start allein beruhen.
|
||||
$view = (string) file_get_contents(resource_path('views/filament/cms/symbol-feld.blade.php'));
|
||||
|
||||
$this->assertStringNotContainsString('this.$refs.start.innerHTML', $view);
|
||||
$this->assertStringContainsString("this.\$root.querySelector('template')", $view);
|
||||
}
|
||||
|
||||
public function test_the_summary_and_media_paths_are_unchanged(): void
|
||||
{
|
||||
$type = app(WidgetRegistry::class)->get('cards');
|
||||
|
||||
$this->assertSame('2 Karten: Eins, Zwei', $type->summary(['data' => ['items' => [['title' => 'Eins'], ['title' => 'Zwei']]]]));
|
||||
$this->assertSame(2, $type->version());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user