10-04-2026
This commit is contained in:
parent
4d6b4930b2
commit
4bb89aad8c
836 changed files with 52961 additions and 5950 deletions
148
tests/Feature/DisplayListTest.php
Normal file
148
tests/Feature/DisplayListTest.php
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
|
||||
use App\Livewire\Admin\Cms\DisplayList;
|
||||
use App\Models\Display;
|
||||
use App\Models\DisplayVersion;
|
||||
use App\Models\User;
|
||||
use Livewire\Livewire;
|
||||
|
||||
beforeEach(function () {
|
||||
$portalDomain = config('domains.domain_portal');
|
||||
Livewire::withoutLazyLoading();
|
||||
url()->forceRootUrl('https://'.$portalDomain);
|
||||
});
|
||||
|
||||
test('display list requires authentication', function () {
|
||||
$response = $this->get(route('admin.cms.displays'));
|
||||
|
||||
$response->assertRedirect('/login');
|
||||
});
|
||||
|
||||
test('display list renders for authenticated users', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = $this->get(route('admin.cms.displays'));
|
||||
|
||||
$response->assertSuccessful();
|
||||
$response->assertSeeLivewire(DisplayList::class);
|
||||
});
|
||||
|
||||
test('can create a display', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(DisplayList::class)
|
||||
->call('openModal')
|
||||
->set('displayName', 'Display 1 - Eingang')
|
||||
->set('displayLocation', 'Schaufenster links')
|
||||
->call('save');
|
||||
|
||||
expect(Display::where('name', 'Display 1 - Eingang')->exists())->toBeTrue();
|
||||
});
|
||||
|
||||
test('can assign versions to a display', function () {
|
||||
$user = User::factory()->create();
|
||||
$version1 = DisplayVersion::factory()->create();
|
||||
$version2 = DisplayVersion::factory()->create();
|
||||
$display = Display::factory()->create();
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(DisplayList::class)
|
||||
->call('openModal', $display->id)
|
||||
->call('addVersion', $version1->id)
|
||||
->call('addVersion', $version2->id)
|
||||
->call('save');
|
||||
|
||||
$display->refresh();
|
||||
expect($display->versions)->toHaveCount(2);
|
||||
expect($display->versions->first()->id)->toBe($version1->id);
|
||||
expect($display->versions->last()->id)->toBe($version2->id);
|
||||
});
|
||||
|
||||
test('can reorder versions in playlist', function () {
|
||||
$user = User::factory()->create();
|
||||
$version1 = DisplayVersion::factory()->create();
|
||||
$version2 = DisplayVersion::factory()->create();
|
||||
$display = Display::factory()->create();
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(DisplayList::class)
|
||||
->call('openModal', $display->id)
|
||||
->call('addVersion', $version1->id)
|
||||
->call('addVersion', $version2->id)
|
||||
->call('moveVersion', 1, 'up')
|
||||
->call('save');
|
||||
|
||||
$display->refresh();
|
||||
expect($display->versions->first()->id)->toBe($version2->id);
|
||||
expect($display->versions->last()->id)->toBe($version1->id);
|
||||
});
|
||||
|
||||
test('can remove version from playlist', function () {
|
||||
$user = User::factory()->create();
|
||||
$version1 = DisplayVersion::factory()->create();
|
||||
$version2 = DisplayVersion::factory()->create();
|
||||
$display = Display::factory()->create();
|
||||
$display->versions()->attach([
|
||||
$version1->id => ['sort_order' => 0],
|
||||
$version2->id => ['sort_order' => 1],
|
||||
]);
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(DisplayList::class)
|
||||
->call('openModal', $display->id)
|
||||
->call('removeVersion', 0)
|
||||
->call('save');
|
||||
|
||||
$display->refresh();
|
||||
expect($display->versions)->toHaveCount(1);
|
||||
expect($display->versions->first()->id)->toBe($version2->id);
|
||||
});
|
||||
|
||||
test('can delete a display', function () {
|
||||
$user = User::factory()->create();
|
||||
$display = Display::factory()->create();
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(DisplayList::class)
|
||||
->call('deleteDisplay', $display->id);
|
||||
|
||||
expect(Display::find($display->id))->toBeNull();
|
||||
});
|
||||
|
||||
test('can toggle display active status', function () {
|
||||
$user = User::factory()->create();
|
||||
$display = Display::factory()->create(['is_active' => true]);
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(DisplayList::class)
|
||||
->call('toggleActive', $display->id);
|
||||
|
||||
expect($display->fresh()->is_active)->toBeFalse();
|
||||
});
|
||||
|
||||
test('validates required fields when creating display', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(DisplayList::class)
|
||||
->call('openModal')
|
||||
->set('displayName', '')
|
||||
->call('save')
|
||||
->assertHasErrors(['displayName']);
|
||||
});
|
||||
|
||||
test('does not add duplicate version to playlist', function () {
|
||||
$user = User::factory()->create();
|
||||
$version = DisplayVersion::factory()->create();
|
||||
|
||||
$component = Livewire::actingAs($user)
|
||||
->test(DisplayList::class)
|
||||
->call('openModal')
|
||||
->call('addVersion', $version->id)
|
||||
->call('addVersion', $version->id);
|
||||
|
||||
expect($component->get('selectedVersionIds'))->toHaveCount(1);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue