diff --git a/assets/styles/utilities/dsfr-extensions/sizing.css b/assets/styles/utilities/dsfr-extensions/sizing.css index 7fa07d1d6..df887d910 100644 --- a/assets/styles/utilities/dsfr-extensions/sizing.css +++ b/assets/styles/utilities/dsfr-extensions/sizing.css @@ -6,6 +6,10 @@ max-width: calc(37 * 0.5rem); } +.fr-x-max-w-38w { + max-width: calc(38 * 0.5rem); +} + .fr-x-max-w-156w { max-width: calc(156 * 0.5rem); } diff --git a/src/Domain/Condition/VehicleSet.php b/src/Domain/Condition/VehicleSet.php index b35953380..7f920417f 100644 --- a/src/Domain/Condition/VehicleSet.php +++ b/src/Domain/Condition/VehicleSet.php @@ -8,8 +8,6 @@ class VehicleSet { - public const DEFAULT_MAX_WEIGHT = 3.5; - public function __construct( private string $uuid, private Measure $measure, diff --git a/src/Infrastructure/Form/Regulation/VehicleSetFormType.php b/src/Infrastructure/Form/Regulation/VehicleSetFormType.php index 4c97c4a10..16cbd64cb 100644 --- a/src/Infrastructure/Form/Regulation/VehicleSetFormType.php +++ b/src/Infrastructure/Form/Regulation/VehicleSetFormType.php @@ -5,7 +5,6 @@ namespace App\Infrastructure\Form\Regulation; use App\Application\Regulation\Command\VehicleSet\SaveVehicleSetCommand; -use App\Domain\Condition\VehicleSet; use App\Domain\Regulation\Enum\CritairEnum; use App\Domain\Regulation\Enum\VehicleTypeEnum; use Symfony\Component\Form\AbstractType; @@ -42,12 +41,20 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ) ->add( 'heavyweightMaxWeight', - NumberType::class, - options: [ + ChoiceType::class, + options : [ + 'choices' => [ + 3.5 => 3.5, + 7.5 => 7.5, + 19 => 19, + 26 => 26, + 32 => 32, + 44 => 44, + ], 'label' => 'regulation.vehicle_set.heavyweightMaxWeight', + 'placeholder' => 'regulation.vehicle_set.heavyweightMaxWeight.placeholder', 'help' => 'regulation.vehicle_set.heavyweightMaxWeight.help', 'required' => false, - 'empty_data' => '3,5', ], ) ->add( @@ -121,15 +128,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void }, ), ); - - $builder - ->get('heavyweightMaxWeight') - ->addModelTransformer( - new CallbackTransformer( - transform: fn ($maxWeight) => $maxWeight ?? VehicleSet::DEFAULT_MAX_WEIGHT, - reverseTransform: fn ($value) => $value, - ), - ); } private function getRestrictedTypesOptions(): array diff --git a/templates/regulation/_vehicle_set_form.html.twig b/templates/regulation/_vehicle_set_form.html.twig index 103788ef2..50f50e863 100644 --- a/templates/regulation/_vehicle_set_form.html.twig +++ b/templates/regulation/_vehicle_set_form.html.twig @@ -104,7 +104,7 @@
@@ -113,8 +113,8 @@
{{ form_row(form.heavyweightMaxWeight, { - group_class: 'fr-input-group', - widget_class: 'fr-input', + group_class: 'fr-select-group', + widget_class: 'fr-select', widget_suffix: 'common.unit.tons'|trans, }) }}
diff --git a/tests/Integration/Infrastructure/Controller/Regulation/Fragments/AddMeasureControllerTest.php b/tests/Integration/Infrastructure/Controller/Regulation/Fragments/AddMeasureControllerTest.php index 7bca86a79..d004f4ed8 100644 --- a/tests/Integration/Infrastructure/Controller/Regulation/Fragments/AddMeasureControllerTest.php +++ b/tests/Integration/Infrastructure/Controller/Regulation/Fragments/AddMeasureControllerTest.php @@ -643,10 +643,28 @@ public function testInvalidVehicleSetBlankRestrictedTypes(): void $saveButton = $crawler->selectButton('Valider'); $form = $saveButton->form(); $values = $form->getPhpValues(); - $this->assertSame($values['measure_form']['vehicleSet']['heavyweightMaxWeight'], '3,5'); $this->assertStringContainsString('Veuillez spécifier un ou plusieurs véhicules concernés.', $crawler->filter('#measure_form_vehicleSet_restrictedTypes_error')->text()); } + public function testInvalidVehicleSetBlankHeavyweightMaxWeight(): void + { + $client = $this->login(); + $crawler = $client->request('GET', '/_fragment/regulations/' . RegulationOrderRecordFixture::UUID_TYPICAL . '/measure/add'); + $this->assertResponseStatusCodeSame(200); + $this->assertSecurityHeaders(); + + $saveButton = $crawler->selectButton('Valider'); + $form = $saveButton->form(); + $values = $form->getPhpValues(); + $values['measure_form']['type'] = 'noEntry'; + $values['measure_form']['vehicleSet']['allVehicles'] = 'no'; + $values['measure_form']['vehicleSet']['restrictedTypes'] = ['heavyGoodsVehicle']; + + $crawler = $client->request($form->getMethod(), $form->getUri(), $values); + $this->assertResponseStatusCodeSame(422); + $this->assertStringContainsString('Cette valeur ne doit pas être vide.', $crawler->filter('#measure_form_vehicleSet_heavyweightMaxWeight_error')->text()); + } + public function testInvalidVehicleSetBlankOtherRestrictedTypeText(): void { $client = $this->login(); @@ -785,15 +803,13 @@ public function testInvalidVehicleSetCharacteristicsNotNumber(): void $values = $form->getPhpValues(); $values['measure_form']['type'] = 'noEntry'; $values['measure_form']['vehicleSet']['allVehicles'] = 'no'; - $values['measure_form']['vehicleSet']['restrictedTypes'] = ['heavyGoodsVehicle', 'dimensions']; - $values['measure_form']['vehicleSet']['heavyweightMaxWeight'] = 'not a number'; + $values['measure_form']['vehicleSet']['restrictedTypes'] = ['dimensions']; $values['measure_form']['vehicleSet']['maxWidth'] = 'true'; $values['measure_form']['vehicleSet']['maxLength'] = [12]; $values['measure_form']['vehicleSet']['maxHeight'] = '2.4m'; $crawler = $client->request($form->getMethod(), $form->getUri(), $values); $this->assertResponseStatusCodeSame(422); - $this->assertStringContainsString('Veuillez saisir un nombre.', $crawler->filter('#measure_form_vehicleSet_heavyweightMaxWeight_error')->text()); $this->assertStringContainsString('Veuillez saisir un nombre.', $crawler->filter('#measure_form_vehicleSet_maxWidth_error')->text()); $this->assertStringContainsString('Veuillez saisir un nombre.', $crawler->filter('#measure_form_vehicleSet_maxLength_error')->text()); $this->assertStringContainsString('Veuillez saisir un nombre.', $crawler->filter('#measure_form_vehicleSet_maxHeight_error')->text()); @@ -811,15 +827,13 @@ public function testInvalidVehicleSetCharacteristicsNotPositive(): void $values = $form->getPhpValues(); $values['measure_form']['type'] = 'noEntry'; $values['measure_form']['vehicleSet']['allVehicles'] = 'no'; - $values['measure_form']['vehicleSet']['restrictedTypes'] = ['heavyGoodsVehicle', 'dimensions']; - $values['measure_form']['vehicleSet']['heavyweightMaxWeight'] = -1; + $values['measure_form']['vehicleSet']['restrictedTypes'] = ['dimensions']; $values['measure_form']['vehicleSet']['maxWidth'] = -0.1; $values['measure_form']['vehicleSet']['maxLength'] = -2.3; $values['measure_form']['vehicleSet']['maxHeight'] = -12; $crawler = $client->request($form->getMethod(), $form->getUri(), $values); $this->assertResponseStatusCodeSame(422); - $this->assertStringContainsString('Cette valeur doit être supérieure ou égale à zéro.', $crawler->filter('#measure_form_vehicleSet_heavyweightMaxWeight_error')->text()); $this->assertStringContainsString('Cette valeur doit être supérieure ou égale à zéro.', $crawler->filter('#measure_form_vehicleSet_maxWidth_error')->text()); $this->assertStringContainsString('Cette valeur doit être supérieure ou égale à zéro.', $crawler->filter('#measure_form_vehicleSet_maxLength_error')->text()); $this->assertStringContainsString('Cette valeur doit être supérieure ou égale à zéro.', $crawler->filter('#measure_form_vehicleSet_maxHeight_error')->text()); diff --git a/translations/messages.fr.xlf b/translations/messages.fr.xlf index 868e7be03..2c752b90c 100644 --- a/translations/messages.fr.xlf +++ b/translations/messages.fr.xlf @@ -1914,13 +1914,17 @@ regulation.vehicle_set.restricted_types.help Spécifiez les véhicules pour lesquels la restriction s'applique : + + regulation.vehicle_set.heavyweightMaxWeight.placeholder + Sélectionner le poids + regulation.vehicle_set.heavyweightMaxWeight Poids maximum regulation.vehicle_set.heavyweightMaxWeight.help - Spécifier le poids maximum autorisé + La restriction s'applique aux véhicules dont le PTAC est supérieur à ... regulation.vehicle_set.maxWidth @@ -1972,7 +1976,7 @@ regulation.vehicle_set.type.heavyGoodsVehicle - Poids lourds + Poids regulation.vehicle_set.type.dimensions