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

Use raw values, not display text, for Entity property values #6514

Merged
merged 3 commits into from
Nov 19, 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 @@ -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")
Copy link
Member Author

@grzesiek2010 grzesiek2010 Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a problem with saving dates as labels. I fixed it here: https://github.com/getodk/collect/pull/6514/files#diff-dcf4e4fc03ff048616e3d821f4dc1ff53ea090480626d6516d0ac054b35c1446R35 but the problem is that such an element is identified as DateTime data type not just Date. It seems to be a bug in javarosa so I'm going to file an issue there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is here: getodk/javarosa#807

.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>