Files
construprogress/tests/Feature/TemplateCreationTest.php
T
javierandClaude Opus 4.8 9fc5854bbb 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>
2026-06-25 11:53:51 +02:00

60 lines
1.8 KiB
PHP

<?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',
]);
}
}