seed(RolesAndPermissionsSeeder::class); }); /** * @return array{customer: User, company: Company, contact: Contact, category: Category} */ function makeCustomerForContactWarning(): array { $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, 'phone' => '+49 30 1234567', ]); $category = Category::factory()->create(); return compact('customer', 'company', 'contact', 'category'); } function makeAdminForContactWarning(): User { $admin = User::factory()->create(['is_active' => true]); $admin->assignRole('admin'); return $admin; } test('customer create zeigt Warn-Box, wenn kein Pressekontakt gewählt ist', function () { /** @var TestCase $this */ ['customer' => $customer, 'company' => $company] = makeCustomerForContactWarning(); $this->actingAs($customer); LivewireVolt::test('customer.press-releases.create') ->set('companyId', $company->id) ->set('contactId', null) ->assertSee('Noch kein Pressekontakt ausgewählt'); }); test('customer create zeigt Warn-Box NICHT, wenn ein Kontakt gewählt ist', function () { /** @var TestCase $this */ ['customer' => $customer, 'company' => $company, 'contact' => $contact] = makeCustomerForContactWarning(); $this->actingAs($customer); LivewireVolt::test('customer.press-releases.create') ->set('companyId', $company->id) ->set('contactId', $contact->id) ->assertDontSee('Noch kein Pressekontakt ausgewählt'); }); test('customer edit zeigt Warn-Box, wenn kein Pressekontakt gewählt ist', function () { /** @var TestCase $this */ ['customer' => $customer, 'company' => $company, 'category' => $category] = makeCustomerForContactWarning(); $this->actingAs($customer); $pr = PressRelease::factory()->create([ 'user_id' => $customer->id, 'company_id' => $company->id, 'category_id' => $category->id, 'portal' => $company->portal->value, 'status' => PressReleaseStatus::Draft->value, ]); LivewireVolt::test('customer.press-releases.edit', ['id' => $pr->id]) ->set('contactId', null) ->assertSee('Noch kein Pressekontakt ausgewählt'); }); test('customer edit zeigt Warn-Box NICHT, wenn ein Kontakt gewählt ist', function () { /** @var TestCase $this */ ['customer' => $customer, 'company' => $company, 'contact' => $contact, 'category' => $category] = makeCustomerForContactWarning(); $this->actingAs($customer); $pr = PressRelease::factory()->create([ 'user_id' => $customer->id, 'company_id' => $company->id, 'category_id' => $category->id, 'portal' => $company->portal->value, 'status' => PressReleaseStatus::Draft->value, ]); $pr->contacts()->sync([$contact->id]); LivewireVolt::test('customer.press-releases.edit', ['id' => $pr->id]) ->assertDontSee('Noch kein Pressekontakt ausgewählt'); }); test('admin create zeigt Warn-Box, wenn kein Pressekontakt gewählt ist', function () { /** @var TestCase $this */ $admin = makeAdminForContactWarning(); $this->actingAs($admin); $company = Company::factory()->presseecho()->create(); Contact::factory()->for($company)->create([ 'portal' => $company->portal->value, 'phone' => '+49 30 7654321', ]); LivewireVolt::test('admin.press-releases.create') ->set('companyId', $company->id) ->set('contactId', null) ->assertSee('Noch kein Pressekontakt ausgewählt'); }); test('admin edit zeigt Warn-Box, wenn kein Pressekontakt gewählt ist', function () { /** @var TestCase $this */ $admin = makeAdminForContactWarning(); $this->actingAs($admin); $company = Company::factory()->presseecho()->create(); Contact::factory()->for($company)->create([ 'portal' => $company->portal->value, 'phone' => '+49 30 7654321', ]); $category = Category::factory()->create(); $pr = PressRelease::factory()->create([ 'company_id' => $company->id, 'category_id' => $category->id, 'portal' => $company->portal->value, 'status' => PressReleaseStatus::Draft->value, ]); LivewireVolt::test('admin.press-releases.edit', ['id' => $pr->id]) ->set('contactId', null) ->assertSee('Noch kein Pressekontakt ausgewählt'); }); test('admin edit zeigt Warn-Box NICHT, wenn ein Kontakt gewählt ist', function () { /** @var TestCase $this */ $admin = makeAdminForContactWarning(); $this->actingAs($admin); $company = Company::factory()->presseecho()->create(); $contact = Contact::factory()->for($company)->create([ 'portal' => $company->portal->value, 'phone' => '+49 30 7654321', ]); $category = Category::factory()->create(); $pr = PressRelease::factory()->create([ 'company_id' => $company->id, 'category_id' => $category->id, 'portal' => $company->portal->value, 'status' => PressReleaseStatus::Draft->value, ]); $pr->contacts()->sync([$contact->id]); LivewireVolt::test('admin.press-releases.edit', ['id' => $pr->id]) ->assertDontSee('Noch kein Pressekontakt ausgewählt'); });