Skip to content

Commit

Permalink
Merge pull request #3446 from nationalarchives/Fix_e2e_test
Browse files Browse the repository at this point in the history
Update error message for the date field when it is empty
  • Loading branch information
vimleshtna authored Nov 1, 2023
2 parents be50c31 + f7d1aff commit 28def34
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 13 additions & 12 deletions app/controllers/util/FormField.scala
Original file line number Diff line number Diff line change
Expand Up @@ -323,18 +323,19 @@ object DateField {
val fieldName = if (dateField.getAlternativeName == "Advisory Council Approval") dateField.fieldAlternativeName else dateField.getAlternativeName.toLowerCase

errorCode match {
case EMPTY_VALUE_ERROR_FOR_DAY | EMPTY_VALUE_ERROR => dateField.copy(fieldErrors = List(emptyValueError.format(fieldName, "day")))
case NUMBER_ERROR_FOR_DAY => dateField.copy(fieldErrors = List(wholeNumberError2.format("day", fieldName, wholeNumberExample)))
case NEGATIVE_NUMBER_ERROR_FOR_DAY => dateField.copy(fieldErrors = List(negativeNumberError.format("day")))
case INVALID_NUMBER_ERROR_FOR_DAY => dateField.copy(fieldErrors = List(invalidDateError.format("day", fieldName, "31")))
case EMPTY_VALUE_ERROR_FOR_MONTH => dateField.copy(fieldErrors = List(emptyValueError.format(fieldName, "month")))
case NUMBER_ERROR_FOR_MONTH => dateField.copy(fieldErrors = List(wholeNumberError2.format("month", fieldName, "3, 9, 12")))
case NEGATIVE_NUMBER_ERROR_FOR_MONTH => dateField.copy(fieldErrors = List(negativeNumberError.format("month")))
case INVALID_NUMBER_ERROR_FOR_MONTH => dateField.copy(fieldErrors = List(invalidDateError.format("month", fieldName, "12")))
case EMPTY_VALUE_ERROR_FOR_YEAR => dateField.copy(fieldErrors = List(emptyValueError.format(fieldName, "year")))
case NUMBER_ERROR_FOR_YEAR => dateField.copy(fieldErrors = List(wholeNumberError2.format("year", fieldName, "1994, 2000, 2023")))
case NEGATIVE_NUMBER_ERROR_FOR_YEAR => dateField.copy(fieldErrors = List(negativeNumberError.format("year")))
case INVALID_NUMBER_ERROR_FOR_YEAR => dateField.copy(fieldErrors = List(invalidYearError.format(fieldName)))
case EMPTY_VALUE_ERROR => dateField.copy(fieldErrors = List(dateNotEnteredError.format(fieldName)))
case EMPTY_VALUE_ERROR_FOR_DAY => dateField.copy(fieldErrors = List(emptyValueError.format(fieldName, "day")))
case NUMBER_ERROR_FOR_DAY => dateField.copy(fieldErrors = List(wholeNumberError2.format("day", fieldName, wholeNumberExample)))
case NEGATIVE_NUMBER_ERROR_FOR_DAY => dateField.copy(fieldErrors = List(negativeNumberError.format("day")))
case INVALID_NUMBER_ERROR_FOR_DAY => dateField.copy(fieldErrors = List(invalidDateError.format("day", fieldName, "31")))
case EMPTY_VALUE_ERROR_FOR_MONTH => dateField.copy(fieldErrors = List(emptyValueError.format(fieldName, "month")))
case NUMBER_ERROR_FOR_MONTH => dateField.copy(fieldErrors = List(wholeNumberError2.format("month", fieldName, "3, 9, 12")))
case NEGATIVE_NUMBER_ERROR_FOR_MONTH => dateField.copy(fieldErrors = List(negativeNumberError.format("month")))
case INVALID_NUMBER_ERROR_FOR_MONTH => dateField.copy(fieldErrors = List(invalidDateError.format("month", fieldName, "12")))
case EMPTY_VALUE_ERROR_FOR_YEAR => dateField.copy(fieldErrors = List(emptyValueError.format(fieldName, "year")))
case NUMBER_ERROR_FOR_YEAR => dateField.copy(fieldErrors = List(wholeNumberError2.format("year", fieldName, "1994, 2000, 2023")))
case NEGATIVE_NUMBER_ERROR_FOR_YEAR => dateField.copy(fieldErrors = List(negativeNumberError.format("year")))
case INVALID_NUMBER_ERROR_FOR_YEAR => dateField.copy(fieldErrors = List(invalidYearError.format(fieldName)))
case INVALID_DAY_FOR_MONTH_ERROR =>
val day = dateField.day.value.toInt
val month = dateField.month.value.toInt
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/util/FormFieldSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ class FormFieldSpec extends AnyWordSpec with MockitoSugar with BeforeAndAfterEac

"updateError should set an error message as per the given error code" in {

DateField.updateError(mandatoryDateField, EMPTY_VALUE_ERROR).fieldErrors shouldBe List("The alternativename must contain a day")
DateField.updateError(mandatoryDateField, EMPTY_VALUE_ERROR).fieldErrors shouldBe List("Enter the alternativename for this record")
DateField.updateError(mandatoryDateField, EMPTY_VALUE_ERROR_FOR_DAY).fieldErrors shouldBe List("The alternativename must contain a day")
DateField.updateError(mandatoryDateField, NUMBER_ERROR_FOR_DAY).fieldErrors shouldBe List("The day of the alternativename must be a whole number, like 3, 15, 21")
DateField.updateError(mandatoryDateField, NEGATIVE_NUMBER_ERROR_FOR_DAY).fieldErrors shouldBe List("The day cannot be a negative number")
Expand Down

0 comments on commit 28def34

Please sign in to comment.