From d8d256be338aedc65eb3b576d24095d72e3ba826 Mon Sep 17 00:00:00 2001 From: Ravi Date: Fri, 15 Mar 2024 15:54:43 +0530 Subject: [PATCH] Constraint messages should work when type is integer for number-input --- .../components/util/AbstractBaseImpl.java | 2 +- .../models/v1/form/NumberInputImplTest.java | 14 +++++++--- .../form/numberinput/test-content.json | 26 ++++++++++++++++++- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractBaseImpl.java b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractBaseImpl.java index def88a8889..980673276a 100644 --- a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractBaseImpl.java +++ b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractBaseImpl.java @@ -269,7 +269,7 @@ protected String getConstraintMessage(ConstraintType type) { putConstraintMessage(ConstraintType.FORMAT, msgs.getFormatConstraintMessage()); } - if (type.equals(Type.NUMBER)) { + if (type.equals(Type.NUMBER) || type.equals(Type.INTEGER)) { putConstraintMessage(ConstraintType.MINIMUM, msgs.getMinimumConstraintMessage()); putConstraintMessage(ConstraintType.MAXIMUM, msgs.getMaximumConstraintMessage()); } diff --git a/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/NumberInputImplTest.java b/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/NumberInputImplTest.java index 1071f387f8..bc31c7a919 100644 --- a/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/NumberInputImplTest.java +++ b/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/NumberInputImplTest.java @@ -39,10 +39,7 @@ import io.wcm.testing.mock.aem.junit5.AemContext; import io.wcm.testing.mock.aem.junit5.AemContextExtension; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -51,6 +48,7 @@ public class NumberInputImplTest { private static final String BASE = "/form/numberinput"; private static final String CONTENT_ROOT = "/content"; private static final String PATH_NUMBER_INPUT_CUSTOMIZED = CONTENT_ROOT + "/numberinput-customized"; + private static final String PATH_NUMBER_INPUT_INTEGER_TYPE = CONTENT_ROOT + "/numberinput-integer-type"; private static final String PATH_NUMBER_INPUT_CONSTRAINTS = CONTENT_ROOT + "/numberinput-exclusive"; private static final String PATH_NUMBER_INPUT_BACKWARD_COMPATIBLE = CONTENT_ROOT + "/numberinput-backwardcompatible"; private static final String PATH_NUMBER_INPUT_BACKWARD_COMPATIBLE_STRING = CONTENT_ROOT + "/numberinput-backwardcompatible-string"; @@ -241,6 +239,14 @@ void testGetConstraintMessages() { assertEquals(Collections.emptyMap(), numberInputMock.getConstraintMessages()); } + @Test + void testGetConstraintMessagesTypeInteger() { + NumberInput numberInput = Utils.getComponentUnderTest(PATH_NUMBER_INPUT_INTEGER_TYPE, NumberInput.class, context); + Map constraintsMessages = numberInput.getConstraintMessages(); + assertEquals(constraintsMessages.get(ConstraintType.MAXIMUM), "Please enter a valid Number"); + assertEquals(constraintsMessages.get(ConstraintType.MINIMUM), "Please enter a valid Number"); + } + @Test void testJSONExportForCustomized() throws Exception { NumberInput numberInput = Utils.getComponentUnderTest(PATH_NUMBER_INPUT_CUSTOMIZED, NumberInput.class, context); diff --git a/bundles/af-core/src/test/resources/form/numberinput/test-content.json b/bundles/af-core/src/test/resources/form/numberinput/test-content.json index dce6a44a8a..4fd1658e88 100644 --- a/bundles/af-core/src/test/resources/form/numberinput/test-content.json +++ b/bundles/af-core/src/test/resources/form/numberinput/test-content.json @@ -48,6 +48,30 @@ "minimum" : 10002, "maximum" : 2000002 }, + "numberinput-integer-type" : { + "jcr:primaryType": "nt:unstructured", + "sling:resourceType" : "core/fd/components/form/numberinput/v1/numberinput", + "name" : "abc", + "jcr:title" : "def", + "hideTitle" : true, + "description" : "dummy", + "visible" : false, + "readOnly": false, + "enabled": true, + "assistPriority" : "custom", + "dataRef" : "a.b", + "custom" : "Custom screen reader text", + "typeMessage" : "incorrect type", + "tooltip": "test-short-description", + "fieldType": "number-input", + "type" : "integer", + "maximumMessage" : "Please enter a valid Number", + "minimumMessage" : "Please enter a valid Number", + "exclusiveMinimum" : true, + "exclusiveMaximum" : true, + "minimum" : 10002, + "maximum" : 2000002 + }, "numberinput-datalayer": { "id": "numberinput-57e5de6073", "sling:resourceType": "core/fd/components/form/numberinput/v1/numberinput", @@ -130,4 +154,4 @@ }, ":type": "forms-components-examples/components/form/numberinput" } -} \ No newline at end of file +}