diff --git a/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php b/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php index 3cf9d3d..282aaaf 100644 --- a/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php +++ b/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php @@ -128,6 +128,10 @@ public function mount(int|string $record): void $this->thumbnailAlt = (string) ($this->getRecord()->thumbnail_alt ?? ''); $this->bildQuelle = $this->getRecord()->output_class === 'film' ? 'film' : 'upload'; $this->fillEditorial(); + // Die gezeigte Fassung wird festgehalten. Sonst wechselte die Anzeige still auf eine andere Fassung, sobald + // eine Freigabe oder neue Fassung die Vorgabe „neueste freigegebene“ ändert, während das Textfeld noch den + // Wortlaut der bisherigen enthält. + $this->fassung ??= $this->shownVersion()?->id; $this->syncBodyDraft(); if (in_array($bereich, ['praesentation', 'redaktion'], true) && $this->canEditEditorial()) { @@ -441,6 +445,8 @@ public function reviseAction(): Action ->visible(fn (): bool => ContentElementResource::editor()) ->schema(fn (): array => ElementRevision::fields($this->getRecord())) ->action(function (array $data): void { + // Vor dem Anlegen prüfen: danach gäbe es eine andere neueste Fassung. + $textOffen = $this->textUnsaved(); $this->report(function () use ($data): string { /** @var ContentElement $element */ $element = $this->getRecord(); @@ -450,7 +456,7 @@ public function reviseAction(): Action $this->getRecord()->unsetRelation('versions'); // Die neue Fassung wird gezeigt, sofern dabei kein offener Text verloren geht. - if (! $this->textUnsaved()) { + if (! $textOffen) { $neueste = $this->getRecord()->versions()->orderByDesc('number')->value('id'); $this->fassung = $neueste !== null ? (int) $neueste : $this->fassung; $this->fassungFeedback = ''; diff --git a/tests/Feature/VerwaltungArbeitsplatzTest.php b/tests/Feature/VerwaltungArbeitsplatzTest.php index 98654b0..27754f0 100644 --- a/tests/Feature/VerwaltungArbeitsplatzTest.php +++ b/tests/Feature/VerwaltungArbeitsplatzTest.php @@ -683,6 +683,41 @@ public function test_media_versions_are_listed_left_and_the_chosen_one_is_shown_ ->assertDontSee('Diese Fassung freigeben'); } + public function test_releasing_another_version_does_not_move_the_shown_text_onto_it(): void + { + $content = app(ContentService::class); + $text = $content->createElement('text', 'text', 'Trainerunterlage'); + $first = $content->publishElementVersion($text, 'Erster Wortlaut'); + $draft = $content->draftElementVersion($text, 'Zweiter Wortlaut'); + + Livewire::actingAs($this->editor(), 'staff') + ->test(ViewContentElement::class, ['record' => $text->getKey()]) + ->assertSet('bodyDraft', 'Erster Wortlaut') + ->callAction('releaseVersion', [], ['version' => $draft->id]) + ->assertSet('fassung', $first->id) + ->assertSet('bodyDraft', 'Erster Wortlaut') + ->assertDontSee('Text der Fassung nicht gespeichert'); + + $this->assertSame('Zweiter Wortlaut', $draft->fresh()->body); + } + + public function test_a_new_version_from_the_dialog_is_shown_with_its_own_text(): void + { + $content = app(ContentService::class); + $text = $content->createElement('text', 'text', 'Trainerunterlage'); + $content->publishElementVersion($text, 'Erster Wortlaut'); + + $component = Livewire::actingAs($this->editor(), 'staff') + ->test(ViewContentElement::class, ['record' => $text->getKey()]) + ->callAction('revise', ['body' => 'Neuer Wortlaut', 'change_note' => 'Neu']) + ->assertHasNoFormErrors(); + + $second = $text->versions()->where('number', 2)->firstOrFail(); + $component->assertSet('fassung', $second->id) + ->assertSet('bodyDraft', 'Neuer Wortlaut') + ->assertDontSee('Text der Fassung nicht gespeichert'); + } + public function test_the_frame_slider_starts_at_the_current_preview_frame(): void { $content = app(ContentService::class);