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

Remove obsolete backward compatibility flag for case search dropdowns #1455

Merged
merged 5 commits into from
Sep 5, 2023
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
12 changes: 0 additions & 12 deletions src/main/java/org/commcare/formplayer/objects/QueryData.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ public class QueryData extends Hashtable<String, Object> {
public static final String KEY_FORCE_MANUAL_SEARCH = "force_manual_search";
private static final String KEY_INPUTS = "inputs";

// whether the select prompt selection is passed as itemset keys
// only here to maintain backward compatibility and can be removed
// once web apps fully transition using keys to convey select prompt selection.
private static final String KEY_SELECT_VALUES_BY_KEY = "select_values_by_key";

public Boolean getExecute(String key) {
return getProperty(key, KEY_EXECUTE);
}
Expand Down Expand Up @@ -91,11 +86,4 @@ private void setProperty(String key, Boolean value, String property) {
((Map<String, Object>) this.get(key)).put(property, value);
}

public boolean isSelectValuesByKeys(String key) {
return getProperty(key, KEY_SELECT_VALUES_BY_KEY);
}

public void setSelectValuesByKeys(String key, Boolean value) {
setProperty(key, value, KEY_SELECT_VALUES_BY_KEY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ private boolean isAutoAdvanceMenu() {
private void answerQueryPrompts(FormplayerQueryScreen screen, QueryData queryData, String queryKey) {
Hashtable<String, String> queryDictionary = queryData == null ? null : queryData.getInputs(queryKey);
if (queryDictionary != null) {
screen.answerPrompts(queryDictionary, queryData.isSelectValuesByKeys(queryKey));
screen.answerPrompts(queryDictionary);
}
}

Expand Down
65 changes: 33 additions & 32 deletions src/test/java/org/commcare/formplayer/tests/CaseClaimTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public void testEmptySearch() throws Exception {

// Empty params should be carried over to url as well
queryData.setExecute("search_command.m1", true);
inputs.put("age", "22");
inputs.put("state", "ka");
inputs.put("name", "Burt");
inputs.put("dob", "");
sessionNavigateWithQuery(new String[]{"1", "action 1"},
"caseclaim",
queryData,
Expand All @@ -122,17 +126,16 @@ public void testEmptySearch() throws Exception {
requestDataCaptor.capture());
assertEquals("http://localhost:8000/a/test/phone/search/", urlCaptor.getAllValues().get(0));
Multimap<String, String> requestData = requestDataCaptor.getAllValues().get(0);
assertEquals(4, requestData.keySet().size());
assertEquals(6, requestData.keySet().size());
assertArrayEquals(new String[]{"case1", "case2", "case3"},
requestData.get("case_type").toArray());
assertArrayEquals(new String[]{""}, requestData.get("name").toArray());
assertArrayEquals(new String[]{""}, requestData.get("state").toArray());
assertArrayEquals(new String[]{""}, requestData.get("dob").toArray());
assertArrayEquals(new String[]{"False"}, requestData.get("include_closed").toArray());

// select empty with a valid choice
inputs.put("name", "#,#chris");
inputs.put("state", "0");
inputs.put("district", "#,#1");
inputs.put("state", "ka");
inputs.put("district", "#,#hampi");
queryData.setExecute("search_command.m1", false);
queryResponseBean = runQuery(queryData);
assert queryResponseBean.getDisplays()[0].getValue().contentEquals("#,#chris");
Expand All @@ -148,7 +151,7 @@ public void testEmptySearch() throws Exception {
requestDataCaptor.capture());
assertEquals("http://localhost:8000/a/test/phone/search/", urlCaptor.getAllValues().get(2));
requestData = requestDataCaptor.getAllValues().get(2);
assertEquals(5, requestData.keySet().size());
assertEquals(7, requestData.keySet().size());
assertArrayEquals(new String[]{"case1", "case2", "case3"},
requestData.get("case_type").toArray());
assertArrayEquals(new String[]{"", "chris"}, requestData.get("name").toArray());
Expand Down Expand Up @@ -218,17 +221,18 @@ public void testQueryScreen() throws Exception {
assert queryResponseBean.getDisplays()[0].getValue().contentEquals("Burt");

// multi-select test
inputs.put("state", "0");
inputs.put("district", "0#,#1"); // select 2 districts
inputs.put("state", "ka");
inputs.put("district", "bang#,#hampi"); // select 2 districts
queryResponseBean = runQuery(queryData);
assert queryResponseBean.getDisplays()[2].getValue().contentEquals("bang#,#hampi");

// Select an invalid choice in multi-select and verify it's removed from formplayer response
inputs.put("district", "0#,#2#,#1");
inputs.put("district", "bang#,#WhyAmIHere#,#hampi");
queryResponseBean = runQuery(queryData);
assert queryResponseBean.getDisplays()[2].getValue().contentEquals("bang#,#hampi");

// Execute Search to get results
inputs.put("age", "22"); // satisfy required condition to execute search
queryData.setExecute("search_command.m1", true);
responseBean = sessionNavigateWithQuery(new String[]{"1", "action 1"},
"caseclaim",
Expand Down Expand Up @@ -271,10 +275,11 @@ public void testQueryScreen() throws Exception {
// Therefore there are only 2 http calls here instead of 3
assertEquals("http://localhost:8000/a/test/phone/search/", urlCaptor.getAllValues().get(1));
requestData = requestDataCaptor.getAllValues().get(1);
assertEquals(5, requestData.keySet().size());
assertEquals(6, requestData.keySet().size());
assertArrayEquals(new String[]{"case1", "case2", "case3"},
requestData.get("case_type").toArray());
assertArrayEquals(new String[]{"Burt"}, requestData.get("name").toArray());
assertArrayEquals(new String[]{"22"}, requestData.get("age").toArray());
assertArrayEquals(new String[]{"bang", "hampi"}, requestData.get("district").toArray());
assertArrayEquals(new String[]{"ka"}, requestData.get("state").toArray());
assertArrayEquals(new String[]{"False"}, requestData.get("include_closed").toArray());
Expand Down Expand Up @@ -337,7 +342,7 @@ public void testQueryPromptRequired() throws Exception {
@Test
public void testDependentItemsets_DependentChoicesChangeWithSelection() throws Exception {
Hashtable<String, String> inputs = new Hashtable<>();
inputs.put("state", "1");
inputs.put("state", "rj");
QueryData queryData = setUpQueryDataWithInput(inputs, true, false);
QueryResponseBean queryResponseBean = runQuery(queryData);
assert queryResponseBean.getDisplays()[1].getValue().contentEquals("rj");
Expand All @@ -346,7 +351,7 @@ public void testDependentItemsets_DependentChoicesChangeWithSelection() throws E
assertArrayEquals(queryResponseBean.getDisplays()[2].getItemsetChoices(),
new String[]{"Baran", "Kota"});

inputs.put("state", "0");
inputs.put("state", "ka");
queryResponseBean = runQuery(queryData);
assert queryResponseBean.getDisplays()[1].getValue().contentEquals("ka");
assertArrayEquals(queryResponseBean.getDisplays()[1].getItemsetChoices(),
Expand Down Expand Up @@ -399,16 +404,16 @@ private HashMap<String, Object> getAnswers(String index, String answer) {
@Test
public void testDependentItemsets_SelectionPeristsInResponse() throws Exception {
Hashtable<String, String> inputs = new Hashtable<>();
inputs.put("state", "0");
inputs.put("district", "0");
inputs.put("state", "ka");
inputs.put("district", "bang");
QueryData queryData = setUpQueryDataWithInput(inputs, true, false);
QueryResponseBean queryResponseBean = runQuery(queryData);
assertEquals("ka", queryResponseBean.getDisplays()[1].getValue());
assertEquals("bang", queryResponseBean.getDisplays()[2].getValue());

// Change selection
inputs.put("state", "1");
inputs.put("district", "1");
inputs.put("state", "rj");
inputs.put("district", "kota");
queryResponseBean = runQuery(queryData);
assertEquals("rj", queryResponseBean.getDisplays()[1].getValue());
assertEquals("kota", queryResponseBean.getDisplays()[2].getValue());
Expand All @@ -418,7 +423,7 @@ public void testDependentItemsets_SelectionPeristsInResponse() throws Exception
public void testDependentItemsets_WithKeysInResponse() throws Exception {
Hashtable<String, String> inputs = new Hashtable<>();
inputs.put("state", "rj");
QueryData queryData = setUpQueryDataWithInput(inputs, true, false, true);
QueryData queryData = setUpQueryDataWithInput(inputs, true, false);
QueryResponseBean queryResponseBean = runQuery(queryData);
assertEquals(queryResponseBean.getDisplays()[1].getValue(), "rj");
assertArrayEquals(queryResponseBean.getDisplays()[1].getItemsetChoices(),
Expand Down Expand Up @@ -452,20 +457,20 @@ public void testDependentItemsets_WrongSelectionCausesValueToClear() throws Exce
Hashtable<String, String> inputs = new Hashtable<>();
inputs.put("state", "ka");
inputs.put("district", "baran");
QueryData queryData = setUpQueryDataWithInput(inputs, true, false, true);
QueryData queryData = setUpQueryDataWithInput(inputs, true, false);
QueryResponseBean queryResponseBean = runQuery(queryData);
assertEquals(queryResponseBean.getDisplays()[1].getValue(),"ka");
assertNull(queryResponseBean.getDisplays()[2].getValue());
}

@Test
public void testQueryPromptValidation_NullInputCausesNoError() throws Exception {
runRequestAndValidateAgeError(null, null, true, false);
public void testQueryPromptValidation_NullInputCausesRequiredError() throws Exception {
runRequestAndValidateAgeError(null, "One of age or DOB is required", true, false);
}

@Test
public void testQueryPromptValidation_EmptyInputCausesNoError() throws Exception {
runRequestAndValidateAgeError("", null, true, false);
public void testQueryPromptValidation_EmptyInputCausesRequiredError() throws Exception {
runRequestAndValidateAgeError("", "One of age or DOB is required", true, false);
}

@Test
Expand All @@ -479,13 +484,13 @@ public void testQueryPromptValidation_ValidInputCausesNoError() throws Exception
}

@Test
public void testQueryPromptValidationWithExecute_NullInputCausesNoError() throws Exception {
runRequestAndValidateAgeError(null, null, true, true);
public void testQueryPromptValidationWithExecute_NullInputCausesRequiredError() throws Exception {
runRequestAndValidateAgeError(null, "One of age or DOB is required", true, true);
}

@Test
public void testQueryPromptValidationWithExecute_EmptyInputCausesNoError() throws Exception {
runRequestAndValidateAgeError("", null, true, true);
public void testQueryPromptValidationWithExecute_EmptyInputCausesRequiredError() throws Exception {
runRequestAndValidateAgeError("", "One of age or DOB is required", true, true);
}

@Test
Expand Down Expand Up @@ -538,11 +543,6 @@ private QueryData setUpQueryDataWithAge(String age, boolean forceManual, boolean

private QueryData setUpQueryDataWithInput(Hashtable<String, String> inputs, boolean forceManual,
boolean execute) {
return setUpQueryDataWithInput(inputs, forceManual, execute, false);
}

private QueryData setUpQueryDataWithInput(Hashtable<String, String> inputs, boolean forceManual,
boolean execute, boolean selectValuesByKeys) {
QueryData queryData = new QueryData();
queryData.setInputs("search_command.m1", inputs);
if (forceManual) {
Expand All @@ -551,7 +551,6 @@ private QueryData setUpQueryDataWithInput(Hashtable<String, String> inputs, bool
if (execute) {
queryData.setExecute("search_command.m1", true);
}
queryData.setSelectValuesByKeys("search_command.m1", selectValuesByKeys);
return queryData;
}

Expand All @@ -564,6 +563,8 @@ public void testAlreadyOwnCase() throws Exception {

Hashtable<String, String> inputs = new Hashtable<>();
inputs.put("name", "Burt");
inputs.put("age", "33");
inputs.put("state", "ka");
QueryData queryData = setUpQueryDataWithInput(inputs, true, true);
CommandListResponseBean response = sessionNavigateWithQuery(
new String[]{"1", "action 1", "3512eb7c-7a58-4a95-beda-205eb0d7f163"},
Expand Down