25a59e4413
- FeatureTable e InspectionTable (DataTableComponent) sustituyen las tablas HTML de las pestañas "Elementos" e "Inspecciones" del mapa: búsqueda, orden, filtro (progreso) y acciones. - Selección de elemento e "ver inspección" se comunican al ProjectMap por eventos (map-select-feature / map-view-inspection, vía #[On]); seleccionar abre el panel de edición y centra el mapa igual que antes. - Las relaciones requieren sus FKs en additionalSelects (layer_id / feature_id, template_id, user_id) porque Rappasoft no selecciona '*'. Tests: MapTablesTest (3). Suite 74 passing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
82 lines
2.8 KiB
PHP
82 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Livewire\Projects\FeatureTable;
|
|
use App\Livewire\Projects\InspectionTable;
|
|
use App\Models\Feature;
|
|
use App\Models\Inspection;
|
|
use App\Models\Layer;
|
|
use App\Models\Phase;
|
|
use App\Models\Project;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
|
|
class MapTablesTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private User $user;
|
|
private Project $project;
|
|
private Feature $feature;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->user = User::factory()->create();
|
|
$this->project = Project::create([
|
|
'reference' => 'MAP-1', 'name' => 'Proyecto Mapa', 'address' => 'x',
|
|
'lat' => 40.0, 'lng' => -3.0, 'start_date' => now()->toDateString(),
|
|
'end_date_estimated' => now()->addMonth()->toDateString(),
|
|
'status' => 'in_progress', 'created_by' => $this->user->id,
|
|
]);
|
|
$this->project->users()->attach($this->user->id, ['role_in_project' => 'supervisor']);
|
|
|
|
$phase = Phase::create(['project_id' => $this->project->id, 'name' => 'Fase 1', 'order' => 1, 'color' => '#3b82f6', 'progress_percent' => 0]);
|
|
$layer = Layer::create(['project_id' => $this->project->id, 'phase_id' => $phase->id, 'name' => 'Capa A', 'color' => '#10b981', 'uploaded_by' => $this->user->id]);
|
|
$this->feature = Feature::create([
|
|
'layer_id' => $layer->id, 'name' => 'Pilar 12',
|
|
'geometry' => ['type' => 'Point', 'coordinates' => [-3.0, 40.0]],
|
|
'progress' => 50, 'status' => 'in_progress',
|
|
]);
|
|
}
|
|
|
|
public function test_feature_table_lists_project_features(): void
|
|
{
|
|
Livewire::actingAs($this->user)
|
|
->test(FeatureTable::class, ['projectId' => $this->project->id])
|
|
->assertOk()
|
|
->assertSee('Pilar 12')
|
|
->assertSee('Capa A');
|
|
}
|
|
|
|
public function test_feature_table_forbidden_for_non_member(): void
|
|
{
|
|
$outsider = User::factory()->create();
|
|
Livewire::actingAs($outsider)
|
|
->test(FeatureTable::class, ['projectId' => $this->project->id])
|
|
->assertForbidden();
|
|
}
|
|
|
|
public function test_inspection_table_lists_project_inspections(): void
|
|
{
|
|
Inspection::create([
|
|
'project_id' => $this->project->id,
|
|
'layer_id' => $this->feature->layer_id,
|
|
'feature_id' => $this->feature->id,
|
|
'user_id' => $this->user->id,
|
|
'data' => ['ok' => true],
|
|
'status' => 'completed',
|
|
'result' => 'pass',
|
|
]);
|
|
|
|
Livewire::actingAs($this->user)
|
|
->test(InspectionTable::class, ['projectId' => $this->project->id])
|
|
->assertOk()
|
|
->assertSee('Pilar 12')
|
|
->assertSee('pass');
|
|
}
|
|
}
|