From 83c9f2b529e896c5079d3af63d30a4f722fe0259 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Mon, 13 Mar 2023 22:16:50 +0100 Subject: [PATCH] Allow relevance check on nested repeat whose parent doesn't currently exist (#710) --- .../java/org/javarosa/core/model/FormDef.java | 2 +- .../javarosa/core/model/test/FormDefTest.java | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/javarosa/core/model/FormDef.java b/src/main/java/org/javarosa/core/model/FormDef.java index b060b1904..e9832ab0f 100644 --- a/src/main/java/org/javarosa/core/model/FormDef.java +++ b/src/main/java/org/javarosa/core/model/FormDef.java @@ -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; diff --git a/src/test/java/org/javarosa/core/model/test/FormDefTest.java b/src/test/java/org/javarosa/core/model/test/FormDefTest.java index 36ba11c26..69930e0e4 100644 --- a/src/test/java/org/javarosa/core/model/test/FormDefTest.java +++ b/src/test/java/org/javarosa/core/model/test/FormDefTest.java @@ -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