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

Duplicate of commcare_2.54 #1450

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 1 addition & 3 deletions src/main/java/org/commcare/session/CommCareSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,6 @@ public EvaluationContext getEvaluationContext(InstanceInitializationFactory iif,
Vector<Entry> entries = getEntriesForCommand(command);
Vector<Menu> menus = getMenusForCommand(command);

Menu menu = null;
Entry entry = null;
Hashtable<String, DataInstance> instancesInScope = new Hashtable<>();
Hashtable<String, DataInstance> menuInstances = null;
Expand All @@ -649,8 +648,7 @@ public EvaluationContext getEvaluationContext(InstanceInitializationFactory iif,
}
}

if (!menus.isEmpty()) {
menu = menus.elementAt(0);
for (Menu menu : menus) {
if (menu != null) {
menuInstances = menu.getInstances(instancesToInclude);
}
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/org/commcare/backend/session/test/MenuTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.commcare.modern.session.SessionWrapper;
import org.commcare.session.CommCareSession;
import org.commcare.suite.model.AssertionSet;
import org.commcare.suite.model.Menu;
import org.commcare.suite.model.Suite;
Expand All @@ -12,6 +15,8 @@
import org.junit.Before;
import org.junit.Test;

import java.util.List;

/**
* Tests for assertions in menus
*/
Expand All @@ -36,4 +41,18 @@ public void testAssertionsEvaluated() throws Exception {
assertNotNull(assertions);
assertEquals("custom_assertion.m0.0", assertionFailures.getArgument());
}

/**
* When there are multiple menu blocks with same ids, we should accumulate the required instances from all
* of the menus and their contained entries
*/
@Test
public void testMenuInstances_WhenMenuHaveSameIds() {
SessionWrapper currentSession = appWithMenuAssertions.getSession();
EvaluationContext ec = currentSession.getEvaluationContext(currentSession.getIIF(), "m3", null);
List<String> instanceIds = ec.getInstanceIds();
assertEquals(2, instanceIds.size());
assertTrue(instanceIds.contains("my_instance"));
assertTrue(instanceIds.contains("casedb"));
}
}
3 changes: 2 additions & 1 deletion src/test/resources/app_structure/suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,10 @@
<text>Menu</text>
<command id="m0-f0"/>
</menu>
<menu id="m3">
<menu id="m3" relevant="count(instance('my_instance'))>0">
<text>Menu</text>
<command id="m0-f1"/>
<instance id="my_instance" src="my_instance_source"/>
</menu>
<endpoint id="case_list" respect-relevancy="false">
<argument id="selected_cases" instance-id="selected_cases" instance-src="jr://instance/selected-entities"/>
Expand Down
Loading