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

Add test of relevance on calculates #704

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
27 changes: 27 additions & 0 deletions src/test/java/org/javarosa/core/model/TriggerableDagTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,33 @@ public void non_relevant_node_values_are_always_null_regardless_of_their_actual_
assertThat(scenario.answerOf("/data/some-field"), is(intAnswer(42)));
}

// Users use relevance on calculates to ensure that calculations are only run when the values
Copy link
Member

Choose a reason for hiding this comment

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

Is it important to make sure that the calculation isn't executed or just that the calculation isn't "answered"? I'm guessing it's the latter (as that's what this test is about), but the comment suggests it might the former.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great and deep question. Now I'm no longer 100% sure of the intent. This led me to some strange docs: getodk/docs#1547 I will come back to it.

// they need are populated. Using relevance is easier than adding a condition.
@Test
public void relevance_appliesToElementsWithoutControls() throws IOException, XFormParser.ParseException {
Scenario scenario = Scenario.init("Relevance on calculate", html(
head(
title("Relevance on calculate"),
model(
mainInstance(t("data id=\"relevance-calculate\"",
t("q1"),
t("c1"),
t("c2")
)),
bind("/data/q1").type("string"),
bind("/data/c1").calculate("2 * 2").relevant("/data/q1 = 'yes'"),
bind("/data/c2").calculate("/data/c1")
)),
body(
input("/data/q1")
)));

assertThat(scenario.answerOf("/data/c2"), is(nullValue()));

scenario.answer("/data/q1", "yes");
assertThat(scenario.answerOf("/data/c2"), is(intAnswer(4)));
}

/**
* This test was inspired by the issue reported at https://code.google.com/archive/p/opendatakit/issues/888
* <p>
Expand Down