feat(inspections): formulario y visor por grupos + comentarios + fotos
Parte 2 del bloque de plantillas/inspecciones: - Formulario de inspección (mapa): campos agrupados por sección, muestra la "pregunta" del campo (con la etiqueta como subtexto) y la ayuda; al final, apartado de Comentarios (notes) y subida de Fotos (media en la inspección). - ProjectMap: WithFileUploads + inspectionPhotos; saveInspection adjunta las fotos como media; Inspection gana relación media(). - Visor de inspección: datos agrupados por sección con pregunta/valor, comentarios y galería de fotos. Tests: InspectionFormTest (registra inspección con comentarios + foto). Suite 91 passing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user