feat(templates): tabla Rappasoft con filtros para el catálogo global

- Nueva InspectionTemplatesTable (DataTableComponent): columnas Plantilla,
  Descripción, Campos, Proyectos (uso) y Acciones; filtros en cabecera por nombre,
  descripción y uso (en uso / sin uso). Gateada por manage templates.
- GlobalTemplateManager: el listado HTML se sustituye por la tabla embebida.
  Acciones Editar/Borrar viajan por eventos (template-edit/template-delete);
  el manager emite templates-changed al guardar/borrar/importar para que la tabla
  se refresque (#[On('templates-changed')]).

Tests: GlobalTemplatesTest amplía con tabla (render + permiso, evento edit). Suite 91 passing.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-25 18:24:59 +02:00
co-authored by Claude Opus 4.7
parent f8a68312a3
commit 51c07ede38
5 changed files with 297 additions and 164 deletions
+37
View File
@@ -3,6 +3,7 @@
namespace Tests\Feature;
use App\Livewire\Inspections\GlobalTemplateManager;
use App\Livewire\Inspections\InspectionTemplatesTable;
use App\Livewire\Projects\ProjectMap;
use App\Livewire\Projects\ProjectTemplatesPicker;
use App\Models\InspectionTemplate;
@@ -79,6 +80,42 @@ class GlobalTemplatesTest extends TestCase
$this->assertFalse($project->fresh()->inspectionTemplates()->where('inspection_templates.id', $tpl->id)->exists());
}
public function test_templates_table_lists_and_requires_permission(): void
{
Permission::findOrCreate('manage templates');
InspectionTemplate::create(['name' => 'Recepción acero', 'fields' => []]);
// Sin permiso → 403
$weak = User::factory()->create();
Livewire::actingAs($weak)
->test(InspectionTemplatesTable::class)
->assertForbidden();
// Con permiso → lista
$admin = User::factory()->create();
$admin->givePermissionTo('manage templates');
Livewire::actingAs($admin)
->test(InspectionTemplatesTable::class)
->assertOk()
->assertSee('Recepción acero');
}
public function test_table_emits_edit_event_handled_by_manager(): void
{
Permission::findOrCreate('manage templates');
$admin = User::factory()->create();
$admin->givePermissionTo('manage templates');
$tpl = InspectionTemplate::create(['name' => 'Editame', 'fields' => []]);
// El manager escucha #[On('template-edit')] y abre el form
Livewire::actingAs($admin)
->test(GlobalTemplateManager::class)
->assertSet('showForm', false)
->call('editTemplate', $tpl->id) // simula el dispatch
->assertSet('showForm', true)
->assertSet('editingTemplate', $tpl->id);
}
public function test_map_template_selector_only_shows_assigned_templates(): void
{
$user = User::factory()->create();