Skip to content

Commit

Permalink
Allow relevance check on nested repeat whose parent doesn't currently…
Browse files Browse the repository at this point in the history
… exist (#710)
  • Loading branch information
grzesiek2010 authored Mar 13, 2023
1 parent 3f80bae commit 83c9f2b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
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

0 comments on commit 83c9f2b

Please sign in to comment.