Skip to content

Commit

Permalink
Tests for case list endpoints with inline case search enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham1g5 committed Aug 31, 2023
1 parent 978a051 commit 0adfde9
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.commcare.formplayer.util.Constants.TOGGLE_SESSION_ENDPOINTS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -332,4 +333,56 @@ public void testMultiSelectEndpointWithClaim_ValidSelection() throws Exception {
checkForSelectedEntitiesInstance(formResponse.getSessionId(), selectedValues);
}
}

@Test
@WithHqUser(enabledToggles = {TOGGLE_SESSION_ENDPOINTS})
public void testCaseListEndpointWithInlineCaseSearch() throws Exception {
try (MockRequestUtils.VerifiedMock ignore = mockRequest.mockQuery(
"query_responses/case_search_multi_select_response.xml")) {
EntityListResponse response = sessionNavigateWithEndpoint(APP_NAME,
"inline_case_search_list_without_selection",
null,
EntityListResponse.class);
assertNotNull(response.getEntities());
}
}


@Test
@WithHqUser(enabledToggles = {TOGGLE_SESSION_ENDPOINTS})
public void testCaseListSelectionEndpointWithInlineCaseSearch() throws Exception {
String[] selectedValues = new String[]{"94f8d030-c6f9-49e0-bc3f-5e0cdbf10c18",
"0156fa3e-093e-4136-b95c-01b13dae66c7",
"0156fa3e-093e-4136-b95c-01b13dae66c8"};
String selectedValuesArg = String.join(",", selectedValues);
HashMap<String, String> endpointArgs = new HashMap<>();
endpointArgs.put("selected_cases", selectedValuesArg);
try (MockRequestUtils.VerifiedMock ignore = mockRequest.mockQuery(
"query_responses/case_search_multi_select_response.xml")) {
CommandListResponseBean response = sessionNavigateWithEndpoint(APP_NAME,
"inline_case_search_list",
endpointArgs,
CommandListResponseBean.class);
assertEquals(response.getCommands().length, 1);
}
}

@Test
@WithHqUser(enabledToggles = {TOGGLE_SESSION_ENDPOINTS})
public void testFormEndpointWithInlineCaseSearch() throws Exception {
String[] selectedValues = new String[]{"94f8d030-c6f9-49e0-bc3f-5e0cdbf10c18",
"0156fa3e-093e-4136-b95c-01b13dae66c7",
"0156fa3e-093e-4136-b95c-01b13dae66c8"};
String selectedValuesArg = String.join(",", selectedValues);
HashMap<String, String> endpointArgs = new HashMap<>();
endpointArgs.put("selected_cases", selectedValuesArg);
try (MockRequestUtils.VerifiedMock ignore = mockRequest.mockQuery(
"query_responses/case_search_multi_select_response.xml")) {
NewFormResponse formResponse = sessionNavigateWithEndpoint(APP_NAME,
"inline_case_search_form",
endpointArgs,
NewFormResponse.class);
checkForSelectedEntitiesInstance(formResponse.getSessionId(), selectedValues);
}
}
}
66 changes: 66 additions & 0 deletions src/test/resources/archives/case_claim_with_multi_select/suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,33 @@
<instance-datum id="selected_cases" autoselect="true" nodeset="instance('casedb')/casedb/case[@case_type='case'][@status='open']" value="./@case_id" detail-select="m1_case_short_autolaunch_autoselect" detail-confirm="m1_case_long"/>
</session>
</entry>
<entry>
<form>http://openrosa.org/formdesigner/5CCB1614-68B3-44C0-A166-D63AA7C1D4FB</form>
<post url="http://localhost:8000/a/shubham/phone/claim-case/" relevant="$case_id != ''">
<data key="case_id" ref="." nodeset="instance('selected_cases')/results/value" exclude="count(instance('casedb')/casedb/case[@case_id=current()/.]) = 1"/>
</post>
<command id="m2-f0">
<text>
<locale id="forms.m1f1"/>
</text>
</command>
<instance id="casedb" src="jr://instance/casedb"/>
<instance id="results:inline" src="jr://instance/remote/results:inline"/>
<instance id="selected_cases" src="jr://instance/selected-entities/selected_cases"/>
<session>
<query url="http://localhost:8000/a/shubham/phone/search/87189ba3c8bb401490d63e7157f566c1/" storage-instance="results:inline" template="case" default_search="true">
<data key="case_type" ref="'case'"/>
<prompt key="name">
<display>
<text>
<locale id="search_property.m1.name"/>
</text>
</display>
</prompt>
</query>
<instance-datum id="selected_cases" nodeset="instance('results:inline')/results/case[@case_type='case'][@status='open'][not(commcare_is_related_case=true())]" value="./@case_id" detail-select="m1_case_short" detail-confirm="m1_case_long"/>
</session>
</entry>
<menu id="m1">
<text>
<locale id="modules.m1"/>
Expand All @@ -283,6 +310,45 @@
</text>
<command id="m0-f0"/>
</menu>
<menu id="m2-inline-search">
<text>
<locale id="modules.m1"/>
</text>
<command id="m2-f0"/>
</menu>
<endpoint id="inline_case_search_list_without_selection">
<stack>
<push>
<command value="'m2-inline-search'"/>
</push>
</stack>
</endpoint>
<endpoint id="inline_case_search_list">
<argument id="selected_cases" instance-id="selected_cases" instance-src="jr://instance/selected-entities"/>
<stack>
<push>
<command value="'m2-inline-search'"/>
<query id="results:inline" value="http://localhost:8000/a/shubham/phone/search/87189ba3c8bb401490d63e7157f566c1/">
<data key="case_type" ref="'case'"/>
</query>
<instance-datum id="selected_cases" value="$selected_cases"/>
</push>
</stack>
</endpoint>
<endpoint id="inline_case_search_form">
<argument id="selected_cases" instance-id="selected_cases" instance-src="jr://instance/selected-entities"/>
<stack>
<push>
<command value="'m2-inline-search'"/>
<query id="results:inline" value="http://localhost:8000/a/shubham/phone/search/87189ba3c8bb401490d63e7157f566c1/">
<data key="case_type" ref="'case'"/>
</query>
<instance-datum id="selected_cases" value="$selected_cases"/>
<command value="'m2-f0'"/>
</push>
</stack>
</endpoint>

<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 0adfde9

Please sign in to comment.