presseportale/tests/Feature/Admin/AdminImagesIndexTest.php

69 lines
2.6 KiB
PHP

<?php
use App\Enums\ImagePrecheckOutcome;
use App\Models\PressRelease;
use App\Models\PressReleaseImage;
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);
});
function imagesIndexAdmin(): User
{
$admin = User::factory()->create(['is_active' => true]);
$admin->assignRole('admin');
return $admin;
}
test('the images list shows every title image with press release link, confirmation state and precheck result', function () {
/** @var TestCase $this */
$this->actingAs(imagesIndexAdmin());
$pr = PressRelease::factory()->create(['title' => 'Bildliste Testmeldung']);
$queued = PressReleaseImage::factory()->rulesV2()->create([
'press_release_id' => $pr->id,
'copyright' => 'Foto: Beispiel AG',
'precheck_outcome' => ImagePrecheckOutcome::Queue,
'precheck_review_required_at' => now(),
'withheld_at' => now(),
'precheck' => ['model' => 'test-model', 'evaluation' => ['triggers' => [['category' => 'screenshot_or_collage', 'confidence' => 0.7, 'outcome' => 'queue', 'note' => null]]]],
]);
$legacy = PressReleaseImage::factory()->legacy()->create(['press_release_id' => PressRelease::factory()->create()->id]);
$this->get(route('admin.images.index'))->assertSuccessful();
LivewireVolt::test('admin.images.index')
->assertSee('Bildliste Testmeldung')
->assertSee(route('admin.press-releases.show', ['id' => $pr->id]))
->assertSee('Foto: Beispiel AG')
->assertSee('Screenshot oder Collage')
->assertSee('Sichtung offen')
->assertSee('Bestand')
->assertSeeHtml('data-image-row="'.$queued->id.'"')
->assertSeeHtml('data-image-row="'.$legacy->id.'"')
->set('state', 'review')
->assertSeeHtml('data-image-row="'.$queued->id.'"')
->assertDontSeeHtml('data-image-row="'.$legacy->id.'"')
->set('state', '')
->set('precheck', 'none')
->assertDontSeeHtml('data-image-row="'.$queued->id.'"')
->assertSeeHtml('data-image-row="'.$legacy->id.'"')
->set('precheck', '')
->set('search', 'Bildliste')
->assertSeeHtml('data-image-row="'.$queued->id.'"')
->assertDontSeeHtml('data-image-row="'.$legacy->id.'"');
});
test('customers cannot open the images list', function () {
/** @var TestCase $this */
$user = User::factory()->create(['is_active' => true]);
$user->assignRole('customer');
$this->actingAs($user)->get(route('admin.images.index'))->assertForbidden();
});