feat(machine) : add custom field management on machine detail page
- Fix: return customFieldValues in structure endpoint (was hardcoded null) - Frontend: add editor to create/edit/delete custom field definitions - Tests: add integration tests for structure values + definition CRUD Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Api\Controller;
|
||||
|
||||
use App\Tests\AbstractApiTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class MachineStructureCustomFieldValuesTest extends AbstractApiTestCase
|
||||
{
|
||||
public function testStructureIncludesCustomFieldValues(): void
|
||||
{
|
||||
$machine = $this->createMachine('Machine CFV');
|
||||
$cf = $this->createCustomField('Tension', 'number', $machine);
|
||||
$this->createCustomFieldValue($cf, '220', $machine);
|
||||
|
||||
$client = $this->createViewerClient();
|
||||
$client->request('GET', sprintf('/api/machines/%s/structure', $machine->getId()));
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
$data = $client->getResponse()->toArray();
|
||||
|
||||
$this->assertArrayHasKey('machine', $data);
|
||||
$this->assertArrayHasKey('customFieldValues', $data['machine']);
|
||||
$this->assertIsArray($data['machine']['customFieldValues']);
|
||||
$this->assertNotEmpty($data['machine']['customFieldValues'], 'customFieldValues should not be empty');
|
||||
|
||||
$cfv = $data['machine']['customFieldValues'][0];
|
||||
$this->assertSame('220', $cfv['value']);
|
||||
$this->assertArrayHasKey('customField', $cfv);
|
||||
$this->assertSame('Tension', $cfv['customField']['name']);
|
||||
$this->assertSame('number', $cfv['customField']['type']);
|
||||
}
|
||||
|
||||
public function testStructureReturnsEmptyArrayWhenNoCustomFieldValues(): void
|
||||
{
|
||||
$machine = $this->createMachine('Machine sans CFV');
|
||||
|
||||
$client = $this->createViewerClient();
|
||||
$client->request('GET', sprintf('/api/machines/%s/structure', $machine->getId()));
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
$data = $client->getResponse()->toArray();
|
||||
|
||||
$this->assertArrayHasKey('customFieldValues', $data['machine']);
|
||||
$this->assertSame([], $data['machine']['customFieldValues']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user