Skip to content

Commit

Permalink
Création d'une dropdown avec les catégories de véhicules lourds (#1118)
Browse files Browse the repository at this point in the history
* dropdown with weight list

* delete enum

* validation

* tests integration

* change input size

* refacto heavyweightMaxWeight choices

---------

Co-authored-by: Mathieu MARCHOIS <[email protected]>
  • Loading branch information
Lealefoulon and mmarchois authored Dec 19, 2024
1 parent 7b2918b commit 08ee7c7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 27 deletions.
4 changes: 4 additions & 0 deletions assets/styles/utilities/dsfr-extensions/sizing.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 0 additions & 2 deletions src/Domain/Condition/VehicleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

class VehicleSet
{
public const DEFAULT_MAX_WEIGHT = 3.5;

public function __construct(
private string $uuid,
private Measure $measure,
Expand Down
24 changes: 11 additions & 13 deletions src/Infrastructure/Form/Regulation/VehicleSetFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions templates/regulation/_vehicle_set_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@

<fieldset
data-controller="section form-control"
class="fr-fieldset fr-x-max-w-32w {{ restrictedDetailsClass['heavyGoodsVehicle'] }}"
class="fr-fieldset fr-x-max-w-38w {{ restrictedDetailsClass['heavyGoodsVehicle'] }}"
aria-labelledby="heavyGoodsVehicle-details-legend-{{ index }}"
{% if 'heavyGoodsVehicle' not in form.restrictedTypes.vars.value %}hidden disabled{% endif %}
>
Expand All @@ -113,8 +113,8 @@
</legend>
<div class="fr-fieldset__element">
{{ 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,
}) }}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
8 changes: 6 additions & 2 deletions translations/messages.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -1914,13 +1914,17 @@
<source>regulation.vehicle_set.restricted_types.help</source>
<target>Spécifiez les véhicules pour lesquels la restriction s'applique :</target>
</trans-unit>
<trans-unit id="regulation.vehicle_set.heavyweightMaxWeight.placeholder">
<source>regulation.vehicle_set.heavyweightMaxWeight.placeholder</source>
<target>Sélectionner le poids</target>
</trans-unit>
<trans-unit id="regulation.vehicle_set.heavyweightMaxWeight">
<source>regulation.vehicle_set.heavyweightMaxWeight</source>
<target>Poids maximum</target>
</trans-unit>
<trans-unit id="regulation.vehicle_set.heavyweightMaxWeight.help">
<source>regulation.vehicle_set.heavyweightMaxWeight.help</source>
<target>Spécifier le poids maximum autorisé</target>
<target>La restriction s'applique aux véhicules dont le PTAC est supérieur à ...</target>
</trans-unit>
<trans-unit id="regulation.vehicle_set.maxWidth">
<source>regulation.vehicle_set.maxWidth</source>
Expand Down Expand Up @@ -1972,7 +1976,7 @@
</trans-unit>
<trans-unit id="regulation.vehicle_set.type.heavyGoodsVehicle">
<source>regulation.vehicle_set.type.heavyGoodsVehicle</source>
<target>Poids lourds</target>
<target>Poids</target>
</trans-unit>
<trans-unit id="regulation.vehicle_set.type.dimensions">
<source>regulation.vehicle_set.type.dimensions</source>
Expand Down

0 comments on commit 08ee7c7

Please sign in to comment.