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

Reinstate auto select revert #1649

Merged
merged 4 commits into from
Dec 3, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public Screen rebuildSessionFromFrame(MenuSession menuSession, CaseSearchHelper
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 @@ -184,7 +184,7 @@ public boolean handleInput(@Nullable Screen screen, String input, boolean needsF
if (screen instanceof EntityScreen) {
EntityScreen entityScreen = (EntityScreen)screen;
boolean autoLaunch = entityScreen.getAutoLaunchAction() != null && allowAutoLaunch;
addBreadcrumb = !autoLaunch;
addBreadcrumb = !(autoLaunch || entityScreen.shouldBeSkipped());
if (input.startsWith("action ") || (autoLaunch) || !inputValidated) {
screen.init(sessionWrapper);
// auto-launch takes preference over auto-select
Expand Down Expand Up @@ -224,11 +224,13 @@ public boolean handleInput(@Nullable Screen screen, String input, boolean needsF
* current index based selections[] to contain menu ids instead of indexes.
*/
if (entityScreenContext.isRespectRelevancy()) {
if (screen instanceof EntityScreen) {
if (screen instanceof EntityScreen && !screen.shouldBeSkipped()) {
String breadcrumb = screen.getBreadcrumb(input, sandbox, getSessionWrapper());
persistentMenuHelper.addEntitySelection(persistentMenuId, breadcrumb);
persistentMenuHelper.advanceCurrentMenuWithInput(screen, persistentMenuId);
} else if (screen instanceof MenuScreen) {
persistentMenuHelper.advanceCurrentMenuWithInput(screen, persistentMenuId);
}
persistentMenuHelper.advanceCurrentMenuWithInput(screen, persistentMenuId);
}
return true;
} catch (ArrayIndexOutOfBoundsException | NullPointerException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ 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 @@ -28,7 +30,24 @@ class CaseListAutoSelectTests : BaseTestClass() {
fun testAutoSelection() {
// We directly go to the form without selecting the case
val selections = arrayOf("0", "2")
sessionNavigate(selections, APP, NewFormResponse::class.java)
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)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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 @@ -202,6 +203,13 @@ 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 @@ -211,6 +219,15 @@ 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());
String[] selectedValues = new String[]{"94f8d030-c6f9-49e0-bc3f-5e0cdbf10c18",
"0156fa3e-093e-4136-b95c-01b13dae66c7",
"0156fa3e-093e-4136-b95c-01b13dae66c8"};
checkForSelectedEntitiesInstance(formResponse.getSessionId(), selectedValues);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ 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 @@ -266,4 +267,42 @@ 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,6 +21,10 @@
<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: 2 additions & 6 deletions src/test/resources/archives/case_list_auto_select/suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@
<entry>
<form>http://openrosa.org/formdesigner/99F89DA7-E568-4952-9BAF-717263F2C5DD</form>
<command id="m0-f2">
<text>
<locale id="forms.m0f1"/>
</text>
<text>Followup Form 1</text>
</command>
<instance id="casedb" src="jr://instance/casedb"/>
<session>
Expand Down Expand Up @@ -148,9 +146,7 @@
<command id="m0-f2"/>
</menu>
<menu id="m1">
<text>
<locale id="modules.m0"/>
</text>
<text>Case List 1</text>
<command id="m0-f3"/>
</menu>
</suite>
5 changes: 5 additions & 0 deletions src/test/resources/archives/multi_select_case_list/suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@
<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
Loading