presseportale/tests/Feature/Customer/DashboardTest.php
Kevin Adametz e8c47b7553
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
22-05-2026 Optimierung der User und Admin Panels
2026-05-22 11:18:59 +02:00

156 lines
4.9 KiB
PHP

<?php
use App\Enums\PressReleaseStatus;
use App\Models\BillingAddress;
use App\Models\Company;
use App\Models\PressRelease;
use App\Models\Profile;
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);
});
test('customer dashboard renders core sections without errors', function () {
/** @var TestCase $this */
$customer = User::factory()->create(['is_active' => true]);
$customer->assignRole('customer');
$this->actingAs($customer);
LivewireVolt::test('customer.dashboard')
->assertSee('Mein Dashboard')
->assertSee(__('Gesamt'))
->assertSee(__('Veröffentlicht'))
->assertSee(__('In Prüfung'))
->assertSee(__('Entwürfe'))
->assertSee(__('Meine letzten Pressemitteilungen'))
->assertSee(__('Datenqualität'))
->assertSee(__('Brand-Bridge'));
});
test('empty-state with three-step intro shows when no press releases exist', function () {
/** @var TestCase $this */
$customer = User::factory()->create(['is_active' => true]);
$customer->assignRole('customer');
$this->actingAs($customer);
LivewireVolt::test('customer.dashboard')
->assertSee(__('Noch keine Pressemitteilungen'))
->assertSee(__('Erste Pressemitteilung erstellen'))
->assertSee(__('Firma zuordnen'))
->assertSee(__('Mitteilung verfassen'))
->assertSee(__('Zur Prüfung senden'));
});
test('press release list and KPI counts render when data exists', function () {
/** @var TestCase $this */
$customer = User::factory()->create(['is_active' => true]);
$customer->assignRole('customer');
$company = Company::factory()->create(['owner_user_id' => $customer->id]);
PressRelease::factory()
->published()
->create([
'user_id' => $customer->id,
'company_id' => $company->id,
'title' => 'Phase 2 Demo Release',
]);
PressRelease::factory()->create([
'user_id' => $customer->id,
'company_id' => $company->id,
'status' => PressReleaseStatus::Draft->value,
]);
$this->actingAs($customer);
LivewireVolt::test('customer.dashboard')
->assertSee('Phase 2 Demo Release')
->assertDontSee(__('Noch keine Pressemitteilungen'))
->assertSee('Alle anzeigen');
});
test('company dashboard preview is limited to the ten newest companies', function () {
/** @var TestCase $this */
$customer = User::factory()->create(['is_active' => true]);
$customer->assignRole('customer');
for ($i = 1; $i <= 12; $i++) {
Company::factory()->create([
'owner_user_id' => $customer->id,
'name' => sprintf('Dashboard Firma %02d', $i),
'created_at' => now()->subDays(13 - $i),
]);
}
$this->actingAs($customer);
LivewireVolt::test('customer.dashboard')
->assertSee('12 zugeordnet')
->assertSee('Dashboard Firma 12')
->assertSee('Dashboard Firma 03')
->assertDontSee('Dashboard Firma 02')
->assertDontSee('Dashboard Firma 01')
->assertSee('Die zehn neuesten Firmen werden hier als Vorschau angezeigt.')
->assertSee(route('me.press-kits.index'), false);
});
test('profile completeness hint with percentage appears for partial profiles', function () {
/** @var TestCase $this */
$customer = User::factory()->create(['is_active' => true]);
$customer->assignRole('customer');
Profile::factory()->create([
'user_id' => $customer->id,
'first_name' => 'Test',
'last_name' => 'Customer',
'phone' => null,
'address' => null,
'country_code' => null,
'salutation_key' => null,
]);
$this->actingAs($customer);
LivewireVolt::test('customer.dashboard')
->assertSee(__('Profil unvollständig'))
->assertSee('33');
});
test('billing address hint disappears once address is complete', function () {
/** @var TestCase $this */
$customer = User::factory()->create(['is_active' => true]);
$customer->assignRole('customer');
Profile::factory()->create([
'user_id' => $customer->id,
'salutation_key' => 'mr',
'first_name' => 'Test',
'last_name' => 'Customer',
'phone' => '+49 30 1234567',
'address' => 'Teststr. 1',
'country_code' => 'DE',
]);
BillingAddress::query()->create([
'user_id' => $customer->id,
'name' => 'Test Customer GmbH',
'address1' => 'Teststr. 1',
'postal_code' => '10115',
'city' => 'Berlin',
'country_code' => 'DE',
]);
$this->actingAs($customer);
LivewireVolt::test('customer.dashboard')
->assertDontSee(__('Profil unvollständig'))
->assertDontSee(__('Rechnungsadresse fehlt'))
->assertSee(__('Alles im grünen Bereich'));
});