create PM v0.5
This commit is contained in:
parent
9b47296cea
commit
d2ba22c0cf
25 changed files with 2155 additions and 72 deletions
179
tests/Feature/CustomerPressReleaseCreatePhase7Test.php
Normal file
179
tests/Feature/CustomerPressReleaseCreatePhase7Test.php
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
<?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);
|
||||
});
|
||||
|
||||
test('mount picks the alphabetically first contact of the default company', function () {
|
||||
/** @var TestCase $this */
|
||||
$customer = User::factory()->create(['is_active' => true]);
|
||||
$customer->assignRole('customer');
|
||||
$company = Company::factory()->presseecho()->create(['name' => 'Alpha GmbH']);
|
||||
$customer->companies()->attach($company->id, ['role' => 'owner']);
|
||||
|
||||
$contactZ = Contact::factory()->for($company)->create([
|
||||
'first_name' => 'Zacharias',
|
||||
'last_name' => 'Zimmer',
|
||||
'portal' => $company->portal->value,
|
||||
]);
|
||||
$contactA = Contact::factory()->for($company)->create([
|
||||
'first_name' => 'Alfred',
|
||||
'last_name' => 'Acker',
|
||||
'portal' => $company->portal->value,
|
||||
]);
|
||||
|
||||
$this->actingAs($customer);
|
||||
|
||||
LivewireVolt::test('customer.press-releases.create')
|
||||
->assertSet('companyId', $company->id)
|
||||
->assertSet('contactId', $contactA->id);
|
||||
});
|
||||
|
||||
test('changing the company resets the contactId to the new company default', function () {
|
||||
/** @var TestCase $this */
|
||||
$customer = User::factory()->create(['is_active' => true]);
|
||||
$customer->assignRole('customer');
|
||||
|
||||
$alphaCo = Company::factory()->presseecho()->create(['name' => 'Alpha']);
|
||||
$betaCo = Company::factory()->presseecho()->create(['name' => 'Beta']);
|
||||
$customer->companies()->attach($alphaCo->id, ['role' => 'owner']);
|
||||
$customer->companies()->attach($betaCo->id, ['role' => 'owner']);
|
||||
|
||||
$alphaContact = Contact::factory()->for($alphaCo)->create(['portal' => $alphaCo->portal->value]);
|
||||
$betaContact = Contact::factory()->for($betaCo)->create(['portal' => $betaCo->portal->value]);
|
||||
|
||||
$this->actingAs($customer);
|
||||
|
||||
LivewireVolt::test('customer.press-releases.create')
|
||||
->set('companyId', $betaCo->id)
|
||||
->assertSet('contactId', $betaContact->id)
|
||||
->set('companyId', $alphaCo->id)
|
||||
->assertSet('contactId', $alphaContact->id);
|
||||
});
|
||||
|
||||
test('save with all required fields persists the press release and syncs contact', function () {
|
||||
/** @var TestCase $this */
|
||||
$customer = User::factory()->create(['is_active' => true]);
|
||||
$customer->assignRole('customer');
|
||||
$company = Company::factory()->presseecho()->create(['boilerplate' => 'Über uns…']);
|
||||
$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', 'Eine neue Eröffnung der Brauerei')
|
||||
->set('subtitle', 'Subline mit ein wenig Kontext.')
|
||||
->set('text', str_repeat('Inhaltlich relevanter Fließtext. ', 5))
|
||||
->set('categoryId', $category->id)
|
||||
->set('contactId', $contact->id)
|
||||
->set('keywords', 'Brauerei, Eröffnung')
|
||||
->set('useBoilerplateOverride', true)
|
||||
->set('boilerplateOverride', 'Spezielle Boilerplate für diese PM.')
|
||||
->call('save', 'draft')
|
||||
->assertHasNoErrors();
|
||||
|
||||
$pr = PressRelease::query()->where('user_id', $customer->id)->latest('id')->firstOrFail();
|
||||
|
||||
expect($pr->title)->toBe('Eine neue Eröffnung der Brauerei');
|
||||
expect($pr->subtitle)->toBe('Subline mit ein wenig Kontext.');
|
||||
expect($pr->boilerplate_override)->toBe('Spezielle Boilerplate für diese PM.');
|
||||
expect($pr->company_id)->toBe($company->id);
|
||||
expect($pr->category_id)->toBe($category->id);
|
||||
expect($pr->status)->toBe(PressReleaseStatus::Draft);
|
||||
expect($pr->contacts)->toHaveCount(1);
|
||||
expect($pr->contacts->first()->id)->toBe($contact->id);
|
||||
});
|
||||
|
||||
test('save without a contact id fails validation', 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']);
|
||||
$category = Category::factory()->create();
|
||||
|
||||
$this->actingAs($customer);
|
||||
|
||||
LivewireVolt::test('customer.press-releases.create')
|
||||
->set('contactId', null)
|
||||
->set('title', 'Titel mit genug Zeichen')
|
||||
->set('text', str_repeat('x', 60))
|
||||
->set('categoryId', $category->id)
|
||||
->call('save', 'draft')
|
||||
->assertHasErrors(['contactId']);
|
||||
});
|
||||
|
||||
test('boilerplate override is null when toggle is off even if text is filled', 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', 'Genug Zeichen Titel')
|
||||
->set('text', str_repeat('x', 60))
|
||||
->set('categoryId', $category->id)
|
||||
->set('contactId', $contact->id)
|
||||
->set('useBoilerplateOverride', false)
|
||||
->set('boilerplateOverride', 'Wird nicht gespeichert.')
|
||||
->call('save', 'draft')
|
||||
->assertHasNoErrors();
|
||||
|
||||
$pr = PressRelease::query()->where('user_id', $customer->id)->latest('id')->firstOrFail();
|
||||
|
||||
expect($pr->boilerplate_override)->toBeNull();
|
||||
});
|
||||
|
||||
test('addTag appends to keywords and removeTag drops it', 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')
|
||||
->call('addTag', 'Brauerei')
|
||||
->call('addTag', 'Tegernsee')
|
||||
->call('addTag', 'Brauerei')
|
||||
->assertSet('keywords', 'Brauerei, Tegernsee')
|
||||
->call('removeTag', 'Brauerei')
|
||||
->assertSet('keywords', 'Tegernsee');
|
||||
});
|
||||
|
||||
test('addTag stops adding once the 5-tag limit is reached', 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);
|
||||
|
||||
$component = LivewireVolt::test('customer.press-releases.create');
|
||||
|
||||
foreach (['A', 'B', 'C', 'D', 'E'] as $tag) {
|
||||
$component->call('addTag', $tag);
|
||||
}
|
||||
$component->call('addTag', 'F'); // Soft-cap, kein Fehler
|
||||
$component->assertSet('keywords', 'A, B, C, D, E');
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue