From a42a0651f40b29c1057a213fd71dfbeb381b6c23 Mon Sep 17 00:00:00 2001 From: Shrikha Date: Wed, 27 Mar 2024 15:03:14 +0530 Subject: [PATCH] FORMS-13470: Added the marker interface for Modal. --- .../internal/form/FormConstants.java | 3 + .../internal/models/v1/form/ModalImpl.java | 38 ++++++- .../core/components/models/form/Modal.java | 30 +++++- .../models/v1/form/ModalImplTest.java | 59 +++-------- .../resources/form/modal/exporter-modal.json | 98 +++++++++++++++++++ .../resources/form/modal/test-content.json | 30 ++++++ .../form/modal/v1/modal/.content.xml | 2 +- .../components/form/modal/v1/modal/modal.html | 14 +-- 8 files changed, 219 insertions(+), 55 deletions(-) diff --git a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/form/FormConstants.java b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/form/FormConstants.java index a2020efd07..affe5280e6 100644 --- a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/form/FormConstants.java +++ b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/form/FormConstants.java @@ -117,6 +117,9 @@ private FormConstants() { /** The resource type for terms and conditions v1 */ public static final String RT_FD_FORM_TERMS_AND_CONDITIONS_V1 = RT_FD_FORM_PREFIX + "termsandconditions/v1/termsandconditions"; + /** The resource type for modal v1 */ + public static final String RT_FD_FORM_MODAL_V1 = RT_FD_FORM_PREFIX + "modal/v1/modal"; + public static final String FORM_FIELD_TYPE = "form"; public static final String REQ_ATTR_FORMCONTAINER_PATH = "formContainerPath"; diff --git a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/ModalImpl.java b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/ModalImpl.java index 96bd1f0809..b414af4fcc 100644 --- a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/ModalImpl.java +++ b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/ModalImpl.java @@ -1,2 +1,38 @@ -package com.adobe.cq.forms.core.components.internal.models.v1.form;public class ModalImpl { +/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~ Copyright 2024 Adobe + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + +package com.adobe.cq.forms.core.components.internal.models.v1.form; + +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Exporter; +import org.apache.sling.models.annotations.Model; + +import com.adobe.cq.export.json.ComponentExporter; +import com.adobe.cq.export.json.ExporterConstants; +import com.adobe.cq.forms.core.components.internal.form.FormConstants; +import com.adobe.cq.forms.core.components.models.form.Modal; + +@Model( + adaptables = { SlingHttpServletRequest.class, Resource.class }, + adapters = { Modal.class, + ComponentExporter.class }, + resourceType = { FormConstants.RT_FD_FORM_MODAL_V1 }) + +@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION) +public class ModalImpl extends PanelImpl implements Modal { + } diff --git a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/Modal.java b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/Modal.java index 830804189d..8d3ff05cad 100644 --- a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/Modal.java +++ b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/Modal.java @@ -1,2 +1,30 @@ -package com.adobe.cq.forms.core.components.models.form;public class Modal { +/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~ Copyright 2024 Adobe + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + +package com.adobe.cq.forms.core.components.models.form; + +import org.osgi.annotation.versioning.ConsumerType; + +/** + * Defines the form {@code Modal} Sling Model used for the + * {@code /apps/core/fd/components/form/modal/v1/modal} component. + * + * @since com.adobe.cq.forms.core.components.models.form 4.7.0 + */ +@ConsumerType +public interface Modal extends Container, ContainerConstraint, Base { + } diff --git a/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/ModalImplTest.java b/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/ModalImplTest.java index 57c936958b..ae934f1ebd 100644 --- a/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/ModalImplTest.java +++ b/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/ModalImplTest.java @@ -1,5 +1,5 @@ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ Copyright 2023 Adobe + ~ Copyright 2024 Adobe ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ import java.util.stream.StreamSupport; import org.apache.sling.api.resource.Resource; -import org.junit.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -31,7 +30,7 @@ import com.adobe.cq.export.json.SlingModelFilter; import com.adobe.cq.forms.core.Utils; import com.adobe.cq.forms.core.components.internal.form.FormConstants; -import com.adobe.cq.forms.core.components.models.form.TermsAndConditions; +import com.adobe.cq.forms.core.components.models.form.Modal; import com.adobe.cq.forms.core.context.FormsCoreComponentTestContext; import com.day.cq.wcm.api.NameConstants; import com.day.cq.wcm.msm.api.MSMNameConstants; @@ -41,20 +40,19 @@ import static org.junit.Assert.assertEquals; @ExtendWith(AemContextExtension.class) -public class TermsAndConditionsImplTest { +public class ModalImplTest { - private static final String BASE = "/form/termsandconditions"; + private static final String BASE = "/form/modal"; private static final String CONTENT_ROOT = "/content"; - private static final String PATH_TNC = CONTENT_ROOT + "/termsandconditions"; - - private static final String PATH_NOWRAP_TNC = CONTENT_ROOT + "/termsandconditionsNoWrapData"; + private static final String PATH_MODAL = CONTENT_ROOT + "/modal"; private final AemContext context = FormsCoreComponentTestContext.newAemContext(); @BeforeEach public void setUp() { context.load().json(BASE + FormsCoreComponentTestContext.TEST_CONTENT_JSON, CONTENT_ROOT); + context.registerService(SlingModelFilter.class, new SlingModelFilter() { private final Set IGNORED_NODE_NAMES = new HashSet() { @@ -81,46 +79,17 @@ public Iterable filterChildResources(Iterable childResources } @Test - void testExportedType() throws Exception { - TermsAndConditions tnc = Utils.getComponentUnderTest(PATH_TNC, TermsAndConditions.class, context); - assertEquals(FormConstants.RT_FD_FORM_TERMS_AND_CONDITIONS_V1, tnc.getExportedType()); - TermsAndConditions tncMock = Mockito.mock(TermsAndConditions.class); - Mockito.when(tncMock.getExportedType()).thenCallRealMethod(); - assertEquals("", tncMock.getExportedType()); - } - - @Test - public void testGetProperties() { - TermsAndConditions tnc = Utils.getComponentUnderTest(PATH_TNC, TermsAndConditions.class, context); - Assert.assertTrue(tnc.isShowApprovalOption()); - Assert.assertTrue(tnc.isShowAsPopup()); - Assert.assertFalse(tnc.isShowLink()); - } - - @Test - public void testCustomFDProperty() { - TermsAndConditions tnc = Utils.getComponentUnderTest(PATH_TNC, TermsAndConditions.class, context); - Map props = tnc.getProperties(); - Assert.assertTrue(props.containsKey("fd:tnc")); - Assert.assertTrue((Boolean) props.get("fd:tnc")); - + void testExportedType() { + Modal modal = Utils.getComponentUnderTest(PATH_MODAL, Modal.class, context); + assertEquals(FormConstants.RT_FD_FORM_MODAL_V1, modal.getExportedType()); + Modal modalMock = Mockito.mock(Modal.class); + Mockito.when(modalMock.getExportedType()).thenCallRealMethod(); + assertEquals("", modalMock.getExportedType()); } @Test void testJSONExport() throws Exception { - TermsAndConditions tnc = Utils.getComponentUnderTest(PATH_TNC, TermsAndConditions.class, context); - Utils.testJSONExport(tnc, Utils.getTestExporterJSONPath(BASE, PATH_TNC)); - } - - @Test - void testJSONExport_showLink() throws Exception { - TermsAndConditions tnc = Utils.getComponentUnderTest(PATH_NOWRAP_TNC, TermsAndConditions.class, context); - Utils.testJSONExport(tnc, Utils.getTestExporterJSONPath(BASE, PATH_NOWRAP_TNC)); - } - - @Test - void testNoWrap() { - TermsAndConditions tnc = Utils.getComponentUnderTest(PATH_NOWRAP_TNC, TermsAndConditions.class, context); - Assert.assertNull(tnc.getType()); + Modal modal = Utils.getComponentUnderTest(PATH_MODAL, Modal.class, context); + Utils.testJSONExport(modal, Utils.getTestExporterJSONPath(BASE, PATH_MODAL)); } } diff --git a/bundles/af-core/src/test/resources/form/modal/exporter-modal.json b/bundles/af-core/src/test/resources/form/modal/exporter-modal.json index e69de29bb2..e34dfd4920 100644 --- a/bundles/af-core/src/test/resources/form/modal/exporter-modal.json +++ b/bundles/af-core/src/test/resources/form/modal/exporter-modal.json @@ -0,0 +1,98 @@ +{ + "id": "modal-3f8ac07b1d", + "fieldType": "panel", + "name": "modal1711016014566", + "label": { + "value": "Modal" + }, + "events": { + "custom:setProperty": [ + "$event.payload" + ] + }, + "properties": { + "fd:dor": { + "dorExclusion": false, + "dorExcludeTitle": false, + "dorExcludeDescription": false + }, + "fd:path": "/content/modal" + }, + ":itemsOrder": [ + "panelcontainer", + "button" + ], + ":items": { + "panelcontainer": { + "id": "panelcontainer-bc5563a2b9", + "fieldType": "panel", + "name": "panelcontainer", + "label": { + "value": "Panel" + }, + "events": { + "custom:setProperty": [ + "$event.payload" + ] + }, + "properties": { + "fd:dor": { + "dorExclusion": false, + "dorExcludeTitle": false, + "dorExcludeDescription": false + }, + "fd:path": "/content/modal/panelcontainer" + }, + ":itemsOrder": [ + "datepicker" + ], + ":items": { + "datepicker": { + "id": "datepicker-43f0efd69b", + "fieldType": "date-input", + "name": "datepicker1711461935572", + "type": "string", + "label": { + "value": "Date Input" + }, + "events": { + "custom:setProperty": [ + "$event.payload" + ] + }, + "properties": { + "fd:dor": { + "dorExclusion": false + }, + "fd:path": "/content/modal/panelcontainer/datepicker" + }, + "format": "date", + ":type": "core/fd/components/form/datepicker/v1/datepicker" + } + }, + ":type": "core/fd/components/form/panelcontainer/v1/panelcontainer" + }, + "button": { + "id": "button-1605226465", + "fieldType": "button", + "name": "button1711016014673", + "properties": { + "fd:dor": { + "dorExclusion": false + }, + "fd:path": "/content/modal/button", + "fd:buttonType": "button" + }, + "label": { + "value": "Open Modal" + }, + "events": { + "custom:setProperty": [ + "$event.payload" + ] + }, + ":type": "core/fd/components/form/button/v1/button" + } + }, + ":type": "core/fd/components/form/modal/v1/modal" +} \ No newline at end of file diff --git a/bundles/af-core/src/test/resources/form/modal/test-content.json b/bundles/af-core/src/test/resources/form/modal/test-content.json index e69de29bb2..53f96982c3 100644 --- a/bundles/af-core/src/test/resources/form/modal/test-content.json +++ b/bundles/af-core/src/test/resources/form/modal/test-content.json @@ -0,0 +1,30 @@ +{ + "modal": { + "jcr:primaryType": "nt:unstructured", + "fieldType": "panel", + "jcr:title": "Modal", + "name": "modal1711016014566", + "sling:resourceType": "core/fd/components/form/modal/v1/modal", + "panelcontainer": { + "jcr:primaryType": "nt:unstructured", + "fieldType": "panel", + "jcr:title": "Panel", + "name": "panelcontainer", + "sling:resourceType": "core/fd/components/form/panelcontainer/v1/panelcontainer", + "datepicker" : { + "jcr:primaryType": "nt:unstructured", + "fieldType": "date-input", + "jcr:title": "Date Input", + "name": "datepicker1711461935572", + "sling:resourceType": "core/fd/components/form/datepicker/v1/datepicker" + } + }, + "button" : { + "jcr:primaryType": "nt:unstructured", + "fieldType": "button", + "jcr:title": "Open Modal", + "name": "button1711016014673", + "sling:resourceType": "core/fd/components/form/button/v1/button" + } + } +} \ No newline at end of file diff --git a/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/modal/v1/modal/.content.xml b/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/modal/v1/modal/.content.xml index 82a675aecf..8a12fa36a3 100644 --- a/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/modal/v1/modal/.content.xml +++ b/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/modal/v1/modal/.content.xml @@ -20,5 +20,5 @@ jcr:description="Modal" jcr:primaryType="cq:Component" jcr:title="Adaptive Form Modal (v1)" - sling:resourceSuperType="core/fd/components/form/panelcontainer/v1/panelcontainer" + sling:resourceSuperType="wcm/foundation/components/responsivegrid" componentGroup=".core-adaptiveform"/> \ No newline at end of file diff --git a/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/modal/v1/modal/modal.html b/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/modal/v1/modal/modal.html index 15782461c4..7b92d6fd40 100644 --- a/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/modal/v1/modal/modal.html +++ b/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/modal/v1/modal/modal.html @@ -14,7 +14,7 @@ ~ limitations under the License. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/--> -
-
-
+
+
@@ -43,6 +43,6 @@
-
-
+
+