Bug: Im Submit-Modal navigierte 'Buchung auswaehlen' per wire:navigate direkt
zur Buchungsseite, OHNE vorher zu speichern -> im Erstellen ging die ganze PM
verloren, im Bearbeiten die ungespeicherten Aenderungen.
- Submit-Modal: neuer Prop booking-action; ist er gesetzt, speichert der Button
ueber eine Livewire-Aktion zuerst und navigiert erst danach
('Speichern & Buchung auswaehlen'). Fallback-href nur dort, wo bereits
gespeichert ist (Detailansicht).
- create/edit: Persistenz in persistDraft()/persistEdit() extrahiert;
saveDraftAndChooseBooking() speichert den Entwurf bzw. die Aenderungen und
leitet erst dann zur Buchung (Edit reklassifiziert bei Inhaltsaenderung).
- Beide Submit-Modals mit booking-action verdrahtet.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
87 lines
3.4 KiB
PHP
87 lines
3.4 KiB
PHP
<?php
|
|
|
|
use App\Enums\PressReleaseStatus;
|
|
use App\Models\Category;
|
|
use App\Models\Company;
|
|
use App\Models\Contact;
|
|
use App\Models\PressRelease;
|
|
use App\Models\User;
|
|
use Database\Seeders\RolesAndPermissionsSeeder;
|
|
use Livewire\Volt\Volt as LivewireVolt;
|
|
use Tests\TestCase;
|
|
|
|
beforeEach(function (): void {
|
|
/** @var TestCase $this */
|
|
$this->seed(RolesAndPermissionsSeeder::class);
|
|
// Gate aktiv, damit der „Buchung auswählen"-Pfad im Submit-Modal greift.
|
|
config()->set('billing.enforce_booking', true);
|
|
});
|
|
|
|
test('create: choosing a booking from the submit modal saves the draft first', function () {
|
|
/** @var TestCase $this */
|
|
$customer = User::factory()->create(['is_active' => true]);
|
|
$customer->assignRole('customer');
|
|
$company = Company::factory()->presseecho()->create();
|
|
$customer->companies()->attach($company->id, ['role' => 'owner']);
|
|
$contact = Contact::factory()->for($company)->create(['portal' => $company->portal->value]);
|
|
$category = Category::factory()->create();
|
|
|
|
$this->actingAs($customer);
|
|
|
|
LivewireVolt::test('customer.press-releases.create')
|
|
->set('title', 'Entwurf der auf keinen Fall verloren gehen darf')
|
|
->set('text', str_repeat('Inhaltlich relevanter Fließtext. ', 5))
|
|
->set('categoryId', $category->id)
|
|
->set('contactId', $contact->id)
|
|
->call('saveDraftAndChooseBooking')
|
|
->assertHasNoErrors()
|
|
->assertRedirect(route('me.bookings.index'));
|
|
|
|
$pr = PressRelease::query()->where('user_id', $customer->id)->latest('id')->first();
|
|
|
|
expect($pr)->not->toBeNull();
|
|
expect($pr->title)->toBe('Entwurf der auf keinen Fall verloren gehen darf');
|
|
expect($pr->status)->toBe(PressReleaseStatus::Draft);
|
|
});
|
|
|
|
test('create: the submit modal offers the saving booking button when no booking exists', function () {
|
|
/** @var TestCase $this */
|
|
$customer = User::factory()->create(['is_active' => true]);
|
|
$customer->assignRole('customer');
|
|
$company = Company::factory()->presseecho()->create();
|
|
$customer->companies()->attach($company->id, ['role' => 'owner']);
|
|
|
|
$this->actingAs($customer);
|
|
|
|
LivewireVolt::test('customer.press-releases.create')
|
|
->assertSee('Buchung erforderlich')
|
|
->assertSee('Speichern & Buchung auswählen');
|
|
});
|
|
|
|
test('edit: choosing a booking from the submit modal persists the edits first', function () {
|
|
/** @var TestCase $this */
|
|
$customer = User::factory()->create(['is_active' => true]);
|
|
$customer->assignRole('customer');
|
|
$company = Company::factory()->presseecho()->create();
|
|
$customer->companies()->attach($company->id, ['role' => 'owner']);
|
|
$pr = PressRelease::factory()->create([
|
|
'user_id' => $customer->id,
|
|
'company_id' => $company->id,
|
|
'category_id' => Category::factory()->create()->id,
|
|
'portal' => $company->portal->value,
|
|
'status' => 'draft',
|
|
'title' => 'Originaltitel',
|
|
]);
|
|
|
|
$this->actingAs($customer);
|
|
|
|
LivewireVolt::test('customer.press-releases.edit', ['id' => $pr->id])
|
|
->set('title', 'Bearbeiteter Titel der erhalten bleiben muss')
|
|
->set('text', str_repeat('Neuer Fließtext mit Inhalt. ', 5))
|
|
->call('saveDraftAndChooseBooking')
|
|
->assertHasNoErrors()
|
|
->assertRedirect(route('me.bookings.index'));
|
|
|
|
expect($pr->fresh()->title)->toBe('Bearbeiteter Titel der erhalten bleiben muss');
|
|
expect($pr->fresh()->status)->toBe(PressReleaseStatus::Draft);
|
|
});
|