Skip to content

Commit b552c9d

Browse files
ravise5ci-build
authored andcommitted
Constraint messages should work when type is integer for number-input (#1127)
1 parent 7ec4d30 commit b552c9d

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractBaseImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ protected String getConstraintMessage(ConstraintType type) {
269269
putConstraintMessage(ConstraintType.FORMAT, msgs.getFormatConstraintMessage());
270270
}
271271

272-
if (type.equals(Type.NUMBER)) {
272+
if (type.equals(Type.NUMBER) || type.equals(Type.INTEGER)) {
273273
putConstraintMessage(ConstraintType.MINIMUM, msgs.getMinimumConstraintMessage());
274274
putConstraintMessage(ConstraintType.MAXIMUM, msgs.getMaximumConstraintMessage());
275275
}

bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/NumberInputImplTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@
3939
import io.wcm.testing.mock.aem.junit5.AemContext;
4040
import io.wcm.testing.mock.aem.junit5.AemContextExtension;
4141

42-
import static org.junit.Assert.assertEquals;
43-
import static org.junit.Assert.assertFalse;
44-
import static org.junit.Assert.assertNull;
45-
import static org.junit.Assert.assertTrue;
42+
import static org.junit.Assert.*;
4643
import static org.mockito.Mockito.mock;
4744
import static org.mockito.Mockito.spy;
4845

@@ -51,6 +48,7 @@ public class NumberInputImplTest {
5148
private static final String BASE = "/form/numberinput";
5249
private static final String CONTENT_ROOT = "/content";
5350
private static final String PATH_NUMBER_INPUT_CUSTOMIZED = CONTENT_ROOT + "/numberinput-customized";
51+
private static final String PATH_NUMBER_INPUT_INTEGER_TYPE = CONTENT_ROOT + "/numberinput-integer-type";
5452
private static final String PATH_NUMBER_INPUT_CONSTRAINTS = CONTENT_ROOT + "/numberinput-exclusive";
5553
private static final String PATH_NUMBER_INPUT_BACKWARD_COMPATIBLE = CONTENT_ROOT + "/numberinput-backwardcompatible";
5654
private static final String PATH_NUMBER_INPUT_BACKWARD_COMPATIBLE_STRING = CONTENT_ROOT + "/numberinput-backwardcompatible-string";
@@ -241,6 +239,14 @@ void testGetConstraintMessages() {
241239
assertEquals(Collections.emptyMap(), numberInputMock.getConstraintMessages());
242240
}
243241

242+
@Test
243+
void testGetConstraintMessagesTypeInteger() {
244+
NumberInput numberInput = Utils.getComponentUnderTest(PATH_NUMBER_INPUT_INTEGER_TYPE, NumberInput.class, context);
245+
Map<ConstraintType, String> constraintsMessages = numberInput.getConstraintMessages();
246+
assertEquals(constraintsMessages.get(ConstraintType.MAXIMUM), "Please enter a valid Number");
247+
assertEquals(constraintsMessages.get(ConstraintType.MINIMUM), "Please enter a valid Number");
248+
}
249+
244250
@Test
245251
void testJSONExportForCustomized() throws Exception {
246252
NumberInput numberInput = Utils.getComponentUnderTest(PATH_NUMBER_INPUT_CUSTOMIZED, NumberInput.class, context);

bundles/af-core/src/test/resources/form/numberinput/test-content.json

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,30 @@
4848
"minimum" : 10002,
4949
"maximum" : 2000002
5050
},
51+
"numberinput-integer-type" : {
52+
"jcr:primaryType": "nt:unstructured",
53+
"sling:resourceType" : "core/fd/components/form/numberinput/v1/numberinput",
54+
"name" : "abc",
55+
"jcr:title" : "def",
56+
"hideTitle" : true,
57+
"description" : "dummy",
58+
"visible" : false,
59+
"readOnly": false,
60+
"enabled": true,
61+
"assistPriority" : "custom",
62+
"dataRef" : "a.b",
63+
"custom" : "Custom screen reader text",
64+
"typeMessage" : "incorrect type",
65+
"tooltip": "test-short-description",
66+
"fieldType": "number-input",
67+
"type" : "integer",
68+
"maximumMessage" : "Please enter a valid Number",
69+
"minimumMessage" : "Please enter a valid Number",
70+
"exclusiveMinimum" : true,
71+
"exclusiveMaximum" : true,
72+
"minimum" : 10002,
73+
"maximum" : 2000002
74+
},
5175
"numberinput-datalayer": {
5276
"id": "numberinput-57e5de6073",
5377
"sling:resourceType": "core/fd/components/form/numberinput/v1/numberinput",
@@ -130,4 +154,4 @@
130154
},
131155
":type": "forms-components-examples/components/form/numberinput"
132156
}
133-
}
157+
}

0 commit comments

Comments
 (0)