Skip to content

Commit 93f8f2a

Browse files
arunattri26Arun Kumar Attri
andauthored
FORMS-21841: fix rule-editor tests and update custom function extract… (#1718)
* FORMS-21841: fix rule-editor tests and update custom function extraction from rules at runtime * FORMS-21841: fix rule-editor tests and update custom function extraction from rules at runtime * FORMS-21841: fix rule-editor tests and update custom function extraction from rules at runtime --------- Co-authored-by: Arun Kumar Attri <aattri@adobe.com>
1 parent 7b7ac82 commit 93f8f2a

File tree

8 files changed

+104
-35
lines changed

8 files changed

+104
-35
lines changed

it/apps/src/main/content/jcr_root/apps/forms-core-components-it/clientlibs/clientlib-it-custom-function/js/functions.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,22 @@ function formatEmailInput(field)
137137
return transformedEmail;
138138
}
139139

140+
/**
141+
* Validates email input
142+
* @name validateEmailInput Validates email input
143+
* @param {object} field field whose value to be validated
144+
* @return {string}
145+
*/
146+
function validateEmailInput(field)
147+
{
148+
var email = field.$value;
149+
if (!email) {
150+
return "false";
151+
}
152+
// Simple email regex pattern
153+
var pattern = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
154+
return pattern.test(email) ? "true" : "false";
155+
}
140156

