Ergänze Farbe aus der Palette und Schriftgrößen je Widget
CI Feature / test (push) Failing after 5m29s
CI Feature / test (push) Failing after 5m29s
Gemeinsamer Vertrag in WidgetType (typography(), paletteTarget()) mit den Einstellungen heading_size, text_size und palette; WidgetAppearance setzt Klassen und Eigenschaften an der Hülle, nur wenn ein Wert gewählt ist. Eine absolute Größenskala aus den Designwerten gilt in jedem Widget gleich; ohne Wahl bleibt die bisherige Größe. Die Palettenfarbe färbt je Art die Fläche des Widgets (hull) oder dessen eigene Fläche (face). Der Verwendungsnachweis der Palette zählt jetzt auch Widgets, damit die Bestätigung einer Farbänderung und die Sperre beim Entfernen greifen. Der Vertragstest für Einstellungsgruppen nimmt die gemeinsamen Schlüssel bewusst aus, weil sie eigene Gruppen im Editor haben. ADR-68, Abnahme unter docs/ux/verwaltung/abnahme/widget-flaeche-schrift.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
63ad125859
commit
2b00905f00
36 files changed
+910
-12
No files matched your search
@@ -0,0 +1,251 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Domain\Cms\Widgets\Support\WidgetAppearance;
|
||||
use App\Domain\Cms\Widgets\WidgetRegistry;
|
||||
use App\Domain\Design\DesignPalette;
|
||||
use App\Filament\Resources\Pages\Pages\CreatePage;
|
||||
use App\Filament\Resources\Pages\Pages\EditPage;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Testing\TestAction;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Farbe und Schriftgrößen je Widget (ADR-68): Prüfregeln, Darstellung, Rückfall und Verwendungsnachweis der Palette.
|
||||
* Die Ausgabe bisheriger Widgets ohne diese Einstellungen sichert CmsSectionLegacyRenderTest.
|
||||
*/
|
||||
class CmsWidgetAppearanceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
DesignPalette::flush();
|
||||
DesignPalette::save(null, 'Dunkelblau', '#032551', '#ffffff');
|
||||
DesignPalette::save(null, 'Helles Grün', '#e8f0de', '#032551');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $settings
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function heading(array $settings = []): array
|
||||
{
|
||||
return ['type' => 'heading', 'v' => 1, 'settings' => $settings, 'data' => ['heading' => 'Titel', 'intro' => 'Einleitung']];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $settings
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function cards(array $settings = []): array
|
||||
{
|
||||
return ['type' => 'cards', 'v' => 1, 'settings' => $settings, 'data' => ['items' => [['title' => 'Karte', 'text' => 'Text']]]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $widget
|
||||
*/
|
||||
private function publish(string $path, array $widget): Page
|
||||
{
|
||||
$page = Page::query()->create(['path' => $path]);
|
||||
$service = app(PageService::class);
|
||||
$service->publish($page, $service->saveRevision($page, [['layout' => 'u4', 'style' => [], 'slots' => [$widget]]], null, null, null));
|
||||
|
||||
return $page->fresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $widget
|
||||
*/
|
||||
private function hull(string $path, array $widget): string
|
||||
{
|
||||
$this->publish($path, $widget);
|
||||
$html = $this->get($path)->assertOk()->getContent();
|
||||
preg_match('/<section class="block widget [^>]*>/', $html, $match);
|
||||
|
||||
return $match[0] ?? '';
|
||||
}
|
||||
|
||||
public function test_sizes_are_shared_settings_of_widgets_that_declare_them(): void
|
||||
{
|
||||
$registry = app(WidgetRegistry::class);
|
||||
|
||||
$this->assertSame(['small', 'medium', 'large', 'xlarge'], array_keys($registry->get('heading')->settingOptions()['heading_size']));
|
||||
$this->assertSame(['normal', 'large', 'xlarge'], array_keys($registry->get('heading')->settingOptions()['text_size']));
|
||||
$this->assertArrayNotHasKey('heading_size', $registry->get('prose')->settingOptions());
|
||||
$this->assertArrayHasKey('text_size', $registry->get('prose')->settingOptions());
|
||||
$this->assertArrayNotHasKey('text_size', $registry->get('inquiry')->settingOptions());
|
||||
}
|
||||
|
||||
public function test_description_text_has_no_step_below_the_body_size(): void
|
||||
{
|
||||
$this->assertArrayNotHasKey('small', WidgetAppearance::TEXT);
|
||||
$this->assertSame('Normal', WidgetAppearance::TEXT['normal']);
|
||||
}
|
||||
|
||||
public function test_invalid_sizes_and_unknown_slots_are_rejected_on_save(): void
|
||||
{
|
||||
$registry = app(WidgetRegistry::class);
|
||||
|
||||
foreach ([['heading_size' => 'gigantic'], ['text_size' => 'small'], ['palette' => 'c9']] as $settings) {
|
||||
try {
|
||||
$registry->normalize([$this->heading($settings) + ['id' => null, 'variant' => 'standard', 'refs' => []]]);
|
||||
$this->fail('Erwartet: Ablehnung für '.json_encode($settings));
|
||||
} catch (ValidationException $e) {
|
||||
$this->assertNotEmpty($e->errors());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function test_a_widget_without_the_setting_is_rejected_when_it_sends_it_anyway(): void
|
||||
{
|
||||
$registry = app(WidgetRegistry::class);
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
$registry->normalize([['id' => null, 'type' => 'inquiry', 'v' => 1, 'variant' => 'standard', 'settings' => ['heading_size' => 'large'], 'data' => [], 'refs' => []]]);
|
||||
}
|
||||
|
||||
public function test_sizes_become_classes_on_the_widget_shell_and_only_then(): void
|
||||
{
|
||||
$plain = $this->hull('/a', $this->heading());
|
||||
$this->assertStringNotContainsString('widget-hs', $plain);
|
||||
$this->assertStringNotContainsString('widget-ts', $plain);
|
||||
$this->assertStringNotContainsString('widget-palette', $plain);
|
||||
$this->assertStringNotContainsString('style=', $plain);
|
||||
|
||||
$sized = $this->hull('/b', $this->heading(['heading_size' => 'large', 'text_size' => 'xlarge']));
|
||||
$this->assertStringContainsString('widget-hs widget-hs-large', $sized);
|
||||
$this->assertStringContainsString('widget-ts widget-ts-xlarge', $sized);
|
||||
}
|
||||
|
||||
public function test_a_palette_colour_on_a_plain_widget_sets_the_surface_on_the_shell(): void
|
||||
{
|
||||
$dark = $this->hull('/dunkel', $this->heading(['palette' => 'c1']));
|
||||
$this->assertStringContainsString('widget-palette widget-palette--hull', $dark);
|
||||
$this->assertStringContainsString('scope-dark', $dark);
|
||||
$this->assertStringContainsString('--color-surface: #032551', $dark);
|
||||
|
||||
$light = $this->hull('/hell', $this->heading(['palette' => 'c2']));
|
||||
$this->assertStringContainsString('--color-surface: #e8f0de', $light);
|
||||
$this->assertStringNotContainsString('scope-dark', $light);
|
||||
}
|
||||
|
||||
public function test_widgets_with_their_own_face_colour_the_face_not_a_frame(): void
|
||||
{
|
||||
$cards = $this->hull('/karten', $this->cards(['palette' => 'c2']));
|
||||
$this->assertStringContainsString('widget-palette widget-palette--face', $cards);
|
||||
$this->assertStringNotContainsString('widget-palette--hull', $cards);
|
||||
}
|
||||
|
||||
public function test_a_stored_slot_that_no_longer_exists_falls_back_without_error(): void
|
||||
{
|
||||
$this->publish('/alt', $this->heading(['palette' => 'c2']));
|
||||
DesignPalette::flush();
|
||||
\DB::table('site_settings')->where('key', 'design.palette')->update(['value' => json_encode(['next' => 3, 'slots' => []])]);
|
||||
DesignPalette::flush();
|
||||
|
||||
$html = $this->get('/alt')->assertOk()->getContent();
|
||||
preg_match('/<section class="block widget [^>]*>/', $html, $match);
|
||||
|
||||
$this->assertStringNotContainsString('widget-palette', $match[0] ?? '');
|
||||
$this->assertStringContainsString('Titel', $html);
|
||||
}
|
||||
|
||||
public function test_a_colour_used_only_by_a_widget_is_counted_and_cannot_be_removed(): void
|
||||
{
|
||||
$page = $this->publish('/nur-widget', $this->heading(['palette' => 'c2']));
|
||||
|
||||
$usage = DesignPalette::usage();
|
||||
$this->assertArrayHasKey('c2', $usage);
|
||||
$this->assertSame($page->id, $usage['c2'][0]['page_id']);
|
||||
$this->assertSame(1, $usage['c2'][0]['published']);
|
||||
$this->assertArrayNotHasKey('c1', $usage);
|
||||
|
||||
$this->assertNotEmpty(DesignPalette::remove('c2'));
|
||||
$this->assertNotNull(DesignPalette::find('c2'));
|
||||
}
|
||||
|
||||
public function test_a_draft_that_only_a_widget_uses_is_counted_as_draft(): void
|
||||
{
|
||||
$page = $this->publish('/entwurf', $this->heading());
|
||||
app(PageService::class)->saveRevision($page, [['layout' => 'u4', 'style' => [], 'slots' => [$this->heading(['palette' => 'c1'])]]], null, null, null);
|
||||
|
||||
$usage = DesignPalette::usage();
|
||||
$this->assertSame(0, $usage['c1'][0]['published']);
|
||||
$this->assertSame(1, $usage['c1'][0]['draft']);
|
||||
}
|
||||
|
||||
public function test_image_text_takes_the_palette_colour_on_its_own_face(): void
|
||||
{
|
||||
$widget = ['type' => 'image_text', 'v' => 3, 'variant' => 'image_left', 'settings' => ['palette' => 'c1', 'surface' => 'cream'], 'data' => ['title' => 'Titel', 'body' => '<p>Text</p>'], 'refs' => []];
|
||||
$this->publish('/bt', $widget);
|
||||
|
||||
$html = $this->get('/bt')->assertOk()->getContent();
|
||||
|
||||
$this->assertStringContainsString('lf-bt lf-bt--palette', $html);
|
||||
$this->assertStringNotContainsString('lf-bt--cream', $html);
|
||||
$this->assertStringContainsString('widget-palette widget-palette--face scope-dark', $html);
|
||||
}
|
||||
|
||||
public function test_the_notice_widget_keeps_its_own_surface_setting_and_offers_no_palette(): void
|
||||
{
|
||||
$this->assertArrayNotHasKey('palette', app(WidgetRegistry::class)->get('notice')->settingOptions());
|
||||
$this->assertArrayHasKey('surface', app(WidgetRegistry::class)->get('notice')->settingOptions());
|
||||
}
|
||||
|
||||
public function test_the_hero_offers_sizes_but_no_palette(): void
|
||||
{
|
||||
$options = app(WidgetRegistry::class)->get('hero')->settingOptions();
|
||||
|
||||
$this->assertArrayHasKey('heading_size', $options);
|
||||
$this->assertArrayHasKey('text_size', $options);
|
||||
$this->assertArrayNotHasKey('palette', $options);
|
||||
}
|
||||
|
||||
private function editor(): User
|
||||
{
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
|
||||
return $editor;
|
||||
}
|
||||
|
||||
public function test_editor_saves_sizes_and_colour_and_shows_them_in_the_widget_dialog(): void
|
||||
{
|
||||
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
||||
$widget = ['type' => 'heading', 'data' => ['settings' => ['heading_size' => 'xlarge', 'text_size' => 'large', 'palette' => 'c2'], 'data' => ['heading' => 'Größe', 'intro' => '<p>Text</p>']]];
|
||||
$slots = [(string) Str::uuid() => ['widget' => [(string) Str::uuid() => $widget]]];
|
||||
|
||||
Livewire::actingAs($this->editor(), 'staff')
|
||||
->test(CreatePage::class)
|
||||
->fillForm(['path' => '/groesse', 'sections' => [['id' => null, 'layout' => 'u4', 'style' => [], 'slots' => $slots]]])
|
||||
->call('create')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
$page = Page::query()->where('path', '/groesse')->firstOrFail();
|
||||
$this->assertSame(
|
||||
['heading_size' => 'xlarge', 'text_size' => 'large', 'palette' => 'c2'],
|
||||
$page->latestRevision->sections[0]['slots'][0]['settings'],
|
||||
);
|
||||
|
||||
$component = Livewire::actingAs($this->editor(), 'staff')->test(EditPage::class, ['record' => $page->id]);
|
||||
$sectionKey = array_key_first($component->get('data.sections'));
|
||||
$slotKey = array_key_first($component->get("data.sections.$sectionKey.slots"));
|
||||
$itemKey = array_key_first($component->get("data.sections.$sectionKey.slots.$slotKey.widget"));
|
||||
|
||||
$component->mountAction(TestAction::make('edit')->schemaComponent("sections.$sectionKey.slots.$slotKey.widget")->arguments(['item' => $itemKey]))
|
||||
->assertFormFieldExists('settings.heading_size')
|
||||
->assertFormFieldExists('settings.text_size')
|
||||
->assertFormFieldExists('settings.palette');
|
||||
}
|
||||
}
|
||||
@@ -155,6 +155,26 @@ public function test_changing_the_values_of_a_used_colour_shows_the_affected_pag
|
||||
$this->assertStringContainsString('--color-surface: #2f6407;', $this->get('/live')->getContent());
|
||||
}
|
||||
|
||||
public function test_a_colour_used_only_by_a_widget_also_waits_for_confirmation_and_cannot_be_removed(): void
|
||||
{
|
||||
DesignPalette::save(null, 'Grün', '#3b7b09', '#ffffff');
|
||||
$page = Page::query()->create(['path' => '/nur-widget']);
|
||||
$service = app(PageService::class);
|
||||
$service->publish($page, $service->saveRevision($page, [['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'heading', 'v' => 1, 'settings' => ['palette' => 'c1'], 'data' => ['heading' => 'Widget']]]]], null, null, null));
|
||||
|
||||
$component = Livewire::actingAs($this->admin(), 'staff')->test(DesignFarben::class)
|
||||
->call('bearbeiten', 'c1')
|
||||
->call('speichern', 'Grün', '#2f6407', '#ffffff');
|
||||
|
||||
$this->assertSame('#3b7b09', DesignPalette::find('c1')['bg'], 'Bis zur Bestätigung ist nichts gespeichert.');
|
||||
$frage = $component->get('bestaetigung');
|
||||
$this->assertSame('wirkung', $frage['aktion']);
|
||||
$this->assertStringContainsString('/nur-widget', implode(' ', $frage['liste']));
|
||||
|
||||
$this->assertNotEmpty(DesignPalette::remove('c1'));
|
||||
$this->assertNotNull(DesignPalette::find('c1'));
|
||||
}
|
||||
|
||||
public function test_cancelling_the_confirmation_keeps_the_stored_colour(): void
|
||||
{
|
||||
DesignPalette::save(null, 'Grün', '#3b7b09', '#ffffff');
|
||||
|
||||
Reference in new issue
Block a user