Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FORMS-16911 Prefill of static text with explicit data bindings #1443

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ public class TextImpl extends AbstractFormComponentImpl implements Text {
@SlingObject
private Resource resource;

@Override
protected void initBaseModel() {
// Always make dataRef of Text component as null, for this we need to make unboundFormElement as true
unboundFormElement = Boolean.TRUE;
super.initBaseModel();
}

@Override
public String getValue() {
return translate("value", value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void testIsRichText() {
@Test
void testGetDataRef() {
Text text = Utils.getComponentUnderTest(PATH_TEXT_CUSTOMIZED, Text.class, context);
assertEquals("null", text.getDataRef());
assertEquals("a.b", text.getDataRef());
Text textMock = Mockito.mock(Text.class);
Mockito.when(textMock.getDataRef()).thenCallRealMethod();
assertEquals(null, textMock.getDataRef());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"name": "consenttext",
"value": "Text related to the terms and conditions come here",
"richText": false,
"dataRef": null,
"events": {
"custom:setProperty": [
"$event.payload"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "text-bb9fec86e7",
"dataRef": null,
"dataRef": "a.b",
"fieldType": "plain-text",
"name": "abc",
"value": "<p>xyz</p>",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"id": "text-cfbea91bba",
"fieldType": "plain-text",
"dataRef": null,
"name": "text1680491190398",
"value": "This is an AF",
"richText": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"id": "text-ac0bcff4f3",
"fieldType": "plain-text",
"dataRef": null,
"richText": false,
"name": "abc",
":type": "core/fd/components/form/text/v1/text",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ function testImportData(globals)
globals.functions.importData(Object.fromEntries([['textinput_12605243111716188337417','abc']]));
}

/**
* Tests static text import data
* @name testTextImportData
* @param {scope} globals
*/
function testTextImportData(globals)
{
globals.functions.importData({'a' : {'b' : 'prefilled'}});
}

/**
* Tests set focus
* @name testSetFocus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
fd:version="2.1"
jcr:primaryType="nt:unstructured"
sling:resourceType="forms-components-examples/components/form/container"
clientLibRef="corecomponent.it.customfunction"
schemaType="none"
specVersion="0.14.2"
fieldType="form">
<textinput
jcr:primaryType="nt:unstructured"
Expand Down Expand Up @@ -71,6 +74,47 @@
jcr:primaryType="nt:unstructured"
click="[dispatchEvent('reset')]"/>
</reset>
<text_327821969
jcr:created="{Date}2024-10-16T11:14:16.467+05:30"
jcr:createdBy="admin"
jcr:lastModified="{Date}2024-10-16T11:34:33.938+05:30"
jcr:lastModifiedBy="admin"
jcr:primaryType="nt:unstructured"
jcr:title="Text"
sling:resourceType="forms-components-examples/components/form/text"
dataRef="$.a.b"
fieldType="plain-text"
name="prefilltext"
textIsRich="true"
unboundFormElement="{Boolean}false"
value="&lt;p>prefill test&lt;/p>&#xd;&#xa;"
visible="{Boolean}true">
<fd:rules jcr:primaryType="nt:unstructured"/>
<fd:events jcr:primaryType="nt:unstructured"/>
</text_327821969>
<button
jcr:created="{Date}2024-10-16T11:15:30.148+05:30"
jcr:createdBy="admin"
jcr:lastModified="{Date}2024-10-16T11:15:43.398+05:30"
jcr:lastModifiedBy="admin"
jcr:primaryType="nt:unstructured"
jcr:title="click to prefill static text"
sling:resourceType="forms-components-examples/components/form/button"
dorExclusion="true"
enabled="{Boolean}true"
fieldType="button"
name="button1729057530205"
textIsRich="[true,true,true]"
unboundFormElement="{Boolean}false"
visible="{Boolean}true">
<fd:rules
fd:click="[{&quot;nodeName&quot;:&quot;ROOT&quot;\,&quot;items&quot;:[{&quot;nodeName&quot;:&quot;STATEMENT&quot;\,&quot;choice&quot;:{&quot;nodeName&quot;:&quot;EVENT_SCRIPTS&quot;\,&quot;items&quot;:[{&quot;nodeName&quot;:&quot;EVENT_CONDITION&quot;\,&quot;choice&quot;:{&quot;nodeName&quot;:&quot;EVENT_AND_COMPARISON&quot;\,&quot;items&quot;:[{&quot;nodeName&quot;:&quot;COMPONENT&quot;\,&quot;value&quot;:{&quot;id&quot;:&quot;$form.button1729057530205&quot;\,&quot;type&quot;:&quot;BUTTON&quot;\,&quot;name&quot;:&quot;button1729057530205&quot;}}\,{&quot;nodeName&quot;:&quot;EVENT_AND_COMPARISON_OPERATOR&quot;\,&quot;choice&quot;:{&quot;nodeName&quot;:&quot;is clicked&quot;\,&quot;value&quot;:null}}\,{&quot;nodeName&quot;:&quot;PRIMITIVE_EXPRESSION&quot;\,&quot;choice&quot;:null}]}\,&quot;nested&quot;:false}\,{&quot;nodeName&quot;:&quot;Then&quot;\,&quot;value&quot;:null}\,{&quot;nodeName&quot;:&quot;BLOCK_STATEMENTS&quot;\,&quot;items&quot;:[{&quot;nodeName&quot;:&quot;BLOCK_STATEMENT&quot;\,&quot;choice&quot;:{&quot;nodeName&quot;:&quot;FUNCTION_CALL&quot;\,&quot;parentNodeName&quot;:&quot;BLOCK_STATEMENT&quot;\,&quot;functionName&quot;:{&quot;id&quot;:&quot;testTextImportData&quot;\,&quot;displayName&quot;:&quot;testTextImportData&quot;\,&quot;type&quot;:&quot;STRING|NUMBER|BOOLEAN|DATE|ARRAY|OBJECT&quot;\,&quot;isDuplicate&quot;:false\,&quot;displayPath&quot;:&quot;&quot;\,&quot;args&quot;:[]\,&quot;impl&quot;:&quot;$0()&quot;}\,&quot;params&quot;:[]}}]}]}}]\,&quot;isValid&quot;:true\,&quot;enabled&quot;:true\,&quot;version&quot;:1\,&quot;script&quot;:[&quot;testTextImportData()&quot;]\,&quot;eventName&quot;:&quot;Click&quot;\,&quot;ruleType&quot;:&quot;&quot;\,&quot;description&quot;:&quot;&quot;}]"
jcr:primaryType="nt:unstructured"
validationStatus="valid"/>
<fd:events
jcr:primaryType="nt:unstructured"
click="[testTextImportData()]"/>
</button>
</guideContainer>
</jcr:content>
</jcr:root>
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@
<hideTitle
jcr:primaryType="nt:unstructured"
sling:hideResource="{Boolean}true"/>
<bindref
jcr:primaryType="nt:unstructured"
sling:hideResource="{Boolean}true"/>
<enabled
jcr:primaryType="nt:unstructured"
sling:hideResource="{Boolean}true"/>
Expand All @@ -71,9 +68,6 @@
<dorBindref
jcr:primaryType="nt:unstructured"
sling:hideResource="{Boolean}true"/>
<unboundFormElement
jcr:primaryType="nt:unstructured"
sling:hideResource="{Boolean}true" />
<readonly
jcr:primaryType="nt:unstructured"
sling:hideResource="{Boolean}true" />
Expand Down
6 changes: 2 additions & 4 deletions ui.tests/test-module/specs/text/text.authoring.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,11 @@ describe('Page - Authoring', function () {
cy.get("[name='./name']")
.should("exist");
cy.get("[name='./dataRef']")
.should("not.exist");
.should("exist");
cy.get("[name='./readOnly']")
.should("not.exist");
cy.get("[name='./unboundFormElement']")
.should("not.exist");
cy.get("[name='./dorBindRef']")
.should("not.exist");
.should("exist");
cy.get('.cmp-adaptiveform-base__istitlerichtext').should('not.exist');

cy.get("[name='./visible'][type=\"checkbox\"]").should("exist").check();
Expand Down
16 changes: 13 additions & 3 deletions ui.tests/test-module/specs/text/text.runtime.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

})

it(" should get model and view initialized properly ", () => {
it(" should get model and view initialized properly ", () => {
expect(formContainer, "formcontainer is initialized").to.not.be.null;
expect(formContainer._model.items.length, "model and view elements match").to.equal(Object.keys(formContainer._fields).length);
Object.entries(formContainer._fields).forEach(([id, field]) => {
Expand All @@ -65,7 +65,7 @@
});
})

it(" html changes are reflected in model ", () => {
it(" html changes are reflected in model ", () => {
const [id, fieldView] = Object.entries(formContainer._fields)[0]
const model = formContainer._model.getElement(id)
const input = "value"
Expand All @@ -74,7 +74,7 @@
})
});

it('test the rules editor', () => {
it('test the rules editor', () => {
const [id, fieldView] = Object.entries(formContainer._fields)[1];
cy.get('.cmp-adaptiveform-textinput__widget')
.type('Hide me');
Expand Down Expand Up @@ -105,4 +105,14 @@
});
});

it(" prefill of static text using explicit dataRef, name bindings is not supported", () => {
const [id, fieldView] = Object.entries(formContainer._fields)[3];
const [buttonId, buttonFieldView] = Object.entries(formContainer._fields)[5];
const model = formContainer._model.getElement(id);
cy.get(`#${buttonId} button`).should("be.visible").click().then(() => {
expect(model.value, " Text model should import data").contains("prefilled");
cy.get(`#${id}`).contains("prefilled");
});
});

})
Loading