64 lines
2.6 KiB
PHP
64 lines
2.6 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace Tests\Feature;
|
||
|
|
|
||
|
|
use App\Livewire\Projects\ProjectMap;
|
||
|
|
use App\Models\Feature;
|
||
|
|
use App\Models\Inspection;
|
||
|
|
use App\Models\InspectionTemplate;
|
||
|
|
use App\Models\Layer;
|
||
|
|
use App\Models\Phase;
|
||
|
|
use App\Models\Project;
|
||
|
|
use App\Models\User;
|
||
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
|
|
use Illuminate\Http\UploadedFile;
|
||
|
|
use Illuminate\Support\Facades\Storage;
|
||
|
|
use Livewire\Livewire;
|
||
|
|
use Tests\TestCase;
|
||
|
|
|
||
|
|
class InspectionFormTest extends TestCase
|
||
|
|
{
|
||
|
|
use RefreshDatabase;
|
||
|
|
|
||
|
|
public function test_register_inspection_with_comments_and_photo(): void
|
||
|
|
{
|
||
|
|
Storage::fake('public');
|
||
|
|
|
||
|
|
$user = User::factory()->create();
|
||
|
|
$project = Project::create([
|
||
|
|
'reference' => 'INS', 'name' => 'Proyecto Insp', 'address' => 'x', 'lat' => 40, 'lng' => -3,
|
||
|
|
'start_date' => now()->toDateString(), 'end_date_estimated' => now()->addMonth()->toDateString(),
|
||
|
|
'status' => 'in_progress', 'created_by' => $user->id,
|
||
|
|
]);
|
||
|
|
$project->users()->attach($user->id, ['role_in_project' => 'supervisor']);
|
||
|
|
|
||
|
|
$phase = Phase::create(['project_id' => $project->id, 'name' => 'F1', 'order' => 1, 'color' => '#000', 'progress_percent' => 0]);
|
||
|
|
$layer = Layer::create(['project_id' => $project->id, 'phase_id' => $phase->id, 'name' => 'L', 'color' => '#111', 'uploaded_by' => $user->id]);
|
||
|
|
$feature = Feature::create([
|
||
|
|
'layer_id' => $layer->id, 'name' => 'Pilar', 'geometry' => ['type' => 'Point', 'coordinates' => [-3, 40]],
|
||
|
|
'progress' => 0, 'status' => 'planned',
|
||
|
|
]);
|
||
|
|
$template = InspectionTemplate::create([
|
||
|
|
'project_id' => $project->id, 'name' => 'Recepción',
|
||
|
|
'fields' => [
|
||
|
|
['group' => 'Geometría', 'name' => 'altura', 'label' => 'Altura', 'question' => '¿Cota OK?', 'type' => 'text', 'required' => false, 'help' => 'Medir'],
|
||
|
|
],
|
||
|
|
]);
|
||
|
|
|
||
|
|
Livewire::actingAs($user)
|
||
|
|
->test(ProjectMap::class, ['project' => $project])
|
||
|
|
->call('selectFeature', $feature->id)
|
||
|
|
->set('selectedTemplateId', $template->id)
|
||
|
|
->set('inspectionFormData.altura', '5.2')
|
||
|
|
->set('inspectionNotes', 'Todo conforme')
|
||
|
|
->set('inspectionPhotos', [UploadedFile::fake()->image('foto.jpg')])
|
||
|
|
->call('saveInspection');
|
||
|
|
|
||
|
|
$ins = Inspection::where('feature_id', $feature->id)->first();
|
||
|
|
$this->assertNotNull($ins);
|
||
|
|
$this->assertEquals('Todo conforme', $ins->notes);
|
||
|
|
$this->assertEquals('5.2', $ins->data['altura']);
|
||
|
|
$this->assertCount(1, $ins->media);
|
||
|
|
}
|
||
|
|
}
|