Skip to content

Commit f37527f

Browse files
arunattri26Arun Kumar Attri
andauthored
FORMS-14068: Enable rule-editor spa in core-components (#1436)
* FORMS-14068: Enable rule-editor spa in core-components * FORMS-14068: Enable rule-editor spa in core-components --------- Co-authored-by: Arun Kumar Attri <aattri@adobe.com>
1 parent 34aae8b commit f37527f

File tree

3 files changed

+91
-24
lines changed

3 files changed

+91
-24
lines changed

it/config/src/main/content/jcr_root/apps/system/config/com.adobe.granite.toggle.impl.dev.DynamicToggleProviderImpl.cfg.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"FT_FORMS-11581",
2020
"FT_FORMS-14545",
2121
"FT_SITES-19631",
22-
"FT_FORMS-14255"
22+
"FT_FORMS-14255",
23+
"FT_FORMS-14068"
2324
]
2425
}

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/clientlibs/editorhook/js/ruleeditorhook.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,34 @@
2323
* Opens the rule editor in a separate iframe for an editable
2424
* @param editable
2525
*/
26-
window.CQ.FormsCoreComponents.editorhooks.openRuleEditor = function (editable) {
27-
let existingRuleEditorFrame = document.getElementById('af-rule-editor');
28-
if (existingRuleEditorFrame) {
29-
existingRuleEditorFrame.parentNode.removeChild(existingRuleEditorFrame);
30-
}
31-
let ruleEditorFrame = document.createElement('iframe');
32-
ruleEditorFrame.setAttribute('id','af-rule-editor');
33-
let formContainerPath = getFormContainerPath(editable);
34-
if (!formContainerPath) {
35-
showAlert();
36-
} else {
37-
let ruleEditorUri = '/aem/af/expeditor.html' + getFormContainerPath(editable) + "?fieldPath=" + editable.path + "&fieldId=" + getFieldId(editable);
38-
ruleEditorFrame.setAttribute('src', ruleEditorUri);
39-
ruleEditorFrame.setAttribute('title', 'AF Rule Editor');
40-
ruleEditorFrame.style.display = "block";
41-
ruleEditorFrame.style.width = "100%";
42-
ruleEditorFrame.style.height = "100%";
43-
ruleEditorFrame.style.top = "0";
44-
ruleEditorFrame.style.left = "0";
45-
ruleEditorFrame.style.position = "fixed";
46-
ruleEditorFrame.style.zIndex = "10";
47-
document.body.appendChild(ruleEditorFrame);
26+
if (typeof window.CQ.FormsCoreComponents.editorhooks.openRuleEditor !== 'function') {
27+
window.CQ.FormsCoreComponents.editorhooks.openRuleEditor = function (editable) {
28+
let existingRuleEditorFrame = document.getElementById('af-rule-editor');
29+
if (existingRuleEditorFrame) {
30+
existingRuleEditorFrame.parentNode.removeChild(existingRuleEditorFrame);
31+
}
32+
let ruleEditorFrame = document.createElement('iframe');
33+
ruleEditorFrame.setAttribute('id', 'af-rule-editor');
34+
let formContainerPath = getFormContainerPath(editable);
35+
if (!formContainerPath) {
36+
showAlert();
37+
} else {
38+
const ruleEditorUri = '/aem/af/expeditor.html' + getFormContainerPath(editable) + "?fieldPath=" + editable.path + "&fieldId=" + getFieldId(editable);
39+
ruleEditorFrame.setAttribute('src', ruleEditorUri);
40+
ruleEditorFrame.setAttribute('title', 'AF Rule Editor');
41+
const styles = {
42+
display: "block",
43+
width: "100%",
44+
height: "100%",
45+
top: "0",
46+
left: "0",
47+
position: "fixed",
48+
zIndex: "10"
49+
};
50+
51+
Object.assign(ruleEditorFrame.style, styles);
52+
document.body.appendChild(ruleEditorFrame);
53+
}
4854
}
4955
}
5056

@@ -68,7 +74,6 @@
6874
}
6975

7076
function getFieldId(editable) {
71-
// todo: dead code, not used
7277
return editable.dom.find("[data-cmp-adaptiveformcontainer-path]").attr('id');
7378
}
7479

ui.tests/test-module/specs/ruleeditor/ruleEditor.authoring.cy.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,36 @@ describe('Rule editor authoring sanity for core-components',function(){
233233
submitFormButtonEditPath = submitFormContainerPath + "/" + afConstants.components.forms.resourceType.submitButton.split("/").pop(),
234234
submitFormButtonEditPathSelector = "[data-path='" + submitFormButtonEditPath + "']";
235235

236+
it('should open rule-editor from spa', function () {
237+
if (cy.af.isLatestAddon() && toggle_array.includes("FT_FORMS-14068")) {
238+
cy.openAuthoring(formPath);
239+
cy.selectLayer("Edit");
240+
cy.get(sitesSelectors.overlays.overlay.component + "[data-path='" + formContainerPath + "/*']").should("exist");
241+
242+
cy.insertComponent(sitesSelectors.overlays.overlay.component + "[data-path='" + formContainerPath + "/*']",
243+
"Adaptive Form Button", afConstants.components.forms.resourceType.formbutton);
244+
cy.openEditableToolbar(sitesSelectors.overlays.overlay.component + buttonEditPathSelector);
245+
246+
cy.intercept('GET', /solutions\/livecycle-ruleeditor-ui-service.*/).as('ruleEditorRequest');
247+
248+
// Edit rule option not existing on button toolbar
249+
cy.get(formsSelectors.ruleEditor.action.editRule).should("exist");
250+
cy.initializeEventHandlerOnChannel("af-rule-editor-initialized").as("isRuleEditorInitialized");
251+
cy.get(formsSelectors.ruleEditor.action.editRule).click();
252+
253+
// click on create option from rule editor header
254+
cy.get("@isRuleEditorInitialized").its('done').should('equal', true);
255+
cy.wait('@ruleEditorRequest').its('response.statusCode').should('equal', 200);
256+
cy.getRuleEditorIframe().find(formsSelectors.ruleEditor.action.closeRuleEditor).should("exist");
257+
cy.getRuleEditorIframe().find(formsSelectors.ruleEditor.action.closeRuleEditor).click();
258+
259+
cy.get(sitesSelectors.overlays.overlay.component + buttonEditPathSelector).should("exist");
260+
261+
cy.selectLayer("Edit");
262+
cy.deleteComponentByPath(buttonEditPath);
263+
}
264+
})
265+
236266
/**
237267
* RuleSanity for button to change label of textbox
238268
* [To add rule on button item so that when it get clicked
@@ -360,6 +390,37 @@ describe('Rule editor authoring sanity for core-components',function(){
360390
buttonEditPath = formContainerPath + "/" + afConstants.components.forms.resourceType.formbutton.split("/").pop(),
361391
buttonEditPathSelector = "[data-path='" + buttonEditPath + "']";
362392

393+
it('should open rule-editor from spa', function () {
394+
if (cy.af.isLatestAddon() && toggle_array.includes("FT_FORMS-14068")) {
395+
cy.openAuthoring(pagePath);
396+
cy.selectLayer("Edit");
397+
cy.get(sitesSelectors.overlays.overlay.component + "[data-path='" + formContainerPath + "/*']").should("exist");
398+
399+
cy.insertComponent(sitesSelectors.overlays.overlay.component + "[data-path='" + formContainerPath + "/*']",
400+
"Adaptive Form Button", afConstants.components.forms.resourceType.formbutton);
401+
cy.openEditableToolbar(sitesSelectors.overlays.overlay.component + buttonEditPathSelector);
402+
403+
cy.intercept('GET', /solutions\/livecycle-ruleeditor-ui-service.*/).as('ruleEditorRequest');
404+
405+
// Edit rule option not existing on button toolbar
406+
cy.get(formsSelectors.ruleEditor.action.editRule).should("exist");
407+
cy.initializeEventHandlerOnChannel("af-rule-editor-initialized").as("isRuleEditorInitialized");
408+
cy.get(formsSelectors.ruleEditor.action.editRule).click();
409+
410+
// click on create option from rule editor header
411+
cy.get("@isRuleEditorInitialized").its('done').should('equal', true);
412+
cy.wait('@ruleEditorRequest').its('response.statusCode').should('equal', 200);
413+
414+
cy.getRuleEditorIframe().find(formsSelectors.ruleEditor.action.closeRuleEditor).should("exist");
415+
cy.getRuleEditorIframe().find(formsSelectors.ruleEditor.action.closeRuleEditor).click();
416+
417+
cy.get(sitesSelectors.overlays.overlay.component + buttonEditPathSelector).should("exist");
418+
419+
cy.selectLayer("Edit");
420+
cy.deleteComponentByPath(buttonEditPath);
421+
}
422+
})
423+
363424
/**
364425
* RuleSanity for button to change label of textbox
365426
* [To add rule on button item so that when it get clicked

0 commit comments

Comments
 (0)