Skip to content

Commit

Permalink
Merge pull request #1642 from dimagi/revert-1638-persistentMenuAutoSe…
Browse files Browse the repository at this point in the history
…lectFix

Revert persistent menu auto select bug fix and related tests
  • Loading branch information
minhaminha authored Nov 14, 2024
2 parents 9db10a8 + 6663cb0 commit 8d7841c
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,9 @@ public Screen rebuildSessionFromFrame(MenuSession menuSession, CaseSearchHelper
}

if (currentStep != null && currentStep != NEXT_SCREEN && entityScreen.shouldBeSkipped()) {
if (((EntityScreen)screen).autoSelectEntities(menuSession.getSessionWrapper())) {
screen = menuSession.getNextScreen(needsFullInit, entityScreenContext);
continue;
}
menuSession.handleInput(screen, currentStep, needsFullInit, true, false, entityScreenContext);
screen = menuSession.getNextScreen(needsFullInit, entityScreenContext);
continue;
}
if (currentStep == null && processedStepsCount != steps.size()) {
checkAndLogCaseIDMatchError(steps, processedSteps, neededDatum.getDataId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package org.commcare.formplayer.tests

import org.commcare.formplayer.beans.NewFormResponse
import org.commcare.formplayer.beans.menus.EntityListResponse
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest


@WebMvcTest
class CaseListAutoSelectTests : BaseTestClass() {

Expand All @@ -30,24 +28,7 @@ class CaseListAutoSelectTests : BaseTestClass() {
fun testAutoSelection() {
// We directly go to the form without selecting the case
val selections = arrayOf("0", "2")
var response = sessionNavigate(selections, APP, NewFormResponse::class.java)

// test breadcrumb
assertEquals( 3, response.breadcrumbs.size)
assertEquals( "Untitled Application", response.breadcrumbs[0])
assertEquals( "Case List", response.breadcrumbs[1])
assertEquals( "Followup Form 1", response.breadcrumbs[2])

// test persistent menu
val persistentMenu = response.persistentMenu
assertEquals(2, persistentMenu.size)
assertEquals("Case List", persistentMenu[0].displayText)
assertEquals("Case List 1", persistentMenu[1].displayText)
val zeroSelectionMenu = persistentMenu[0].commands
assertEquals(3, zeroSelectionMenu.size)
assertEquals("Registration Form", zeroSelectionMenu[0].displayText)
assertEquals("Followup Form", zeroSelectionMenu[1].displayText)
assertEquals("Followup Form 1", zeroSelectionMenu[2].displayText)
sessionNavigate(selections, APP, NewFormResponse::class.java)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.commcare.formplayer.beans.NewFormResponse;
import org.commcare.formplayer.beans.menus.CommandListResponseBean;
import org.commcare.formplayer.beans.menus.EntityListResponse;
import org.commcare.formplayer.beans.menus.PersistentCommand;
import org.commcare.formplayer.mocks.FormPlayerPropertyManagerMock;
import org.commcare.formplayer.utils.MockRequestUtils;
import org.commcare.formplayer.utils.WithHqUser;
Expand Down Expand Up @@ -203,13 +202,6 @@ public void testAutoSelection() throws Exception {
assertEquals(reponse.getSelections().length, 1);
assertEquals(reponse.getSelections()[0], "2");
assertEquals("Close", reponse.getCommands()[0].getDisplayText());

// Persistent Menu And Breadcrumbs should not contain the auto-selected entities
ArrayList<PersistentCommand> subMenu = reponse.getPersistentMenu().get(2).getCommands();
assertEquals(1, subMenu.size());
assertEquals("Close", subMenu.get(0).getDisplayText()); // directly contains the form instead of entity selection
assertEquals(ImmutableList.of("Case Claim", "Follow Up"),
Arrays.stream(reponse.getBreadcrumbs()).toList());
}

ArrayList<String> updatedSelections = new ArrayList<>(Arrays.asList(reponse.getSelections()));
Expand All @@ -219,11 +211,6 @@ public void testAutoSelection() throws Exception {
APP_NAME,
null,
NewFormResponse.class);
ArrayList<PersistentCommand> subMenu = formResponse.getPersistentMenu().get(2).getCommands();
assertEquals(1, subMenu.size());
assertEquals("Close", subMenu.get(0).getDisplayText());
assertEquals(ImmutableList.of("Case Claim", "Follow Up", "Close"),
Arrays.stream(formResponse.getBreadcrumbs()).toList());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ public void testPersistentMenu() throws Exception {
expectedMenu.add(new PersistentCommand("0", "Case List", "jr://file/commcare/image/m0customicon_en.png", NavIconState.NEXT));
expectedMenu.add(new PersistentCommand("1", "Case List", null, NavIconState.NEXT));
expectedMenu.add(new PersistentCommand("2", "Menu with Auto Submit Form", null, NavIconState.NEXT));
expectedMenu.add(new PersistentCommand("3", "Single Form Auto Select", null, NavIconState.NEXT));
assertEquals(expectedMenu, menuResponse.getPersistentMenu());

selections = new String[]{"0"};
Expand All @@ -267,42 +266,4 @@ public void testPersistentMenu() throws Exception {
firstSecondMenu.addCommand(new PersistentCommand(guid, "(2) 123, ...", null, NavIconState.ENTITY_SELECT));
assertEquals(expectedMenu, formResponse.getPersistentMenu());
}

@Test
public void testPersistentMenuWithAutoSelect() throws Exception {
ArrayList<PersistentCommand> expectedMenu = new ArrayList<>();
expectedMenu.add(new PersistentCommand("0", "Case List", "jr://file/commcare/image/m0customicon_en.png", NavIconState.NEXT));
expectedMenu.add(new PersistentCommand("1", "Case List", null, NavIconState.NEXT));
expectedMenu.add(new PersistentCommand("2", "Menu with Auto Submit Form", null, NavIconState.NEXT));
expectedMenu.add(new PersistentCommand("3", "Single Form Auto Select", null, NavIconState.NEXT));
PersistentCommand firstMenu = expectedMenu.get(0);
firstMenu.addCommand(new PersistentCommand("0","Registration Form", null, NavIconState.JUMP));
firstMenu.addCommand(new PersistentCommand("1","Followup Form", null, NavIconState.JUMP));
firstMenu.addCommand(new PersistentCommand("2","Followup Form with AutoSelect Datum", "jr://file/commcare/image/m0f2customicon_en.png", NavIconState.NEXT));
firstMenu.addCommand(new PersistentCommand("3","Followup Form with AutoSelect Datum", null, NavIconState.NEXT));
String[] selections = new String[]{"0", "2"};
NewFormResponse formResponse = sessionNavigate(selections, APP, NewFormResponse.class);
assertEquals(expectedMenu, formResponse.getPersistentMenu());
}

@Test
public void testPersistentMenuWithAutoAdvance() throws Exception {
ArrayList<PersistentCommand> expectedMenu = new ArrayList<>();
expectedMenu.add(new PersistentCommand("0", "Case List", "jr://file/commcare/image/m0customicon_en.png", NavIconState.NEXT));
expectedMenu.add(new PersistentCommand("1", "Case List", null, NavIconState.NEXT));
expectedMenu.add(new PersistentCommand("2", "Menu with Auto Submit Form", null, NavIconState.NEXT));
expectedMenu.add(new PersistentCommand("3", "Single Form Auto Select", null, NavIconState.NEXT));

// Auto-Advance in a Auto Select Case List
String[] selections = new String[]{"3"};
NewFormResponse formResponse = sessionNavigate(selections, APP, NewFormResponse.class);
assertEquals(expectedMenu, formResponse.getPersistentMenu());

FormPlayerPropertyManagerMock.mockAutoAdvanceMenu(storageFactoryMock, false);
selections = new String[]{"3", "0"};
formResponse = sessionNavigate(selections, APP, NewFormResponse.class);
expectedMenu.get(3).addCommand(new PersistentCommand("0", "Followup Form with AutoSelect Datum",
"jr://file/commcare/image/m0f2customicon_en.png", NavIconState.JUMP));
assertEquals(expectedMenu, formResponse.getPersistentMenu());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

<!-- end -->

<property key="cc-persistent-menu" value="yes" force="true"/>


<features>
<checkoff active="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
<property key="jr_openrosa_api" value="1.0" force="true"/>

<property key="heartbeat-url" value="http://localhost:8000/a/shubham/phone/heartbeat/6e7eb8d05a214872b5ed416a1e5fe313/?build_profile_id=" force="true"/>


<property key="cc-persistent-menu" value="yes" force="true"/>
<property key="cc-auto-advance-menu" value="yes" force="true"/>


<!-- Properties configured on CommCare HQ 1.0 -->
Expand Down
8 changes: 6 additions & 2 deletions src/test/resources/archives/case_list_auto_select/suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@
<entry>
<form>http://openrosa.org/formdesigner/99F89DA7-E568-4952-9BAF-717263F2C5DD</form>
<command id="m0-f2">
<text>Followup Form 1</text>
<text>
<locale id="forms.m0f1"/>
</text>
</command>
<instance id="casedb" src="jr://instance/casedb"/>
<session>
Expand Down Expand Up @@ -146,7 +148,9 @@
<command id="m0-f2"/>
</menu>
<menu id="m1">
<text>Case List 1</text>
<text>
<locale id="modules.m0"/>
</text>
<command id="m0-f3"/>
</menu>
</suite>
5 changes: 0 additions & 5 deletions src/test/resources/archives/multi_select_case_list/suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@
<text>Menu with Auto Submit Form</text>
<command id="m0-auto-submit-form"/>
</menu>
<menu id="single-form-auto-select-menu">
<text>Single Form Auto Select</text>
<command id="m0-f2"/>
<command id="m0-f3" relevant="false()"/>
</menu>
<endpoint id="case_list">
<argument id="selected_cases" instance-id="selected_cases" instance-src="jr://instance/selected-entities"/>
<stack>
Expand Down

0 comments on commit 8d7841c

Please sign in to comment.