Skip to content

Commit

Permalink
FORMS-13470: Added the marker interface for Modal.
Browse files Browse the repository at this point in the history
  • Loading branch information
s1mahanty authored and ci-build committed Mar 27, 2024
1 parent f3306a4 commit a42a065
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

}
Original file line number Diff line number Diff line change
@@ -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 {

}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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<String> IGNORED_NODE_NAMES = new HashSet<String>() {
Expand All @@ -81,46 +79,17 @@ public Iterable<Resource> filterChildResources(Iterable<Resource> 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<String, Object> 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));
}
}
98 changes: 98 additions & 0 deletions bundles/af-core/src/test/resources/form/modal/exporter-modal.json
Original file line number Diff line number Diff line change
@@ -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"
}
30 changes: 30 additions & 0 deletions bundles/af-core/src/test/resources/form/modal/test-content.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->

<sly data-sly-use.panel="com.adobe.cq.forms.core.components.models.form.Panel"
<sly data-sly-use.modal="com.adobe.cq.forms.core.components.models.form.Modal"
data-sly-use.renderer="${'modal.js'}"
data-sly-use.label="${renderer.labelPath}"
data-sly-use.shortDescription="${renderer.shortDescriptionPath}"
Expand All @@ -27,13 +27,13 @@
data-cmp-is="adaptiveFormModal"
data-sly-use.formstructparser="com.adobe.cq.forms.core.components.models.form.FormStructureParser"
data-sly-use.component="com.adobe.cq.wcm.core.components.models.Component"
id="${panel.id}"
title="${panel.tooltipVisible ? '' : panel.tooltipText}"
id="${modal.id}"
title="${modal.tooltipVisible ? '' : modal.tooltipText}"
data-cmp-adaptiveformcontainer-path="${formstructparser.formContainerPath}">

<div class="cmp-adaptiveform-modal__label-container">
<div data-sly-call="${label.label @componentId=widgetId, labelValue=panel.label.value, labelVisible=panel.label.visible, bemBlock='cmp-adaptiveform-modal'}" data-sly-unwrap></div>
<div data-sly-call="${questionMark.questionMark @componentId=panel.id, longDescription=panel.description, bemBlock='cmp-adaptiveform-modal'}" data-sly-unwrap></div>
<div data-sly-call="${label.label @componentId=widgetId, labelValue=modal.label.value, labelVisible=modal.label.visible, bemBlock='cmp-adaptiveform-modal'}" data-sly-unwrap></div>
<div data-sly-call="${questionMark.questionMark @componentId=modal.id, longDescription=modal.description, bemBlock='cmp-adaptiveform-modal'}" data-sly-unwrap></div>
</div>

<div role="dialog">
Expand All @@ -43,6 +43,6 @@
</div>
<div class="cmp-adaptiveform-modal__button" data-sly-resource="${'button'}"></div>

<div data-sly-call="${shortDescription.shortDescription @componentId=panel.id, shortDescriptionVisible=panel.tooltipVisible, shortDescription=panel.tooltip, bemBlock='cmp-adaptiveform-modal'}" data-sly-unwrap></div>
<div data-sly-call="${longDescription.longDescription @componentId=panel.id, longDescription=panel.description, bemBlock='cmp-adaptiveform-modal'}" data-sly-unwrap></div>
<div data-sly-call="${shortDescription.shortDescription @componentId=modal.id, shortDescriptionVisible=modal.tooltipVisible, shortDescription=modal.tooltip, bemBlock='cmp-adaptiveform-modal'}" data-sly-unwrap></div>
<div data-sly-call="${longDescription.longDescription @componentId=modal.id, longDescription=modal.description, bemBlock='cmp-adaptiveform-modal'}" data-sly-unwrap></div>
</div>

0 comments on commit a42a065

Please sign in to comment.