presseportale/tests/Feature/PressReleaseValidationFeedbackTest.php
Kevin Adametz 31da9ea8b6
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (push) Waiting to run
livewire: Volt entfernt — Komponenten als Livewire-4-Single-File-Components, Route::livewire(), Livewire::test(); livewire/volt deinstalliert
- 83 Komponenten: Livewire\Volt\Component → Livewire\Component
- 73 Routen (admin, auth, customer): Volt::route() → Route::livewire()
- 88 Testdateien: Volt::test/actingAs → Livewire::test/actingAs
- VoltServiceProvider gelöscht; composer remove livewire/volt
- config/livewire.php auf v4-Schlüssel (component_layout, component_placeholder,
  component_locations, make_command: SFC ohne ⚡). Der alte Schlüssel layout war
  wirkungslos; alle gerouteten Komponenten setzen ihr Layout selbst.
- CLAUDE.md, AGENTS.md, boost.json, .cursorrules, Skill volt-development
- Roadmap: erledigt; Larastan erfasst SFCs weiterhin nicht (Blade-Dateien)

Suite 2.325 grün, einer übersprungen; Larastan und Pint ohne Meldung;
route:cache und view:cache laufen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 13:59:36 +00:00

103 lines
3.6 KiB
PHP

<?php
use App\Models\Category;
use App\Models\Company;
use App\Models\PressRelease;
use App\Models\User;
use Database\Seeders\RolesAndPermissionsSeeder;
use Livewire\Livewire;
use Tests\TestCase;
/**
* Sichtbares Validierungs-Feedback der PM-Editoren (Customer):
* persistente Fehler-Zusammenfassung bei den Speichern-Buttons statt nur
* flüchtigem Toast, deutsche Feldnamen statt "category id", rot markierte
* Panels für Fehlerfelder.
*/
beforeEach(function (): void {
/** @var TestCase $this */
$this->seed(RolesAndPermissionsSeeder::class);
});
function makeValidationFeedbackCustomer(): User
{
$customer = User::factory()->create(['is_active' => true]);
$customer->assignRole('customer');
$company = Company::factory()->presseecho()->create();
$customer->companies()->attach($company->id, ['role' => 'owner']);
return $customer;
}
test('create page shows a persistent error summary with German field names when saving without a category', function () {
/** @var TestCase $this */
$this->actingAs(makeValidationFeedbackCustomer());
Livewire::test('customer.press-releases.create')
->set('title', 'Ein gültiger Titel für die PM')
->set('text', str_repeat('Aussagekräftiger Fließtext. ', 5))
->set('categoryId', null)
->call('save', 'draft')
->assertHasErrors(['categoryId'])
->assertSee('Speichern nicht möglich')
->assertSee('Kategorie muss ausgefüllt werden.')
->assertDontSee('category id');
});
test('create page error summary lists every failing field and disappears once resolved', function () {
/** @var TestCase $this */
$this->actingAs(makeValidationFeedbackCustomer());
$category = Category::factory()->create();
$component = Livewire::test('customer.press-releases.create')
->call('save', 'draft')
->assertHasErrors(['categoryId', 'title', 'text'])
->assertSee('Speichern nicht möglich')
->assertSee('Kategorie muss ausgefüllt werden.')
->assertSee('Titel muss ausgefüllt werden.')
->assertSee('Text muss ausgefüllt werden.');
$component
->set('categoryId', $category->id)
->set('title', 'Ein gültiger Titel für die PM')
->set('text', str_repeat('Aussagekräftiger Fließtext. ', 5))
->call('save', 'draft')
->assertHasNoErrors()
->assertRedirect();
});
test('create page marks the category panel as invalid and keeps the jump anchor', function () {
/** @var TestCase $this */
$this->actingAs(makeValidationFeedbackCustomer());
Livewire::test('customer.press-releases.create')
->assertSeeHtml('data-error-anchor="categoryId"')
->assertDontSeeHtml('is-invalid')
->call('save', 'draft')
->assertSeeHtml('is-invalid');
});
test('edit page shows the error summary when saving without a category', function () {
/** @var TestCase $this */
$customer = makeValidationFeedbackCustomer();
$company = $customer->companies()->first();
$category = Category::factory()->create();
$pr = PressRelease::factory()->create([
'user_id' => $customer->id,
'company_id' => $company->id,
'category_id' => $category->id,
'portal' => $company->portal->value,
'status' => 'draft',
]);
$this->actingAs($customer);
Livewire::test('customer.press-releases.edit', ['id' => $pr->id])
->set('categoryId', null)
->call('save')
->assertHasErrors(['categoryId'])
->assertSee('Speichern nicht möglich')
->assertSee('Kategorie muss ausgefüllt werden.');
});