Skip to content

Commit

Permalink
Merge pull request #6514 from grzesiek2010/COLLECT-6510
Browse files Browse the repository at this point in the history
Do not format entity values that are build using XPath expressions
  • Loading branch information
seadowg authored Nov 19, 2024
2 parents 3975458 + 9af6c26 commit bae5116
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ class EntityFormTest {
val ruleChain: RuleChain = TestRuleChain.chain(testDependencies)
.around(rule)

@Test
fun fillingEntityRegistrationForm_createsEntityWithValuesTreatedAsOpaqueStrings() {
testDependencies.server.addForm("entities-with-dates-registration.xml")
testDependencies.server.addForm("entities-with-dates-follow-up.xml")

rule.withMatchExactlyProject(testDependencies.server.url)
.startBlankForm("Entities With Dates Registration")
.swipeToEndScreen()
.clickFinalize()

.startBlankForm("Entities With Dates Follow Up")
// .assertText("2024-11-15")
.swipeToNextQuestion("Select date")
.assertText("2024-11-15")
}

@Test
fun fillingEntityRegistrationForm_createsEntityForFollowUpForms() {
testDependencies.server.addForm("one-question-entity-registration.xml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private FormEntity createEntity(TreeElement entityElement, String dataset, List<
IAnswerData answerData = mainInstance.resolveReference(reference).getValue();

if (answerData != null) {
return new Pair<>(saveTo.getSecond(), answerData.getDisplayText());
return new Pair<>(saveTo.getSecond(), answerData.uncast().getString());
} else {
return new Pair<>(saveTo.getSecond(), "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static String parseLabel(TreeElement entity) {
IAnswerData labelValue = labelElement.getValue();

if (labelValue != null) {
return String.valueOf(labelValue.getValue());
return labelValue.uncast().getString();
} else {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:jr="http://openrosa.org/javarosa" xmlns:odk="http://www.opendatakit.org/xforms" xmlns:orx="http://openrosa.org/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:entities="http://www.opendatakit.org/xforms/entities">
<h:head>
<h:title>Entities With Dates Follow Up</h:title>
<model odk:xforms-version="1.0.0" entities:entities-version="2024.1.0">
<instance>
<data id="entities-with-dates-follow_up" version="1">
<label/>
<date/>
<meta>
<instanceID/>
</meta>
</data>
</instance>

<instance id="dates" src="jr://file-csv/dates.csv"/>

<bind nodeset="/data/label" type="string"/>
<bind nodeset="/data/date" type="string"/>
<bind jr:preload="uid" nodeset="/data/meta/instanceID" readonly="true()" type="string"/>
</model>
</h:head>
<h:body>
<select1 ref="/data/label">
<label>Select label</label>
<itemset nodeset="instance('dates')/root/item">
<value ref="name"/>
<label ref="label"/>
</itemset>
</select1>
<select1 ref="/data/date">
<label>Select date</label>
<itemset nodeset="instance('dates')/root/item">
<value ref="name"/>
<label ref="date"/>
</itemset>
</select1>
</h:body>
</h:html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0"?>
<h:html
xmlns="http://www.w3.org/2002/xforms"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jr="http://openrosa.org/javarosa"
xmlns:orx="http://openrosa.org/xforms"
xmlns:odk="http://www.opendatakit.org/xforms"
xmlns:entities="http://www.opendatakit.org/xforms/entities">
<h:head>
<h:title>Entities With Dates Registration</h:title>
<model odk:xforms-version="1.0.0" entities:entities-version="2024.1.0">
<itext>
<translation lang="English">
<text id="/data/date:label">
<value>Select date</value>
</text>
</translation>
</itext>
<instance>
<data id="entities-with-dates-registration">
<date>2024-11-15</date>
<meta>
<instanceID/>
<entity dataset="dates" id="" create="1">
<label/>
</entity>
</meta>
</data>
</instance>
<bind nodeset="/data/date" type="date" entities:saveto="date"/>
<bind nodeset="/data/meta/instanceID" type="string" readonly="true()" jr:preload="uid"/>
<bind nodeset="/data/meta/entity/@id" type="string" readonly="true()"/>
<setvalue ref="/data/meta/entity/@id" event="odk-instance-first-load" type="string" readonly="true()" value="uuid()"/>
<bind nodeset="/data/meta/entity/label" calculate=" /data/date " type="string" readonly="true()"/>
</model>
</h:head>
<h:body>
<input ref="/data/date">
<label ref="jr:itext('/data/date:label')"/>
</input>
</h:body>
</h:html>

0 comments on commit bae5116

Please sign in to comment.