fix(templates): la página de plantillas no embebía el componente
resources/views/projects/templates.blade.php usaba `<livewire/template-manager>` (sintaxis inválida; tras la reorganización el alias es `inspections.template-manager`) y un botón suelto con `$emit` (Livewire 2, fuera de componente) que no hacía nada. Ahora embebe correctamente <livewire:inspections.template-manager> (que ya trae su botón "Nuevo" + formulario funcional) y se elimina el botón roto. Tests: TemplateCreationTest (la página embebe el componente; crear plantilla funciona). Suite 79 passing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,23 @@
|
||||
<x-app-layout>
|
||||
<div class="mb-6">
|
||||
<button wire:click="$emit('showTemplateForm')"
|
||||
class="btn btn-primary btn-lg">
|
||||
+ {{ __('New template') }}
|
||||
</button>
|
||||
<p class="text-sm text-muted mb-4">
|
||||
{{ __('Create generic templates that can be used in any phase of the project') }}
|
||||
</p>
|
||||
<x-slot name="header">
|
||||
<div class="flex items-center gap-3">
|
||||
<a href="{{ route('projects.dashboard', $project) }}" wire:navigate class="btn btn-ghost btn-sm px-2">
|
||||
<x-heroicon-o-arrow-left class="w-4 h-4" />
|
||||
</a>
|
||||
<div>
|
||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">{{ __('Inspection templates') }}</h2>
|
||||
<p class="text-sm text-gray-500 leading-tight">{{ $project->name }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</x-slot>
|
||||
|
||||
<div class="py-8">
|
||||
<div class="max-w-5xl mx-auto sm:px-6 lg:px-8">
|
||||
<p class="text-sm text-base-content/60 mb-4">
|
||||
{{ __('Create generic templates that can be used in any phase of the project') }}
|
||||
</p>
|
||||
|
||||
<livewire:inspections.template-manager :project="$project" />
|
||||
</div>
|
||||
</div>
|
||||
<livewire/template-manager :project="$project" />
|
||||
</x-app-layout>
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Livewire\Inspections\TemplateManager;
|
||||
use App\Models\Project;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TemplateCreationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private function setup_(): array
|
||||
{
|
||||
Permission::findOrCreate('edit projects');
|
||||
$user = User::factory()->create();
|
||||
$user->givePermissionTo('edit projects');
|
||||
$project = Project::create([
|
||||
'reference' => 'TPL-2', 'name' => 'Proyecto TPL', 'address' => 'x',
|
||||
'lat' => 40.0, 'lng' => -3.0, 'start_date' => now()->toDateString(),
|
||||
'end_date_estimated' => now()->addMonth()->toDateString(),
|
||||
'status' => 'in_progress', 'created_by' => $user->id,
|
||||
]);
|
||||
return [$user, $project];
|
||||
}
|
||||
|
||||
public function test_templates_page_embeds_the_manager_component(): void
|
||||
{
|
||||
[$user, $project] = $this->setup_();
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('projects.templates', $project))
|
||||
->assertOk()
|
||||
->assertSeeLivewire(TemplateManager::class);
|
||||
}
|
||||
|
||||
public function test_new_template_button_opens_form_and_saves(): void
|
||||
{
|
||||
[$user, $project] = $this->setup_();
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(TemplateManager::class, ['project' => $project])
|
||||
->assertSet('showForm', false)
|
||||
->call('newTemplate')
|
||||
->assertSet('showForm', true)
|
||||
->set('form.name', 'Recepción de hormigón')
|
||||
->call('saveTemplate')
|
||||
->assertHasNoErrors();
|
||||
|
||||
$this->assertDatabaseHas('inspection_templates', [
|
||||
'project_id' => $project->id,
|
||||
'name' => 'Recepción de hormigón',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user