Skip to content

Commit

Permalink
feat: add 'at least 4 digits' in control
Browse files Browse the repository at this point in the history
  • Loading branch information
nsenave committed Dec 5, 2024
1 parent 7d2c8a7 commit d1cb516
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ java {

allprojects {
group = "fr.insee.eno"
version = "3.30.0-SNAPSHOT"
version = "3.30.0-SNAPSHOT.1"
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ private void createFormatControlsForDatepicker(Datepicker datepicker) {
Optional<ControlType> controlBounds = getFormatControlFromDatepickerAttributes(id, minValue, maxValue, format, responseName);
controlBounds.ifPresent(controls::addFirst);
controlYearFormat.ifPresent(controls::addFirst);
// Note: it's important that the year format is added in first position, since in some cases only the message
// of the first control is displayed.
}

/**
Expand Down Expand Up @@ -198,9 +200,10 @@ private Optional<ControlType> generateDatepickerYearControl(String id, String fo
return Optional.empty();
}
String controlId = id + "-format-year";
String expression = String.format(
"not(not(isnull(%s)) and cast(cast(cast(%s, date, \"%s\"), string, \"YYYY\"), integer) <= 999)",
responseName, responseName, format);
String expression = String.format("not(not(isnull(%s)) and (" +
"cast(cast(cast(%s, date, \"%s\"), string, \"YYYY\"), integer) <= 999 or " +
"cast(cast(cast(%s, date, \"%s\"), string, \"YYYY\"), integer) > 9999))",
responseName, responseName, format, responseName, format);
String message = "\"L'année doit être saisie avec 4 chiffres.\"";
return Optional.of(createFormatControl(controlId, expression, message));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ void datepickerYearFormatControl() {
ControlType yearControl = controls.getFirst();

assertEquals("datepicker-id-format-year", yearControl.getId());
String expected = "not(not(isnull(DATE_VAR)) " +
"and cast(cast(cast(DATE_VAR, date, \"YYYY-MM-DD\"), string, \"YYYY\"), integer) <= 999)";
String expected = "not(not(isnull(DATE_VAR)) and (" +
"cast(cast(cast(DATE_VAR, date, \"YYYY-MM-DD\"), string, \"YYYY\"), integer) <= 999 or " +
"cast(cast(cast(DATE_VAR, date, \"YYYY-MM-DD\"), string, \"YYYY\"), integer) > 9999))";
assertEquals(expected, yearControl.getControl().getValue());
assertEquals(LabelTypeEnum.VTL, yearControl.getControl().getType());
assertEquals(LabelTypeEnum.VTL_MD, yearControl.getErrorMessage().getType());
Expand Down

0 comments on commit d1cb516

Please sign in to comment.