141157
/**
142158
* Formats telephone input

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
"FT_FORMS-14068",
2424
"FT_FORMS-16351",
2525
"FT_FORMS-14518",
26-
"FT_FORMS-13519"
26+
"FT_FORMS-13519",
27+
"FT_FORMS-17107"
2728
],
2829
"disabledToggles": [
29-
"FT_FORMS-17107"
3030
]
3131
}

it/content/src/main/content/jcr_root/content/forms/af/core-components-it/samples/emailinput/basic/.content.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
sling:resourceType="forms-components-examples/components/form/emailinput"
7070
autocomplete="email"
7171
displayValueExpression="formatEmailInput($field)"
72+
validationExpression="validateEmailInput($field) == 'true'"
7273
enabled="{Boolean}true"
7374
fieldType="email"
7475
hideTitle="false"
@@ -80,6 +81,7 @@
8081
visible="{Boolean}true">
8182
<fd:rules
8283
fd:format="[{&quot;nodeName&quot;:&quot;ROOT&quot;\,&quot;items&quot;:[{&quot;nodeName&quot;:&quot;STATEMENT&quot;\,&quot;choice&quot;:{&quot;nodeName&quot;:&quot;FORMAT_EXPRESSION&quot;\,&quot;items&quot;:[{&quot;nodeName&quot;:&quot;VALUE_FIELD&quot;\,&quot;value&quot;:{&quot;id&quot;:&quot;$form.emailinput4&quot;\,&quot;type&quot;:&quot;STRING&quot;\,&quot;name&quot;:&quot;emailinput4&quot;}}\,{&quot;nodeName&quot;:&quot;Using&quot;\,&quot;value&quot;:null}\,{&quot;nodeName&quot;:&quot;Expression&quot;\,&quot;value&quot;:null}\,{&quot;nodeName&quot;:&quot;NUMBER_FORMAT_EXPRESSION&quot;\,&quot;choice&quot;:{&quot;nodeName&quot;:&quot;FUNCTION_CALL&quot;\,&quot;parentNodeName&quot;:&quot;NUMBER_FORMAT_EXPRESSION&quot;\,&quot;functionName&quot;:{&quot;id&quot;:&quot;formatEmailInput&quot;\,&quot;displayName&quot;:&quot;Formats email input&quot;\,&quot;type&quot;:&quot;STRING&quot;\,&quot;isDuplicate&quot;:false\,&quot;displayPath&quot;:&quot;&quot;\,&quot;args&quot;:[{&quot;type&quot;:&quot;OBJECT|AFCOMPONENT&quot;\,&quot;name&quot;:&quot;field&quot;\,&quot;description&quot;:&quot;field whose value to be formatted&quot;}]\,&quot;impl&quot;:&quot;$0($1)&quot;}\,&quot;params&quot;:[{&quot;nodeName&quot;:&quot;EXPRESSION&quot;\,&quot;choice&quot;:{&quot;nodeName&quot;:&quot;COMPONENT&quot;\,&quot;value&quot;:{&quot;id&quot;:&quot;$form.emailinput4&quot;\,&quot;displayName&quot;:&quot;Email Input 4&quot;\,&quot;type&quot;:&quot;AFCOMPONENT&quot;\,&quot;displayPath&quot;:&quot;FORM/Email Input 4/&quot;\,&quot;name&quot;:&quot;emailinput4&quot;\,&quot;parent&quot;:&quot;$form&quot;}}}]}}]}}]\,&quot;isValid&quot;:true\,&quot;enabled&quot;:true\,&quot;version&quot;:1\,&quot;script&quot;:&quot;formatEmailInput($field)&quot;\,&quot;eventName&quot;:&quot;Format&quot;\,&quot;ruleType&quot;:&quot;&quot;\,&quot;description&quot;:&quot;&quot;}]"
84+
fd:validate="[{&quot;nodeName&quot;:&quot;ROOT&quot;\,&quot;items&quot;:[{&quot;nodeName&quot;:&quot;STATEMENT&quot;\,&quot;choice&quot;:{&quot;nodeName&quot;:&quot;VALIDATE_EXPRESSION&quot;\,&quot;items&quot;:[{&quot;nodeName&quot;:&quot;AFCOMPONENT&quot;\,&quot;value&quot;:{&quot;id&quot;:&quot;$form.emailinput4&quot;\,&quot;type&quot;:&quot;AFCOMPONENT&quot;\,&quot;name&quot;:&quot;emailinput4&quot;}}\,{&quot;nodeName&quot;:&quot;Using&quot;\,&quot;value&quot;:null}\,{&quot;nodeName&quot;:&quot;Expression&quot;\,&quot;value&quot;:null}\,{&quot;nodeName&quot;:&quot;CONDITION&quot;\,&quot;choice&quot;:{&quot;nodeName&quot;:&quot;COMPARISON_EXPRESSION&quot;\,&quot;items&quot;:[{&quot;nodeName&quot;:&quot;EXPRESSION&quot;\,&quot;choice&quot;:{&quot;nodeName&quot;:&quot;COMPONENT&quot;\,&quot;value&quot;:{&quot;id&quot;:&quot;$form.emailinput4&quot;\,&quot;displayName&quot;:&quot;Email Input 4&quot;\,&quot;type&quot;:&quot;AFCOMPONENT&quot;\,&quot;displayPath&quot;:&quot;FORM/Email Input 4/&quot;\,&quot;name&quot;:&quot;emailinput4&quot;\,&quot;parent&quot;:&quot;$form&quot;}}}\,{&quot;nodeName&quot;:&quot;OPERATOR&quot;\,&quot;choice&quot;:{&quot;nodeName&quot;:&quot;EQUALS_TO&quot;\,&quot;value&quot;:null}}\,{&quot;nodeName&quot;:&quot;EXPRESSION&quot;\,&quot;choice&quot;:{&quot;nodeName&quot;:&quot;STRING_LITERAL&quot;\,&quot;value&quot;:&quot;true&quot;}}]}\,&quot;nested&quot;:false}]}}]\,&quot;isValid&quot;:true\,&quot;enabled&quot;:true\,&quot;version&quot;:1\,&quot;script&quot;:&quot;validateEmailInput($field) == 'true'&quot;\,&quot;eventName&quot;:&quot;Validate&quot;\,&quot;ruleType&quot;:&quot;&quot;\,&quot;description&quot;:&quot;&quot;}]"
8385
jcr:primaryType="nt:unstructured"
8486
validationStatus="valid"/>
8587
<fd:events jcr:primaryType="nt:unstructured"/>

ui.frontend/src/RuleUtils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ class RuleUtils {
116116
if (!items) return;
117117

118118
Object.values(items).forEach(item => {
119+
120+
if (item.validationExpression) {
121+
extractFunctionNamesFromRuleExpression(item.validationExpression);
122+
}
123+
if (item.displayValueExpression) {
124+
extractFunctionNamesFromRuleExpression(item.displayValueExpression);
125+
}
126+
119127
if (item.events) {
120128
Object.values(item.events).forEach(eventArray => {
121129
eventArray.forEach(eventString => {

ui.tests/test-module/libs/commons/guideSelectors.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ var selectors = {
201201
IS_CLICKED : "coral-selectlist [value='is clicked']",
202202
IS_SUBMITTED_SUCCESSFULLY : "coral-selectlist [value='is submitted successfully']",
203203
SUBMISSION_FAILS : "coral-selectlist [value='submission fails']",
204-
NAVIGATE_TO : "coral-selectlist [value='NAVIGATE_TO']"
204+
NAVIGATE_TO : "coral-selectlist [value='NAVIGATE_TO']",
205+
NAVIGATE_IN_PANEL : "coral-selectlist [value='NAVIGATE_IN_PANEL']"
205206
}
206207
}
207208
};

ui.tests/test-module/specs/numberinput/numberinput.runtime.cy.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ describe("Form with Number Input", () => {
6767
});
6868
})
6969

70-
// @arun to uncomment this
71-
it.skip(" model's changes are reflected in the html ", () => {
70+
it(" model's changes are reflected in the html ", () => {
7271
Object.entries(formContainer._fields).forEach(([id, field]) => {
7372
let model = field.getModel();
7473
model.value = 24

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ const commons = require('../../../libs/commons/commons'),
33
formsSelectors = require('../../../libs/commons/guideSelectors'),
44
afConstants = require('../../../libs/commons/formsConstants');
55

6-
// @arun to uncomment this soon
7-
describe.skip('Rule editor navigate-in-panel rule authoring',function(){
6+
describe('Rule editor navigate-in-panel rule authoring',function(){
87
let toggle_array = [];
98

109
before(() => {
@@ -93,6 +92,14 @@ describe.skip('Rule editor navigate-in-panel rule authoring',function(){
9392
cy.getRuleEditorIframe().find(formsSelectors.ruleEditor.operator.IS_CLICKED).should("exist");
9493
cy.getRuleEditorIframe().find(formsSelectors.ruleEditor.operator.IS_CLICKED).click();
9594

95+
// delete else block if present
96+
cy.getRuleEditorIframe().then($iframe => {
97+
const $button = $iframe.find(".else-section-button > .delete-else-button");
98+
if ($button.length) {
99+
cy.wrap($button).click();
100+
}
101+
});
102+
96103
// check and click on dropdown to view the actions available
97104
cy.getRuleEditorIframe().find(formsSelectors.ruleEditor.choiceModels.BLOCK_STATEMENT + " .choice-view-default").should("exist");
98105
cy.getRuleEditorIframe().find(formsSelectors.ruleEditor.choiceModels.BLOCK_STATEMENT + " .choice-view-default").click({multiple: true, force: true});

0 commit comments

Comments
 (0)