From 62adf0bcfa26afcc6850283067613023ded3aa68 Mon Sep 17 00:00:00 2001 From: Shubham Goyal Date: Wed, 6 Nov 2024 14:13:49 +0530 Subject: [PATCH] More persistent menu tests --- .../tests/MultiSelectCaseClaimTest.java | 16 +++++++---- .../tests/MultiSelectCaseListTest.java | 28 ++++++++++++++----- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/test/java/org/commcare/formplayer/tests/MultiSelectCaseClaimTest.java b/src/test/java/org/commcare/formplayer/tests/MultiSelectCaseClaimTest.java index 6d7ecd5b5..4fcdc4d7a 100644 --- a/src/test/java/org/commcare/formplayer/tests/MultiSelectCaseClaimTest.java +++ b/src/test/java/org/commcare/formplayer/tests/MultiSelectCaseClaimTest.java @@ -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; @@ -207,17 +208,22 @@ public void testAutoSelection() throws Exception { ArrayList 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 updatedSelections = new ArrayList<>(); - updatedSelections.addAll(Arrays.asList(reponse.getSelections())); + ArrayList 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 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 diff --git a/src/test/java/org/commcare/formplayer/tests/MultiSelectCaseListTest.java b/src/test/java/org/commcare/formplayer/tests/MultiSelectCaseListTest.java index 9ff0086ba..985a434fe 100644 --- a/src/test/java/org/commcare/formplayer/tests/MultiSelectCaseListTest.java +++ b/src/test/java/org/commcare/formplayer/tests/MultiSelectCaseListTest.java @@ -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 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()); } }