Ersetze die Symbolauswahl im CMS durch einen Wähler mit Raster, Gruppen und Suche
Das Feld steht in den Einstellungen aller Widgets und je Karte und Merkmal. Es trägt nur die Zeichnung des gewählten Symbols; der Katalog mit allen Zeichnungen kommt beim Öffnen in einer Anfrage (nur Redaktion und Katalogverwaltung). Mit Tastatur bedienbar. Dazu Katalog-Dokumentation, Tokens und Abnahme mit Screenshots (lokal geprüft, nicht auf luf-test). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
edca8e864c
commit
1270e2e948
21 files changed
+409
-16
No files matched your search
@@ -6,6 +6,7 @@
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Domain\Cms\Widgets\Types\FeaturesWidget;
|
||||
use App\Domain\Cms\Widgets\WidgetRegistry;
|
||||
use App\Support\Brand\SymbolCatalog;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Tests\TestCase;
|
||||
@@ -42,6 +43,30 @@ private function publish(string $path, array $widget, string $layout = 'u4'): st
|
||||
return $this->get($path)->assertOk()->getContent();
|
||||
}
|
||||
|
||||
public function test_every_symbol_of_the_library_can_be_saved_and_is_shown_in_a_heading_a_card_and_a_feature(): void
|
||||
{
|
||||
$keys = array_keys(SymbolCatalog::options());
|
||||
$this->assertGreaterThanOrEqual(70, count($keys));
|
||||
|
||||
// Jeder angebotene Schlüssel wird gespeichert und mit seiner zugeschnittenen Zeichnung ausgegeben (eine Seite je Widgetart genügt, die Zuordnung der Zeichnung prüfen die Unit-Tests).
|
||||
$heading = $this->publish('/bibliothek-ueberschrift', $this->widget('heading', ['heading' => 'Filme'], ['symbol' => 'checkliste']));
|
||||
$this->assertMatchesRegularExpression('~<h2><svg[^>]*aria-hidden="true"[^>]*class="brand-symbol lf-heading-symbol"[^>]*viewBox="[\d. ]+"[^>]*>.*?</svg>Filme</h2>~s', $heading);
|
||||
|
||||
$cards = $this->publish('/bibliothek-karten', $this->widget('cards', ['items' => [['title' => 'Karte', 'url' => '/a', 'symbol' => 'zivilcourage']]]));
|
||||
$this->assertMatchesRegularExpression('~<svg[^>]*class="brand-symbol lf-card__symbol"~', $cards);
|
||||
|
||||
$features = $this->publish('/bibliothek-merkmale', $this->widget('features', ['items' => array_map(
|
||||
fn (string $key): array => ['symbol' => $key, 'title' => $key],
|
||||
array_slice($keys, 0, 12),
|
||||
)]));
|
||||
$this->assertSame(12, preg_match_all('~<svg[^>]*class="brand-symbol lf-features__symbol"~', $features));
|
||||
|
||||
// Alle Schlüssel nacheinander: nichts davon darf beim Speichern abgelehnt werden.
|
||||
foreach (array_chunk($keys, 12) as $index => $chunk) {
|
||||
$this->publish('/bibliothek-alle-'.$index, $this->widget('features', ['items' => array_map(fn (string $key): array => ['symbol' => $key, 'title' => $key], $chunk)]));
|
||||
}
|
||||
}
|
||||
|
||||
public function test_a_heading_shows_its_symbol_inside_the_heading_and_the_brush_below(): void
|
||||
{
|
||||
$html = $this->publish('/symbol', $this->widget('heading', ['heading' => 'Filme', 'intro' => 'Kurz erklärt'], ['symbol' => 'filmklappe', 'accent' => 'brush']));
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Filament\Resources\Pages\Pages\CreatePage;
|
||||
use App\Filament\Support\SymbolField;
|
||||
use App\Models\User;
|
||||
use App\Support\Brand\SymbolCatalog;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\ViewErrorBag;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Symbolwähler im CMS: Katalog und Bilder nur für Redaktion und Katalogverwaltung, Feld ohne Bilder im Formular.
|
||||
*/
|
||||
class SymbolPickerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_the_catalog_is_only_for_editorial_staff(): void
|
||||
{
|
||||
$this->get(route('editorial.symbols'))->assertRedirect();
|
||||
|
||||
$member = User::factory()->create();
|
||||
$this->actingAs($member, 'staff')->get(route('editorial.symbols'))->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_the_catalog_lists_every_offered_symbol_in_groups_with_search_words(): void
|
||||
{
|
||||
$response = $this->actingAs(User::factory()->redakteur()->create(), 'staff')->getJson(route('editorial.symbols'))->assertOk();
|
||||
|
||||
$groups = $response->json('groups');
|
||||
$keys = array_merge(...array_map(fn (array $group): array => array_column($group['items'], 'key'), $groups));
|
||||
|
||||
$this->assertSame(array_keys(SymbolCatalog::options()), $keys);
|
||||
$this->assertGreaterThanOrEqual(70, count($keys));
|
||||
$this->assertNotContains('signalstrahlen', $keys);
|
||||
$this->assertNotContains('gelbe-unterstreichung', $keys);
|
||||
$this->assertSame('Film', $groups[1]['name']);
|
||||
$this->assertContains('wiedergabe', array_column($groups[1]['items'], 'key'));
|
||||
$this->assertSame(mb_strtolower($groups[1]['items'][0]['title']), explode(' ', $groups[1]['items'][0]['search'])[0], 'Der Titel gehört zu den Suchwörtern.');
|
||||
}
|
||||
|
||||
public function test_every_entry_carries_its_cleaned_drawing_so_no_single_image_requests_are_needed(): void
|
||||
{
|
||||
$response = $this->actingAs(User::factory()->redakteur()->create(), 'staff')->getJson(route('editorial.symbols'))->assertOk();
|
||||
|
||||
$this->assertStringContainsString('private', (string) $response->headers->get('Cache-Control'));
|
||||
|
||||
foreach ($response->json('groups') as $group) {
|
||||
foreach ($group['items'] as $item) {
|
||||
$this->assertStringStartsWith('<svg aria-hidden="true"', $item['svg'], $item['key']);
|
||||
$this->assertStringContainsString('viewBox="', $item['svg'], $item['key']);
|
||||
$this->assertStringNotContainsString('<title', $item['svg'], $item['key']);
|
||||
$this->assertStringNotContainsString('<script', $item['svg'], $item['key']);
|
||||
$this->assertMatchesRegularExpression('/^<svg[^>]*>.*<\/svg>$/s', $item['svg'], $item['key']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function test_the_field_carries_only_the_chosen_drawing_and_loads_the_rest_when_opened(): void
|
||||
{
|
||||
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$component = Livewire::actingAs($editor, 'staff')->test(CreatePage::class);
|
||||
|
||||
view()->share('errors', new ViewErrorBag);
|
||||
|
||||
$html = Schema::make($component->instance())
|
||||
->statePath('probe')
|
||||
->components([SymbolField::make('symbol', 'Symbol (optional)')])
|
||||
->fill(['symbol' => 'wiedergabe'])
|
||||
->toHtml();
|
||||
|
||||
$this->assertStringContainsString('Symbol (optional)', $html);
|
||||
$this->assertStringContainsString('Wiedergabe', $html, 'Der Titel des gewählten Symbols steht schon im Formular.');
|
||||
$this->assertStringContainsString('Anderes Symbol wählen', $html);
|
||||
$this->assertStringContainsString('/redaktion/symbole', stripslashes($html));
|
||||
// Nur das gewählte Symbol steht im Formular (als Vorschau und als Vorlage), alle anderen werden erst beim Öffnen geladen.
|
||||
preg_match_all('~<svg aria-hidden="true" focusable="false".*?</svg>~s', $html, $drawings);
|
||||
$this->assertCount(1, array_unique($drawings[0]));
|
||||
$this->assertLessThanOrEqual(2, count($drawings[0]));
|
||||
$this->assertLessThan(20000, strlen($html), 'Das Feld darf die Formularantwort nicht aufblähen.');
|
||||
|
||||
$this->assertTrue(Validator::make(['symbol' => 'wiedergabe'], ['symbol' => ['nullable', 'in:'.implode(',', array_keys(SymbolCatalog::options()))]])->passes());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user