create();
$org = Organization::create(['name' => 'Test Commune', 'slug' => 'test-commune', 'org_type' => 'client']);
$response = $this->actingAs($user)->get(route('organizations.infrastructure.index', $org));
$response->assertOk();
$response->assertSee('Infrastructure');
}
public function test_can_create_a_diagram_and_it_opens_in_the_editor(): void
{
$user = User::factory()->create();
$org = Organization::create(['name' => 'Test Commune', 'slug' => 'test-commune', 'org_type' => 'client']);
$this->actingAs($user);
Livewire::test('infrastructure.index', ['organization' => $org])
->set('newDiagramName', 'Schéma réseau - Mairie')
->call('createDiagram')
->assertHasNoErrors();
$this->assertDatabaseHas('documents', [
'organization_id' => $org->id,
'name' => 'Schéma réseau - Mairie',
'type' => 'diagram',
]);
$document = $org->documents()->where('type', 'diagram')->firstOrFail();
$response = $this->get(route('organizations.infrastructure.edit', [$org, $document]));
$response->assertOk();
$response->assertSee('Schéma réseau - Mairie');
}
public function test_saving_a_diagram_creates_a_new_version_only_when_content_changed(): void
{
$user = User::factory()->create();
$org = Organization::create(['name' => 'Test Commune', 'slug' => 'test-commune', 'org_type' => 'client']);
$document = $org->documents()->create([
'name' => 'Schéma test',
'type' => 'diagram',
'content' => 'old',
'current_version' => 1,
'created_by' => $user->id,
]);
$document->versions()->create(['version' => 1, 'content' => 'old', 'created_by' => $user->id]);
$this->actingAs($user);
Livewire::test('documents.diagram-editor', ['organization' => $org, 'document' => $document])
->call('saveDiagram', 'new');
$document->refresh();
$this->assertSame('new', $document->content);
$this->assertSame(2, $document->current_version);
$this->assertCount(2, $document->versions);
}
}