seed(\Database\Seeders\RolesAndPermissionsSeeder::class); $this->seed(\Database\Seeders\PermissionCatalogSeeder::class); $user = User::factory()->create(); $user->assignRole('Supervisor'); $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'], ], ]); // Attach template to project (pivot required for loadTemplates) $project->inspectionTemplates()->attach($template->id); 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); } }