api/tests/Feature/Filament/HuntStepsRelationManagerTes...

59 lines
1.7 KiB
PHP

<?php
use App\Enums\UserRole;
use App\Filament\Resources\Hunts\Pages\EditHunts;
use App\Filament\Resources\Hunts\RelationManagers\StepsRelationManager;
use App\Models\Hunts;
use App\Models\User;
use Dotswan\MapPicker\Fields\Map;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Hidden;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
uses(RefreshDatabase::class);
it('uses an image upload and map picker when creating hunt steps', function () {
$admin = User::factory()->create([
'role' => UserRole::ADMIN,
]);
$hunt = Hunts::withoutSyncingToSearch(fn () => Hunts::factory()->create([
'creator_id' => $admin->id,
'latitude' => 44.837789,
'longitude' => -0.57918,
]));
$this->actingAs($admin);
Livewire::test(StepsRelationManager::class, [
'ownerRecord' => $hunt,
'pageClass' => EditHunts::class,
])
->mountTableAction('create')
->assertTableActionDataSet([
'latitude' => 44.837789,
'longitude' => -0.57918,
'location' => [
'lat' => 44.837789,
'lng' => -0.57918,
],
])
->assertFormFieldExists(
'hint_media_url',
fn ($field): bool => $field instanceof FileUpload,
)
->assertFormFieldExists(
'latitude',
fn ($field): bool => $field instanceof Hidden,
)
->assertFormFieldExists(
'longitude',
fn ($field): bool => $field instanceof Hidden,
)
->assertFormFieldExists(
'location',
fn ($field): bool => $field instanceof Map,
);
});