Skip to content

Commit

Permalink
More persistent menu tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham1g5 committed Nov 6, 2024
1 parent 26eb5fa commit 62adf0b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimap;

import org.apache.commons.lang3.ArrayUtils;
Expand Down Expand Up @@ -207,17 +208,22 @@ public void testAutoSelection() throws Exception {
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(2, reponse.getBreadcrumbs().length);
assertEquals(ImmutableList.of("Case Claim", "Follow Up"),
Arrays.stream(reponse.getBreadcrumbs()).toList());
}

ArrayList<String> updatedSelections = new ArrayList<>();
updatedSelections.addAll(Arrays.asList(reponse.getSelections()));
ArrayList<String> updatedSelections = new ArrayList<>(Arrays.asList(reponse.getSelections()));
updatedSelections.add("0");

sessionNavigateWithQuery(updatedSelections.toArray(new String[0]),
NewFormResponse formResponse = sessionNavigateWithQuery(updatedSelections.toArray(new String[0]),
APP_NAME,
null,
FormEntryResponseBean.class);
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 @@ -275,20 +275,34 @@ public void testPersistentMenuWithAutoSelect() throws Exception {
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());


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));
selections = new String[]{"0", "2"};
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());
}
}

0 comments on commit 62adf0b

Please sign in to comment.