Verlagere Name, Sprungmarke und Sichtbarkeit eines Abschnitts in einen Einstellungsdialog und verschlanke den Seitenaufbau
CI Feature / test (push) Successful in 4m33s
CI Feature / test (push) Successful in 4m33s
Ein Zahnrad im Abschnittskopf öffnet den Dialog; Übernehmen ändert nur den Seitenentwurf, Abbrechen, Schließen und Esc verwerfen. Die Sprungmarke wird mit denselben Regeln und Texten wie beim Speichern geprüft (PageSections::anchorProblem). Ein Speicherfehler zu Name oder Sprungmarke steht am Abschnitt und führt zum Dialog. Der Eingabeblock in jedem Abschnitt, die gestrichelten Rahmen um Plätze und die Rahmen um Bausteinvorschauen entfallen; Seitenformat und Speicherwege bleiben. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0492133201
commit
d03fcfceaf
9 files changed
+421
-59
No files matched your search
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Domain\Cms\Sections\PageSections;
|
||||
use App\Filament\Resources\Pages\Pages\EditPage;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Testing\TestAction;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Features\SupportTesting\Testable;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Einstellungsdialog des Abschnitts im Seiteneditor: Name, Sprungmarke und Sichtbarkeit stehen nicht mehr als
|
||||
* Eingabeblock in jedem Abschnitt, sondern im Dialog. „Übernehmen“ ändert nur den Seitenentwurf.
|
||||
*/
|
||||
class CmsSectionSettingsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private function editor(): User
|
||||
{
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
|
||||
return $editor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $extra
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function section(string $heading, array $extra = []): array
|
||||
{
|
||||
return $extra + ['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'heading', 'v' => 1, 'data' => ['heading' => $heading]]]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $sections
|
||||
*/
|
||||
private function page(string $path, array $sections): Page
|
||||
{
|
||||
$page = Page::query()->create(['path' => $path]);
|
||||
app(PageService::class)->saveRevision($page, $sections, null, null, null);
|
||||
|
||||
return $page->fresh();
|
||||
}
|
||||
|
||||
private function editorFor(Page $page): Testable
|
||||
{
|
||||
return Livewire::actingAs($this->editor(), 'staff')->test(EditPage::class, ['record' => $page->id]);
|
||||
}
|
||||
|
||||
private function settings(string $key): TestAction
|
||||
{
|
||||
return TestAction::make('einstellungen')->schemaComponent('sections')->arguments(['item' => $key]);
|
||||
}
|
||||
|
||||
public function test_the_dialog_shows_the_values_of_the_section_and_applies_them_to_the_draft_only(): void
|
||||
{
|
||||
$page = $this->page('/einstellungen', [$this->section('A', ['name' => 'Alt', 'anchor' => 'alt']), $this->section('B')]);
|
||||
$revisions = $page->revisions()->count();
|
||||
$component = $this->editorFor($page);
|
||||
$keys = array_keys($component->get('data.sections'));
|
||||
$slotsBefore = $component->get("data.sections.{$keys[0]}.slots");
|
||||
$styleBefore = $component->get("data.sections.{$keys[0]}.style");
|
||||
$otherBefore = $component->get("data.sections.{$keys[1]}");
|
||||
|
||||
$component->mountAction($this->settings($keys[0]))
|
||||
->assertActionDataSet(['name' => 'Alt', 'anchor' => 'alt', 'hidden' => false])
|
||||
->callMountedAction()
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
$this->assertSame('Alt', $component->get("data.sections.{$keys[0]}.name"), 'Ohne Änderung bleibt alles wie es war.');
|
||||
|
||||
$component->callAction($this->settings($keys[0]), ['name' => ' Kurse 2026 ', 'anchor' => 'Kurse 2026', 'hidden' => true])->assertHasNoActionErrors();
|
||||
|
||||
$this->assertSame('Kurse 2026', $component->get("data.sections.{$keys[0]}.name"));
|
||||
$this->assertSame('kurse-2026', $component->get("data.sections.{$keys[0]}.anchor"), 'Die Sprungmarke wird in die zulässige Form gebracht.');
|
||||
$this->assertTrue($component->get("data.sections.{$keys[0]}.hidden"));
|
||||
$this->assertSame($slotsBefore, $component->get("data.sections.{$keys[0]}.slots"), 'Plätze und Bausteine bleiben unberührt.');
|
||||
$this->assertSame($styleBefore, $component->get("data.sections.{$keys[0]}.style"));
|
||||
$this->assertSame($otherBefore, $component->get("data.sections.{$keys[1]}"), 'Ein anderer Abschnitt bleibt unberührt.');
|
||||
|
||||
$this->assertTrue($component->instance()->hasUnsavedEditorChanges());
|
||||
$this->assertSame($revisions, $page->revisions()->count(), 'Übernehmen speichert keine Revision.');
|
||||
$this->assertSame('Alt', $page->fresh()->latestRevision->sections()[0]['name']);
|
||||
|
||||
$component->call('save')->assertHasNoFormErrors();
|
||||
$stored = $page->fresh()->latestRevision->sections();
|
||||
$this->assertSame(['Kurse 2026', 'kurse-2026', true], [$stored[0]['name'], $stored[0]['anchor'], $stored[0]['hidden']]);
|
||||
}
|
||||
|
||||
public function test_closing_the_dialog_without_applying_changes_nothing(): void
|
||||
{
|
||||
$page = $this->page('/abbrechen', [$this->section('A', ['name' => 'Bleibt'])]);
|
||||
$component = $this->editorFor($page);
|
||||
$key = array_key_first($component->get('data.sections'));
|
||||
|
||||
$component->mountAction($this->settings($key))->unmountAction();
|
||||
|
||||
$this->assertSame('Bleibt', $component->get("data.sections.{$key}.name"));
|
||||
$this->assertFalse($component->instance()->hasUnsavedEditorChanges());
|
||||
}
|
||||
|
||||
public function test_the_dialog_rejects_invalid_reserved_and_duplicate_anchors_with_the_save_wording(): void
|
||||
{
|
||||
$page = $this->page('/pruefung', [$this->section('A', ['anchor' => 'kurse']), $this->section('B')]);
|
||||
$component = $this->editorFor($page);
|
||||
$keys = array_keys($component->get('data.sections'));
|
||||
|
||||
// Doppelte Sprungmarke (auch ungespeicherte Eingaben der anderen Abschnitte zählen).
|
||||
$component->callAction($this->settings($keys[1]), ['name' => null, 'anchor' => 'KURSE', 'hidden' => false])->assertHasActionErrors(['anchor'])->unmountAction();
|
||||
$this->assertNull($component->get("data.sections.{$keys[1]}.anchor"));
|
||||
|
||||
// Reserviert.
|
||||
$component->callAction($this->settings($keys[1]), ['name' => null, 'anchor' => 'inhalt', 'hidden' => false])->assertHasActionErrors(['anchor'])->unmountAction();
|
||||
|
||||
// Eine Eingabe, aus der nichts Zulässiges entsteht, wird wie beim Verlassen des Feldes zu „keine Sprungmarke“.
|
||||
$component->callAction($this->settings($keys[1]), ['name' => null, 'anchor' => '!!!', 'hidden' => false])->assertHasNoActionErrors();
|
||||
$this->assertNull($component->get("data.sections.{$keys[1]}.anchor"));
|
||||
|
||||
// Die eigene Marke des Abschnitts ist kein Duplikat; leer entfernt sie.
|
||||
$component->callAction($this->settings($keys[0]), ['name' => null, 'anchor' => 'kurse', 'hidden' => false])->assertHasNoActionErrors();
|
||||
$component->callAction($this->settings($keys[0]), ['name' => null, 'anchor' => '', 'hidden' => false])->assertHasNoActionErrors();
|
||||
$this->assertNull($component->get("data.sections.{$keys[0]}.anchor"));
|
||||
}
|
||||
|
||||
public function test_the_section_list_has_no_input_block_for_name_and_anchor_but_the_settings_button(): void
|
||||
{
|
||||
$page = $this->page('/ohne-block', [$this->section('A', ['name' => 'Kursübersicht', 'anchor' => 'kurse']), $this->section('B', ['hidden' => true])]);
|
||||
|
||||
$html = $this->editorFor($page)->html();
|
||||
|
||||
$this->assertStringNotContainsString('Name des Abschnitts', $html, 'Die Eingabefelder stehen nur im Dialog.');
|
||||
$this->assertStringNotContainsString('luf-abschnitt-bezeichnung', $html);
|
||||
$this->assertSame(2, substr_count($html, 'data-luf-einstellungen'), 'Jeder Abschnittskopf trägt den Einstellungsbutton.');
|
||||
$this->assertStringContainsString('Kursübersicht', $html);
|
||||
$this->assertStringContainsString('#kurse', $html);
|
||||
$this->assertStringContainsString('Ausgeblendet', $html);
|
||||
}
|
||||
|
||||
public function test_a_save_error_for_name_or_anchor_is_shown_at_the_section_with_a_way_to_the_dialog(): void
|
||||
{
|
||||
$page = $this->page('/fehler', [$this->section('A', ['anchor' => 'kurse']), $this->section('B')]);
|
||||
$component = $this->editorFor($page);
|
||||
$keys = array_keys($component->get('data.sections'));
|
||||
|
||||
$component->set("data.sections.{$keys[1]}.anchor", 'kurse')->call('save')->assertHasFormErrors(["sections.{$keys[1]}.anchor"]);
|
||||
|
||||
$html = $component->html();
|
||||
$this->assertSame(1, substr_count($html, 'data-abschnitt-fehler'), 'Die Meldung steht genau am betroffenen Abschnitt.');
|
||||
$this->assertStringContainsString('Diese Sprungmarke gibt es auf der Seite schon', $html);
|
||||
$this->assertStringContainsString('Einstellungen öffnen', $html);
|
||||
|
||||
// Nach der Korrektur im Dialog lässt sich speichern.
|
||||
$component->callAction($this->settings($keys[1]), ['name' => null, 'anchor' => 'anderes-ziel', 'hidden' => false])->assertHasNoActionErrors();
|
||||
$component->call('save')->assertHasNoFormErrors();
|
||||
$this->assertSame('anderes-ziel', $page->fresh()->latestRevision->sections()[1]['anchor']);
|
||||
}
|
||||
|
||||
public function test_other_open_inputs_of_the_page_survive_the_dialog(): void
|
||||
{
|
||||
$page = $this->page('/offen', [$this->section('A')]);
|
||||
$component = $this->editorFor($page);
|
||||
$key = array_key_first($component->get('data.sections'));
|
||||
|
||||
$component->set('data.seo_title', 'Offener Titel')
|
||||
->callAction($this->settings($key), ['name' => 'Neu', 'anchor' => null, 'hidden' => false])
|
||||
->assertSet('data.seo_title', 'Offener Titel')
|
||||
->assertSet("data.sections.{$key}.name", 'Neu');
|
||||
}
|
||||
|
||||
public function test_the_anchor_rules_have_one_wording_for_dialog_and_save(): void
|
||||
{
|
||||
$this->assertNull(PageSections::anchorProblem('kurse-2026', ['andere']));
|
||||
$this->assertStringContainsString('Kleinbuchstaben', (string) PageSections::anchorProblem('Kurse', []));
|
||||
$this->assertStringContainsString('Kleinbuchstaben', (string) PageSections::anchorProblem('a--b', []));
|
||||
$this->assertStringContainsString('Seitengerüst', (string) PageSections::anchorProblem('main', []));
|
||||
$this->assertStringContainsString('Seitengerüst', (string) PageSections::anchorProblem('bereich-abc', []));
|
||||
$this->assertStringContainsString('schon', (string) PageSections::anchorProblem('kurse', ['kurse']));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user