Skip to content

Commit

Permalink
Merge pull request #6103 from grzesiek2010/COLLECT-5941
Browse files Browse the repository at this point in the history
Support updating dynamic required questions in field-list
  • Loading branch information
seadowg authored May 21, 2024
2 parents 340b977 + bc38868 commit 2a7ae92
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,22 @@ public void recordingAudio_ShouldChangeRelevanceOfRelatedField() {
.assertTextDoesNotExist("Target16");
}

@Test
public void changeInValueUsedToDetermineIfAQuestionIsRequired_ShouldUpdateTheRelatedRequiredQuestion() {
new FormEntryPage("fieldlist-updates")
.clickGoToArrow()
.clickGoUpIcon()
.clickOnGroup("Dynamic required question")
.clickOnQuestion("Source17")
.assertQuestion("Target17")
.answerQuestion(0, "blah")
.assertQuestion("Target17", true)
.swipeToNextQuestionWithConstraintViolation(org.odk.collect.strings.R.string.required_answer_error)
.answerQuestion(0, "")
.assertQuestion("Target17")
.assertTextDoesNotExist(org.odk.collect.strings.R.string.required_answer_error);
}

// Scroll down until the desired group name is visible. This is needed to make the tests work
// on devices with screens of different heights.
private void jumpToGroupWithText(String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ public ErrorDialog swipeToNextQuestionWithError() {
return new ErrorDialog().assertOnPage();
}

public FormEntryPage swipeToNextQuestionWithConstraintViolation(int constraintText) {
flingLeft();
assertText(constraintText);

return this;
}

public FormEntryPage swipeToNextQuestionWithConstraintViolation(String constraintText) {
flingLeft();
assertText(constraintText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public class ImmutableDisplayableQuestion {
*/
private final boolean isReadOnly;

/**
* Whether the question is required.
*/
private final boolean isRequired;

/**
* The choices displayed to a user if this question is of a type that has choices.
*/
Expand All @@ -78,6 +83,7 @@ public ImmutableDisplayableQuestion(FormEntryPrompt question) {
guidanceText = question.getSpecialFormQuestionText(question.getQuestion().getHelpTextID(), "guidance");
answerText = question.getAnswerText();
isReadOnly = question.isReadOnly();
isRequired = question.isRequired();

List<SelectChoice> choices = question.getSelectChoices();
if (choices != null) {
Expand Down Expand Up @@ -106,7 +112,8 @@ public boolean sameAs(FormEntryPrompt question) {
&& (getGuidanceHintText(question) == null ? guidanceText == null : getGuidanceHintText(question).equals(guidanceText))
&& (question.getAnswerText() == null ? answerText == null : question.getAnswerText().equals(answerText))
&& (question.isReadOnly() == isReadOnly)
&& selectChoiceListsEqual(question.getSelectChoices(), selectChoices);
&& selectChoiceListsEqual(question.getSelectChoices(), selectChoices)
&& question.isRequired() == isRequired;
}

private static boolean selectChoiceListsEqual(List<SelectChoice> selectChoiceList1, List<SelectChoice> selectChoiceList2) {
Expand Down
15 changes: 15 additions & 0 deletions test-forms/src/main/resources/forms/fieldlist-updates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@
<source16/>
<target16/>
</audio>
<required>
<source17/>
<target17/>
</required>
<meta>
<instanceID/>
</meta>
Expand Down Expand Up @@ -372,6 +376,8 @@
<bind nodeset="/fieldlist-updates/long_list_of_questions/question20" type="integer"/>
<bind nodeset="/fieldlist-updates/audio/source16" type="binary"/>
<bind nodeset="/fieldlist-updates/audio/target16" relevant=" /fieldlist-updates/audio/source16 != ''" type="string"/>
<bind nodeset="/fieldlist-updates/required/source17" type="binary"/>
<bind nodeset="/fieldlist-updates/required/target17" required=" /fieldlist-updates/required/source17 != ''" type="string"/>
<bind calculate="concat('uuid:', uuid())" nodeset="/fieldlist-updates/meta/instanceID" readonly="true()" type="string"/>
</model>
</h:head>
Expand Down Expand Up @@ -729,5 +735,14 @@
<label>Target16</label>
</input>
</group>
<group appearance="field-list" ref="/fieldlist-updates/required">
<label>Dynamic required question</label>
<input ref="/fieldlist-updates/required/source17">
<label>Source17</label>
</input>
<input ref="/fieldlist-updates/required/target17">
<label>Target17</label>
</input>
</group>
</h:body>
</h:html>

0 comments on commit 2a7ae92

Please sign in to comment.