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

Checking relevance of an inner repeat group should be possible even if its parent group does not exist yet #710

Merged
merged 2 commits into from
Mar 13, 2023
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
2 changes: 1 addition & 1 deletion src/main/java/org/javarosa/core/model/FormDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ public boolean isRepeatRelevant(TreeReference repeatRef) {
TreeReference parentPath = templNode.getParent().getRef().genericize();
TreeElement parentNode = mainInstance
.resolveReference(parentPath.contextualize(repeatRef));
relev = parentNode.isRelevant() && templNode.isRelevant();
relev = parentNode != null && parentNode.isRelevant() && templNode.isRelevant();
}

return relev;
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/org/javarosa/core/model/test/FormDefTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,34 @@ public void nestedRepeatRelevance_updatesBasedOnParentPosition() throws IOExcept
scenario.next();
assertThat(scenario.refAtIndex(), is(getRef("/data/outer[0]/inner[0]")));
}

@Test
public void innerRepeatGroupIsIrrelevant_whenItsParentRepeatGroupDoesNotExist() throws IOException, XFormParser.ParseException {
Scenario scenario = Scenario.init("Nested repeat relevance", html(
head(
title("Nested repeat relevance"),
model(
mainInstance(t("data id=\"nested-repeat-relevance\"",
t("outer",
t("inner",
t("q1")
)
)
))
)),
body(
repeat("/data/outer",
repeat("/data/outer/inner",
input("/data/outer/inner/q1")
)
)
)));


FormDef formDef = scenario.getFormDef();
// outer[1] does not exist at this moment, we only have outer[0]. Checking if its inner repeat group is relevant should be possible and return false.
assertThat(formDef.isRepeatRelevant(getRef("/data/outer[1]/inner[0]")), is(false));
}
//endregion

@Test
Expand Down