From 7c8ffaaeabd8a4334702ea9fe9da1036853f21f4 Mon Sep 17 00:00:00 2001 From: Samuel Githengi Date: Tue, 10 Mar 2020 11:08:52 +0300 Subject: [PATCH 1/5] Test write and validate with invalid inputs --- .../com/vijay/jsonwizard/TestConstants.java | 3 ++ ...FormFragmentPresenterRoboElectricTest.java | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/TestConstants.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/TestConstants.java index 4d8e96381..a9ec72f32 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/TestConstants.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/TestConstants.java @@ -11,4 +11,7 @@ public class TestConstants { public static final String TYPE_ARRAY = "array"; public static final String PAOT_TEST_FORM="{\"count\":\"1\",\"encounter_type\":\"PAOT\",\"entity_id\":\"\",\"metadata\":{\"start\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"start\",\"openmrs_entity_id\":\"163137AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"end\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"end\",\"openmrs_entity_id\":\"163138AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"today\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"encounter\",\"openmrs_entity_id\":\"encounter_date\"},\"deviceid\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"deviceid\",\"openmrs_entity_id\":\"163149AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"subscriberid\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"subscriberid\",\"openmrs_entity_id\":\"163150AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"simserial\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"simserial\",\"openmrs_entity_id\":\"163151AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"phonenumber\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"phonenumber\",\"openmrs_entity_id\":\"163152AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"encounter_location\":\"\"},\"step1\":{\"title\":\"Potential Area of Transmission\",\"display_back_button\":\"true\",\"fields\":[{\"key\":\"paotStatus\",\"label\":\"Status\",\"type\":\"native_radio\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"options\":[{\"key\":\"Active\",\"text\":\"Active\"},{\"key\":\"Inactive\",\"text\":\"Inactive\"},{\"key\":\"Not_Eligible\",\"text\":\"Not Eligible\"}],\"v_required\":{\"value\":true,\"err\":\"Please specify status of area of transmission\"}},{\"key\":\"paotComments\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"edit_text\",\"hint\":\"Comments\"},{\"key\":\"lastUpdatedDate\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"date_picker\",\"hint\":\"Last Updated\",\"max_date\":\"today\",\"v_required\":{\"value\":true,\"err\":\"Please specify the last updated date\"}},{\"key\":\"business_status\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"hidden\",\"value\":\"Complete\"}]}}"; + + + public static final String BASIC_FORM="{\"count\":\"3\",\"encounter_type\":\"Test\",\"entity_id\":\"\",\"relational_id\":\"\",\"validate_on_submit\":true,\"show_errors_on_submit\":true,\"metadata\":{\"start\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"start\",\"openmrs_entity_id\":\"163137AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"end\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"end\",\"openmrs_entity_id\":\"163138AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"today\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"encounter\",\"openmrs_entity_id\":\"encounter_date\"},\"deviceid\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"deviceid\",\"openmrs_entity_id\":\"163149AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"subscriberid\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"subscriberid\",\"openmrs_entity_id\":\"163150AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"simserial\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"simserial\",\"openmrs_entity_id\":\"163151AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"phonenumber\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"phonenumber\",\"openmrs_entity_id\":\"163152AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"encounter_location\":\"\",\"look_up\":{\"entity_id\":\"\",\"value\":\"\"}},\"step1\":{\"title\":\"Basic Form One\",\"next\":\"step2\",\"fields\":[{\"key\":\"user_image\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"choose_image\",\"uploadButtonText\":\"Take a photo of the child\"},{\"key\":\"thumbnail\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"image_view\",\"uploadButtonText\":\"Take a photo of the child\"},{\"key\":\"user_first_name\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"edit_text\",\"hint\":\"User First name\",\"edit_type\":\"name\",\"v_required\":{\"value\":\"true\",\"err\":\"Please enter the first name\"},\"v_regex\":{\"value\":\"[A-Za-z\\\\s\\\\.\\\\-]*\",\"err\":\"Please enter a valid name\"}},{\"key\":\"user_last_name\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"normal_edit_text\",\"hint\":\"User Last name\",\"edit_type\":\"name\",\"v_required\":{\"value\":\"true\",\"err\":\"Please enter the last name\"},\"v_regex\":{\"value\":\"[A-Za-z\\\\s\\\\.\\\\-]*\",\"err\":\"Please enter a valid name\"}},{\"key\":\"user_qr_code\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"barcode\",\"barcode_type\":\"qrcode\",\"hint\":\"User ID\",\"scanButtonText\":\"Scan QR Code\",\"v_numeric\":{\"value\":\"true\",\"err\":\"Please enter a valid ID\"},\"v_required\":{\"value\":false,\"err\":\"Please enter the user ID\"}},{\"key\":\"user_age\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"edit_text\",\"hint\":\"User age\",\"edit_type\":\"number\",\"v_required\":{\"value\":\"true\",\"err\":\"Please enter user age\"},\"v_regex\":{\"value\":\"[A-Za-z\\\\s\\\\.\\\\-]*\",\"err\":\"Please enter a valid name\"}},{\"key\":\"user_gps\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"openmrs_data_type\":\"text\",\"type\":\"gps\"},{\"key\":\"user_calculation_one\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_entity_id\":\"165260AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\"type\":\"hidden\"},{\"key\":\"user_spinner\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"spinner\",\"hint\":\"User Spinners\",\"values\":[\"User Option One\",\"User Option Two\"],\"keys\":[\"user_option_one\",\"user_option_two\"],\"v_required\":{\"value\":\"true\",\"err\":\"Please enter the sex\"},\"openmrs_choice_ids\":{\"user_one\":\"1107AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\"user_two\":\"1713AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"}},{\"key\":\"user_check_box\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"openmrs_data_type\":\"select one\",\"type\":\"check_box\",\"label\":\"Do want to select any checkbox?\",\"label_text_style\":\"bold\",\"options\":[{\"key\":\"None\",\"text\":\"None\",\"value\":false,\"openmrs_choice_id\":\"\"},{\"key\":\"yes\",\"text\":\"Yes\",\"value\":false,\"openmrs_choice_id\":\"\"},{\"key\":\"no\",\"text\":\"No\",\"value\":false,\"openmrs_choice_id\":\"\"},{\"key\":\"other\",\"text\":\"Other\",\"value\":false,\"openmrs_choice_id\":\"\"}],\"v_required\":{\"value\":\"true\"}}]},\"step2\":{\"title\":\"Basic Form Two\",\"next\":\"step3\",\"fields\":[{\"key\":\"user_select\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"native_radio\",\"label\":\"Do you want to select anything\",\"label_text_style\":\"bold\",\"text_color\":\"#000000\",\"label_info_text\":\"You can select every thing you want.\",\"label_info_title\":\"User selection\",\"options\":[{\"key\":\"yes\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"text\":\"Yes\"},{\"key\":\"no\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"text\":\"No\"}]},{\"key\":\"user_normal_edit_text\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"normal_edit_text\",\"hint\":\"User Text \",\"edit_text_style\":\"bordered\"},{\"key\":\"user_normal_edit_number\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"normal_edit_text\",\"hint\":\"User number\",\"edit_text_style\":\"bordered\",\"edit_type\":\"number\"},{\"key\":\"user_toaster_problem\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"toaster_notes\",\"text\":\"User problem toaster\",\"toaster_info_text\":\"Procedure:\\n- This shows the user the problems.\\n- Problem toaster.\",\"toaster_type\":\"problem\"},{\"key\":\"user_toaster_warning\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"toaster_notes\",\"text\":\"User warning toaster\",\"toaster_info_text\":\"Procedure:\\n- This shows the user the warning.\\n- Warning toaster.\",\"toaster_type\":\"warning\"},{\"key\":\"user_toaster_positive\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"toaster_notes\",\"text\":\"User positive toaster\",\"toaster_info_text\":\"Procedure:\\n- This shows the user the positive.\\n- Positive toaster.\",\"toaster_type\":\"positive\"},{\"key\":\"user_toaster_info\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"toaster_notes\",\"text\":\"User Info toaster\",\"toaster_info_text\":\"Procedure:\\n- This shows the user the info.\\n- Info toaster.\",\"toaster_type\":\"info\"}]},\"step3\":{\"title\":\"Basic Form Threes\",\"fields\":[{\"key\":\"user_date\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"date_picker\",\"hint\":\"User DOB\",\"expanded\":false,\"duration\":{\"label\":\"Age\"},\"default\":\"12-12-2015\",\"min_date\":\"today-5y\",\"max_date\":\"today\",\"v_required\":{\"value\":\"true\",\"err\":\"Please enter the date of birth\"}},{\"key\":\"user_time\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"time_picker\",\"hint\":\"Birth Time\",\"expanded\":false,\"duration\":{\"label\":\"Birth Time\"},\"v_required\":{\"value\":true,\"err\":\"Please enter the time of birth\"}},{\"key\":\"user_spinner\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"spinner\",\"hint\":\"User Spinners\",\"values\":[\"User Option One\",\"User Option Two\"],\"keys\":[\"user_option_one\",\"user_option_two\"],\"v_required\":{\"value\":\"true\",\"err\":\"Please enter the sex\"},\"openmrs_choice_ids\":{\"user_one\":\"1107AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\"user_two\":\"1713AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"}},{\"key\":\"spacer\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"spacer\",\"type\":\"spacer\",\"spacer_height\":\"20dp\"},{\"key\":\"user_form_labels\",\"type\":\"label\",\"label_text_style\":\"bold\",\"text\":\"Number of labels\",\"text_color\":\"#000000\",\"v_required\":{\"value\":true}},{\"key\":\"user_form\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"numbers_selector\",\"number_of_selectors\":\"5\",\"start_number\":\"1\",\"max_value\":\"15\",\"text_size\":\"16px\",\"text_color\":\"#000000\",\"selected_text_color\":\"#ffffff\",\"v_required\":{\"value\":true}},{\"key\":\"spacer\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"spacer\",\"type\":\"spacer\",\"spacer_height\":\"20dp\"},{\"key\":\"user_sub_form\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"native_radio\",\"label\":\"User sub forms?\",\"label_text_style\":\"bold\",\"text_color\":\"#000000\",\"extra_rel\":true,\"has_extra_rel\":\"yes\",\"options\":[{\"key\":\"yes\",\"text\":\"Yes\",\"value\":false,\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"specify_info\":\"User sub specify...\",\"specify_widget\":\"normal_edit_text\",\"specify_info_color\":\"#8C8C8C\",\"secondary_suffix\":\"bpm\",\"content_form\":\"user_native_sub_form\"},{\"key\":\"no\",\"text\":\"No\",\"value\":false,\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\"}],\"v_required\":{\"value\":true,\"err\":\"Please specify user native form.\"}},{\"key\":\"user_check_box\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"openmrs_data_type\":\"select one\",\"type\":\"check_box\",\"label\":\"Do want to select any checkbox?\",\"label_text_style\":\"bold\",\"options\":[{\"key\":\"None\",\"text\":\"None\",\"value\":false,\"openmrs_choice_id\":\"\"},{\"key\":\"yes\",\"text\":\"Yes\",\"value\":false,\"openmrs_choice_id\":\"\"},{\"key\":\"no\",\"text\":\"No\",\"value\":false,\"openmrs_choice_id\":\"\"},{\"key\":\"other\",\"text\":\"Other\",\"value\":false,\"openmrs_choice_id\":\"\"}],\"v_required\":{\"value\":\"false\"},\"value\":\"[yes]\"}]}}"; } diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java index 977c9a112..5d49dbcda 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java @@ -1,6 +1,7 @@ package com.vijay.jsonwizard.presenters; import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.TextView; @@ -26,6 +27,7 @@ import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.powermock.reflect.Whitebox; +import org.robolectric.Robolectric; import org.robolectric.RuntimeEnvironment; import java.lang.ref.WeakReference; @@ -42,6 +44,8 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -91,6 +95,15 @@ public void setUp() throws JSONException { when(jsonFormActivity.getmJSONObject()).thenReturn(jsonForm); } + private void initWithActualForm() { + Intent intent = new Intent(); + intent.putExtra("json", TestConstants.BASIC_FORM); + jsonFormActivity = spy(Robolectric.buildActivity(JsonFormActivity.class, intent).create().resume().get()); + formFragment = spy(JsonFormFragment.getFormFragment("step1")); + jsonFormActivity.getSupportFragmentManager().beginTransaction().add(formFragment, null).commit(); + presenter = formFragment.getPresenter(); + } + @Test public void testAddFormElements() { Bundle bundle = new Bundle(); @@ -174,4 +187,20 @@ public void testOnNextClickReturnsFalseIfFormIsInvalid() { assertFalse(presenter.onNextClick(null)); } + + @Test + public void testValidateAndWriteValuesWithInvalidFields() { + initWithActualForm(); + formFragment.onFieldsInvalid = this.onFieldsInvalid; + presenter.validateAndWriteValues(); + assertEquals(4, presenter.getInvalidFields().size()); + assertEquals("Please enter the last name", presenter.getInvalidFields().get("step1#Basic Form One:user_last_name").getErrorMessage()); + assertEquals("Please enter user age", presenter.getInvalidFields().get("step1#Basic Form One:user_age").getErrorMessage()); + assertEquals("Please enter the first name", presenter.getInvalidFields().get("step1#Basic Form One:user_first_name").getErrorMessage()); + assertEquals("Please enter the sex", presenter.getInvalidFields().get("step1#Basic Form One:user_spinner").getErrorMessage()); + verify(formFragment, times(6)).writeValue(anyString(), anyString(), anyString(), anyString(), anyString(), + anyString(), anyBoolean()); + verify(onFieldsInvalid).passInvalidFields(presenter.getInvalidFields()); + } + } From 83e834b054d01b8622df3414948d2b0dd120b9c6 Mon Sep 17 00:00:00 2001 From: Samuel Githengi Date: Tue, 10 Mar 2020 11:45:04 +0300 Subject: [PATCH 2/5] Test validate and validate and write validates with form inputs --- .../com/vijay/jsonwizard/TestConstants.java | 2 +- ...FormFragmentPresenterRoboElectricTest.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/TestConstants.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/TestConstants.java index a9ec72f32..4bbaaf9f5 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/TestConstants.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/TestConstants.java @@ -13,5 +13,5 @@ public class TestConstants { public static final String PAOT_TEST_FORM="{\"count\":\"1\",\"encounter_type\":\"PAOT\",\"entity_id\":\"\",\"metadata\":{\"start\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"start\",\"openmrs_entity_id\":\"163137AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"end\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"end\",\"openmrs_entity_id\":\"163138AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"today\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"encounter\",\"openmrs_entity_id\":\"encounter_date\"},\"deviceid\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"deviceid\",\"openmrs_entity_id\":\"163149AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"subscriberid\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"subscriberid\",\"openmrs_entity_id\":\"163150AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"simserial\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"simserial\",\"openmrs_entity_id\":\"163151AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"phonenumber\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"phonenumber\",\"openmrs_entity_id\":\"163152AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"encounter_location\":\"\"},\"step1\":{\"title\":\"Potential Area of Transmission\",\"display_back_button\":\"true\",\"fields\":[{\"key\":\"paotStatus\",\"label\":\"Status\",\"type\":\"native_radio\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"options\":[{\"key\":\"Active\",\"text\":\"Active\"},{\"key\":\"Inactive\",\"text\":\"Inactive\"},{\"key\":\"Not_Eligible\",\"text\":\"Not Eligible\"}],\"v_required\":{\"value\":true,\"err\":\"Please specify status of area of transmission\"}},{\"key\":\"paotComments\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"edit_text\",\"hint\":\"Comments\"},{\"key\":\"lastUpdatedDate\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"date_picker\",\"hint\":\"Last Updated\",\"max_date\":\"today\",\"v_required\":{\"value\":true,\"err\":\"Please specify the last updated date\"}},{\"key\":\"business_status\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"hidden\",\"value\":\"Complete\"}]}}"; - public static final String BASIC_FORM="{\"count\":\"3\",\"encounter_type\":\"Test\",\"entity_id\":\"\",\"relational_id\":\"\",\"validate_on_submit\":true,\"show_errors_on_submit\":true,\"metadata\":{\"start\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"start\",\"openmrs_entity_id\":\"163137AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"end\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"end\",\"openmrs_entity_id\":\"163138AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"today\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"encounter\",\"openmrs_entity_id\":\"encounter_date\"},\"deviceid\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"deviceid\",\"openmrs_entity_id\":\"163149AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"subscriberid\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"subscriberid\",\"openmrs_entity_id\":\"163150AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"simserial\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"simserial\",\"openmrs_entity_id\":\"163151AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"phonenumber\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"phonenumber\",\"openmrs_entity_id\":\"163152AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"encounter_location\":\"\",\"look_up\":{\"entity_id\":\"\",\"value\":\"\"}},\"step1\":{\"title\":\"Basic Form One\",\"next\":\"step2\",\"fields\":[{\"key\":\"user_image\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"choose_image\",\"uploadButtonText\":\"Take a photo of the child\"},{\"key\":\"thumbnail\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"image_view\",\"uploadButtonText\":\"Take a photo of the child\"},{\"key\":\"user_first_name\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"edit_text\",\"hint\":\"User First name\",\"edit_type\":\"name\",\"v_required\":{\"value\":\"true\",\"err\":\"Please enter the first name\"},\"v_regex\":{\"value\":\"[A-Za-z\\\\s\\\\.\\\\-]*\",\"err\":\"Please enter a valid name\"}},{\"key\":\"user_last_name\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"normal_edit_text\",\"hint\":\"User Last name\",\"edit_type\":\"name\",\"v_required\":{\"value\":\"true\",\"err\":\"Please enter the last name\"},\"v_regex\":{\"value\":\"[A-Za-z\\\\s\\\\.\\\\-]*\",\"err\":\"Please enter a valid name\"}},{\"key\":\"user_qr_code\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"barcode\",\"barcode_type\":\"qrcode\",\"hint\":\"User ID\",\"scanButtonText\":\"Scan QR Code\",\"v_numeric\":{\"value\":\"true\",\"err\":\"Please enter a valid ID\"},\"v_required\":{\"value\":false,\"err\":\"Please enter the user ID\"}},{\"key\":\"user_age\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"edit_text\",\"hint\":\"User age\",\"edit_type\":\"number\",\"v_required\":{\"value\":\"true\",\"err\":\"Please enter user age\"},\"v_regex\":{\"value\":\"[A-Za-z\\\\s\\\\.\\\\-]*\",\"err\":\"Please enter a valid name\"}},{\"key\":\"user_gps\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"openmrs_data_type\":\"text\",\"type\":\"gps\"},{\"key\":\"user_calculation_one\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_entity_id\":\"165260AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\"type\":\"hidden\"},{\"key\":\"user_spinner\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"spinner\",\"hint\":\"User Spinners\",\"values\":[\"User Option One\",\"User Option Two\"],\"keys\":[\"user_option_one\",\"user_option_two\"],\"v_required\":{\"value\":\"true\",\"err\":\"Please enter the sex\"},\"openmrs_choice_ids\":{\"user_one\":\"1107AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\"user_two\":\"1713AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"}},{\"key\":\"user_check_box\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"openmrs_data_type\":\"select one\",\"type\":\"check_box\",\"label\":\"Do want to select any checkbox?\",\"label_text_style\":\"bold\",\"options\":[{\"key\":\"None\",\"text\":\"None\",\"value\":false,\"openmrs_choice_id\":\"\"},{\"key\":\"yes\",\"text\":\"Yes\",\"value\":false,\"openmrs_choice_id\":\"\"},{\"key\":\"no\",\"text\":\"No\",\"value\":false,\"openmrs_choice_id\":\"\"},{\"key\":\"other\",\"text\":\"Other\",\"value\":false,\"openmrs_choice_id\":\"\"}],\"v_required\":{\"value\":\"true\"}}]},\"step2\":{\"title\":\"Basic Form Two\",\"next\":\"step3\",\"fields\":[{\"key\":\"user_select\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"native_radio\",\"label\":\"Do you want to select anything\",\"label_text_style\":\"bold\",\"text_color\":\"#000000\",\"label_info_text\":\"You can select every thing you want.\",\"label_info_title\":\"User selection\",\"options\":[{\"key\":\"yes\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"text\":\"Yes\"},{\"key\":\"no\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"text\":\"No\"}]},{\"key\":\"user_normal_edit_text\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"normal_edit_text\",\"hint\":\"User Text \",\"edit_text_style\":\"bordered\"},{\"key\":\"user_normal_edit_number\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"normal_edit_text\",\"hint\":\"User number\",\"edit_text_style\":\"bordered\",\"edit_type\":\"number\"},{\"key\":\"user_toaster_problem\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"toaster_notes\",\"text\":\"User problem toaster\",\"toaster_info_text\":\"Procedure:\\n- This shows the user the problems.\\n- Problem toaster.\",\"toaster_type\":\"problem\"},{\"key\":\"user_toaster_warning\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"toaster_notes\",\"text\":\"User warning toaster\",\"toaster_info_text\":\"Procedure:\\n- This shows the user the warning.\\n- Warning toaster.\",\"toaster_type\":\"warning\"},{\"key\":\"user_toaster_positive\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"toaster_notes\",\"text\":\"User positive toaster\",\"toaster_info_text\":\"Procedure:\\n- This shows the user the positive.\\n- Positive toaster.\",\"toaster_type\":\"positive\"},{\"key\":\"user_toaster_info\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"toaster_notes\",\"text\":\"User Info toaster\",\"toaster_info_text\":\"Procedure:\\n- This shows the user the info.\\n- Info toaster.\",\"toaster_type\":\"info\"}]},\"step3\":{\"title\":\"Basic Form Threes\",\"fields\":[{\"key\":\"user_date\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"date_picker\",\"hint\":\"User DOB\",\"expanded\":false,\"duration\":{\"label\":\"Age\"},\"default\":\"12-12-2015\",\"min_date\":\"today-5y\",\"max_date\":\"today\",\"v_required\":{\"value\":\"true\",\"err\":\"Please enter the date of birth\"}},{\"key\":\"user_time\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"time_picker\",\"hint\":\"Birth Time\",\"expanded\":false,\"duration\":{\"label\":\"Birth Time\"},\"v_required\":{\"value\":true,\"err\":\"Please enter the time of birth\"}},{\"key\":\"user_spinner\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"spinner\",\"hint\":\"User Spinners\",\"values\":[\"User Option One\",\"User Option Two\"],\"keys\":[\"user_option_one\",\"user_option_two\"],\"v_required\":{\"value\":\"true\",\"err\":\"Please enter the sex\"},\"openmrs_choice_ids\":{\"user_one\":\"1107AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\"user_two\":\"1713AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"}},{\"key\":\"spacer\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"spacer\",\"type\":\"spacer\",\"spacer_height\":\"20dp\"},{\"key\":\"user_form_labels\",\"type\":\"label\",\"label_text_style\":\"bold\",\"text\":\"Number of labels\",\"text_color\":\"#000000\",\"v_required\":{\"value\":true}},{\"key\":\"user_form\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"numbers_selector\",\"number_of_selectors\":\"5\",\"start_number\":\"1\",\"max_value\":\"15\",\"text_size\":\"16px\",\"text_color\":\"#000000\",\"selected_text_color\":\"#ffffff\",\"v_required\":{\"value\":true}},{\"key\":\"spacer\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"spacer\",\"type\":\"spacer\",\"spacer_height\":\"20dp\"},{\"key\":\"user_sub_form\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"native_radio\",\"label\":\"User sub forms?\",\"label_text_style\":\"bold\",\"text_color\":\"#000000\",\"extra_rel\":true,\"has_extra_rel\":\"yes\",\"options\":[{\"key\":\"yes\",\"text\":\"Yes\",\"value\":false,\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"specify_info\":\"User sub specify...\",\"specify_widget\":\"normal_edit_text\",\"specify_info_color\":\"#8C8C8C\",\"secondary_suffix\":\"bpm\",\"content_form\":\"user_native_sub_form\"},{\"key\":\"no\",\"text\":\"No\",\"value\":false,\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\"}],\"v_required\":{\"value\":true,\"err\":\"Please specify user native form.\"}},{\"key\":\"user_check_box\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"openmrs_data_type\":\"select one\",\"type\":\"check_box\",\"label\":\"Do want to select any checkbox?\",\"label_text_style\":\"bold\",\"options\":[{\"key\":\"None\",\"text\":\"None\",\"value\":false,\"openmrs_choice_id\":\"\"},{\"key\":\"yes\",\"text\":\"Yes\",\"value\":false,\"openmrs_choice_id\":\"\"},{\"key\":\"no\",\"text\":\"No\",\"value\":false,\"openmrs_choice_id\":\"\"},{\"key\":\"other\",\"text\":\"Other\",\"value\":false,\"openmrs_choice_id\":\"\"}],\"v_required\":{\"value\":\"false\"},\"value\":\"[yes]\"}]}}"; + public static final String BASIC_FORM="{\"count\":\"3\",\"encounter_type\":\"Test\",\"entity_id\":\"\",\"relational_id\":\"\",\"validate_on_submit\":true,\"show_errors_on_submit\":true,\"metadata\":{\"start\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"start\",\"openmrs_entity_id\":\"163137AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"end\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"end\",\"openmrs_entity_id\":\"163138AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"today\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"encounter\",\"openmrs_entity_id\":\"encounter_date\"},\"deviceid\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"deviceid\",\"openmrs_entity_id\":\"163149AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"subscriberid\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"subscriberid\",\"openmrs_entity_id\":\"163150AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"simserial\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"simserial\",\"openmrs_entity_id\":\"163151AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"phonenumber\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_data_type\":\"phonenumber\",\"openmrs_entity_id\":\"163152AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},\"encounter_location\":\"\",\"look_up\":{\"entity_id\":\"\",\"value\":\"\"}},\"step1\":{\"title\":\"Basic Form One\",\"next\":\"step2\",\"fields\":[{\"key\":\"user_image\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"choose_image\",\"uploadButtonText\":\"Take a photo of the child\"},{\"key\":\"thumbnail\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"image_view\",\"uploadButtonText\":\"Take a photo of the child\"},{\"key\":\"user_first_name\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"edit_text\",\"hint\":\"User First name\",\"edit_type\":\"name\",\"v_required\":{\"value\":\"true\",\"err\":\"Please enter the first name\"},\"v_regex\":{\"value\":\"[A-Za-z\\\\s\\\\.\\\\-]*\",\"err\":\"Please enter a valid name\"}},{\"key\":\"user_last_name\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"normal_edit_text\",\"hint\":\"User Last name\",\"edit_type\":\"name\",\"v_required\":{\"value\":\"true\",\"err\":\"Please enter the last name\"},\"v_regex\":{\"value\":\"[A-Za-z\\\\s\\\\.\\\\-]*\",\"err\":\"Please enter a valid name\"}},{\"key\":\"user_qr_code\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"barcode\",\"barcode_type\":\"qrcode\",\"hint\":\"User ID\",\"scanButtonText\":\"Scan QR Code\",\"v_numeric\":{\"value\":\"true\",\"err\":\"Please enter a valid ID\"},\"v_required\":{\"value\":false,\"err\":\"Please enter the user ID\"}},{\"key\":\"user_age\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"edit_text\",\"hint\":\"User age\",\"edit_type\":\"number\",\"v_required\":{\"value\":\"true\",\"err\":\"Please enter user age\"}},{\"key\":\"user_gps\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"openmrs_data_type\":\"text\",\"type\":\"gps\"},{\"key\":\"user_calculation_one\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_entity_id\":\"165260AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\"type\":\"hidden\"},{\"key\":\"user_spinner\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"spinner\",\"hint\":\"User Spinners\",\"values\":[\"User Option One\",\"User Option Two\"],\"keys\":[\"user_option_one\",\"user_option_two\"],\"v_required\":{\"value\":\"true\",\"err\":\"Please enter the sex\"},\"openmrs_choice_ids\":{\"user_one\":\"1107AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\"user_two\":\"1713AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"}},{\"key\":\"user_check_box\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"openmrs_data_type\":\"select one\",\"type\":\"check_box\",\"label\":\"Do want to select any checkbox?\",\"label_text_style\":\"bold\",\"options\":[{\"key\":\"None\",\"text\":\"None\",\"value\":false,\"openmrs_choice_id\":\"\"},{\"key\":\"yes\",\"text\":\"Yes\",\"value\":false,\"openmrs_choice_id\":\"\"},{\"key\":\"no\",\"text\":\"No\",\"value\":false,\"openmrs_choice_id\":\"\"},{\"key\":\"other\",\"text\":\"Other\",\"value\":false,\"openmrs_choice_id\":\"\"}],\"v_required\":{\"value\":\"true\"}}]},\"step2\":{\"title\":\"Basic Form Two\",\"next\":\"step3\",\"fields\":[{\"key\":\"user_select\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"native_radio\",\"label\":\"Do you want to select anything\",\"label_text_style\":\"bold\",\"text_color\":\"#000000\",\"label_info_text\":\"You can select every thing you want.\",\"label_info_title\":\"User selection\",\"options\":[{\"key\":\"yes\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"text\":\"Yes\"},{\"key\":\"no\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"text\":\"No\"}]},{\"key\":\"user_normal_edit_text\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"normal_edit_text\",\"hint\":\"User Text \",\"edit_text_style\":\"bordered\"},{\"key\":\"user_normal_edit_number\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"normal_edit_text\",\"hint\":\"User number\",\"edit_text_style\":\"bordered\",\"edit_type\":\"number\"},{\"key\":\"user_toaster_problem\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"toaster_notes\",\"text\":\"User problem toaster\",\"toaster_info_text\":\"Procedure:\\n- This shows the user the problems.\\n- Problem toaster.\",\"toaster_type\":\"problem\"},{\"key\":\"user_toaster_warning\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"toaster_notes\",\"text\":\"User warning toaster\",\"toaster_info_text\":\"Procedure:\\n- This shows the user the warning.\\n- Warning toaster.\",\"toaster_type\":\"warning\"},{\"key\":\"user_toaster_positive\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"toaster_notes\",\"text\":\"User positive toaster\",\"toaster_info_text\":\"Procedure:\\n- This shows the user the positive.\\n- Positive toaster.\",\"toaster_type\":\"positive\"},{\"key\":\"user_toaster_info\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"toaster_notes\",\"text\":\"User Info toaster\",\"toaster_info_text\":\"Procedure:\\n- This shows the user the info.\\n- Info toaster.\",\"toaster_type\":\"info\"}]},\"step3\":{\"title\":\"Basic Form Threes\",\"fields\":[{\"key\":\"user_date\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"date_picker\",\"hint\":\"User DOB\",\"expanded\":false,\"duration\":{\"label\":\"Age\"},\"default\":\"12-12-2015\",\"min_date\":\"today-5y\",\"max_date\":\"today\",\"v_required\":{\"value\":\"true\",\"err\":\"Please enter the date of birth\"}},{\"key\":\"user_time\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"time_picker\",\"hint\":\"Birth Time\",\"expanded\":false,\"duration\":{\"label\":\"Birth Time\"},\"v_required\":{\"value\":true,\"err\":\"Please enter the time of birth\"}},{\"key\":\"user_spinner\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"spinner\",\"hint\":\"User Spinners\",\"values\":[\"User Option One\",\"User Option Two\"],\"keys\":[\"user_option_one\",\"user_option_two\"],\"v_required\":{\"value\":\"true\",\"err\":\"Please enter the sex\"},\"openmrs_choice_ids\":{\"user_one\":\"1107AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\"user_two\":\"1713AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"}},{\"key\":\"spacer\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"spacer\",\"type\":\"spacer\",\"spacer_height\":\"20dp\"},{\"key\":\"user_form_labels\",\"type\":\"label\",\"label_text_style\":\"bold\",\"text\":\"Number of labels\",\"text_color\":\"#000000\",\"v_required\":{\"value\":true}},{\"key\":\"user_form\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"numbers_selector\",\"number_of_selectors\":\"5\",\"start_number\":\"1\",\"max_value\":\"15\",\"text_size\":\"16px\",\"text_color\":\"#000000\",\"selected_text_color\":\"#ffffff\",\"v_required\":{\"value\":true}},{\"key\":\"spacer\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"spacer\",\"type\":\"spacer\",\"spacer_height\":\"20dp\"},{\"key\":\"user_sub_form\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"native_radio\",\"label\":\"User sub forms?\",\"label_text_style\":\"bold\",\"text_color\":\"#000000\",\"extra_rel\":true,\"has_extra_rel\":\"yes\",\"options\":[{\"key\":\"yes\",\"text\":\"Yes\",\"value\":false,\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"specify_info\":\"User sub specify...\",\"specify_widget\":\"normal_edit_text\",\"specify_info_color\":\"#8C8C8C\",\"secondary_suffix\":\"bpm\",\"content_form\":\"user_native_sub_form\"},{\"key\":\"no\",\"text\":\"No\",\"value\":false,\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\"}],\"v_required\":{\"value\":true,\"err\":\"Please specify user native form.\"}},{\"key\":\"user_check_box\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"openmrs_data_type\":\"select one\",\"type\":\"check_box\",\"label\":\"Do want to select any checkbox?\",\"label_text_style\":\"bold\",\"options\":[{\"key\":\"None\",\"text\":\"None\",\"value\":false,\"openmrs_choice_id\":\"\"},{\"key\":\"yes\",\"text\":\"Yes\",\"value\":false,\"openmrs_choice_id\":\"\"},{\"key\":\"no\",\"text\":\"No\",\"value\":false,\"openmrs_choice_id\":\"\"},{\"key\":\"other\",\"text\":\"Other\",\"value\":false,\"openmrs_choice_id\":\"\"}],\"v_required\":{\"value\":\"false\"},\"value\":\"[yes]\"}]}}"; } diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java index 5d49dbcda..28f08eaa0 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java @@ -3,10 +3,12 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.support.v7.widget.AppCompatSpinner; import android.view.View; import android.widget.TextView; import com.vijay.jsonwizard.BaseTest; +import com.vijay.jsonwizard.R; import com.vijay.jsonwizard.TestConstants; import com.vijay.jsonwizard.activities.JsonFormActivity; import com.vijay.jsonwizard.constants.JsonFormConstants; @@ -44,6 +46,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -203,4 +206,31 @@ public void testValidateAndWriteValuesWithInvalidFields() { verify(onFieldsInvalid).passInvalidFields(presenter.getInvalidFields()); } + + @Test + public void testValidateAndWriteValues() { + initWithActualForm(); + presenter.validateAndWriteValues(); + assertEquals(4, presenter.getInvalidFields().size()); + + + setTextValue("step1:user_last_name", "Doe"); + setTextValue("step1:user_first_name", "John"); + setTextValue("step1:user_age", "21"); + ((AppCompatSpinner) formFragment.getJsonApi().getFormDataView("step1:user_spinner")).setSelection(1); + formFragment.onFieldsInvalid = this.onFieldsInvalid; + presenter.validateAndWriteValues(); + assertEquals(0, presenter.getInvalidFields().size()); + verify(formFragment, times(13)).writeValue(anyString(), anyString(), anyString(), anyString(), anyString(), + anyString(), anyBoolean()); + verify(onFieldsInvalid).passInvalidFields(presenter.getInvalidFields()); + } + + private void setTextValue(String address, String value) { + TextView view= (TextView) formFragment.getJsonApi().getFormDataView(address); + view.setTag(R.id.raw_value, value); + view.setText(value); + + } + } From 87b33e61ea65e6aa96e29f109ca777c45602746e Mon Sep 17 00:00:00 2001 From: Samuel Githengi Date: Tue, 10 Mar 2020 11:57:20 +0300 Subject: [PATCH 3/5] Unit test clicking save show error dialog and display toast with invalid fields --- ...FormFragmentPresenterRoboElectricTest.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java index 28f08eaa0..53abc1c29 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java @@ -6,6 +6,7 @@ import android.support.v7.widget.AppCompatSpinner; import android.view.View; import android.widget.TextView; +import android.widget.Toast; import com.vijay.jsonwizard.BaseTest; import com.vijay.jsonwizard.R; @@ -31,6 +32,7 @@ import org.powermock.reflect.Whitebox; import org.robolectric.Robolectric; import org.robolectric.RuntimeEnvironment; +import org.robolectric.shadows.ShadowToast; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -41,6 +43,7 @@ import static com.vijay.jsonwizard.constants.JsonFormConstants.STEP1; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyString; @@ -103,6 +106,7 @@ private void initWithActualForm() { intent.putExtra("json", TestConstants.BASIC_FORM); jsonFormActivity = spy(Robolectric.buildActivity(JsonFormActivity.class, intent).create().resume().get()); formFragment = spy(JsonFormFragment.getFormFragment("step1")); + formFragment.onFieldsInvalid = this.onFieldsInvalid; jsonFormActivity.getSupportFragmentManager().beginTransaction().add(formFragment, null).commit(); presenter = formFragment.getPresenter(); } @@ -194,7 +198,6 @@ public void testOnNextClickReturnsFalseIfFormIsInvalid() { @Test public void testValidateAndWriteValuesWithInvalidFields() { initWithActualForm(); - formFragment.onFieldsInvalid = this.onFieldsInvalid; presenter.validateAndWriteValues(); assertEquals(4, presenter.getInvalidFields().size()); assertEquals("Please enter the last name", presenter.getInvalidFields().get("step1#Basic Form One:user_last_name").getErrorMessage()); @@ -218,7 +221,6 @@ public void testValidateAndWriteValues() { setTextValue("step1:user_first_name", "John"); setTextValue("step1:user_age", "21"); ((AppCompatSpinner) formFragment.getJsonApi().getFormDataView("step1:user_spinner")).setSelection(1); - formFragment.onFieldsInvalid = this.onFieldsInvalid; presenter.validateAndWriteValues(); assertEquals(0, presenter.getInvalidFields().size()); verify(formFragment, times(13)).writeValue(anyString(), anyString(), anyString(), anyString(), anyString(), @@ -227,10 +229,30 @@ public void testValidateAndWriteValues() { } private void setTextValue(String address, String value) { - TextView view= (TextView) formFragment.getJsonApi().getFormDataView(address); + TextView view = (TextView) formFragment.getJsonApi().getFormDataView(address); view.setTag(R.id.raw_value, value); view.setText(value); } + + @Test + public void testOnSaveClickDisplaysErrorFragmentAndDisplaysToast() { + initWithActualForm(); + formFragment.getMainView().setTag(R.id.skip_validation, false); + presenter.onSaveClick(formFragment.getMainView()); + assertEquals(4, presenter.getInvalidFields().size()); + assertEquals("Please enter the last name", presenter.getInvalidFields().get("step1#Basic Form One:user_last_name").getErrorMessage()); + assertEquals("Please enter user age", presenter.getInvalidFields().get("step1#Basic Form One:user_age").getErrorMessage()); + assertEquals("Please enter the first name", presenter.getInvalidFields().get("step1#Basic Form One:user_first_name").getErrorMessage()); + assertEquals("Please enter the sex", presenter.getInvalidFields().get("step1#Basic Form One:user_spinner").getErrorMessage()); + verify(formFragment, times(6)).writeValue(anyString(), anyString(), anyString(), anyString(), anyString(), + anyString(), anyBoolean()); + assertTrue(presenter.getErrorFragment().isVisible()); + Toast toast = ShadowToast.getLatestToast(); + assertEquals(Toast.LENGTH_SHORT, toast.getDuration()); + assertEquals(context.getString(R.string.json_form_error_msg, 4), ShadowToast.getTextOfLatestToast()); + } + + } From f467cc1f964148954d405079c7350fb05fd5686d Mon Sep 17 00:00:00 2001 From: Samuel Githengi Date: Tue, 10 Mar 2020 12:03:20 +0300 Subject: [PATCH 4/5] Code cleanup --- .../presenters/JsonFormFragmentPresenterRoboElectricTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java index 53abc1c29..36553ec53 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java @@ -49,7 +49,6 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; -import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; From 1223395ef4e57489e5b5d9e250bad6cf5588c596 Mon Sep 17 00:00:00 2001 From: Samuel Githengi Date: Tue, 10 Mar 2020 12:25:10 +0300 Subject: [PATCH 5/5] Update failing unit tests --- .../presenters/JsonFormFragmentPresenterRoboElectricTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java index 36553ec53..43668144b 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenterRoboElectricTest.java @@ -105,8 +105,8 @@ private void initWithActualForm() { intent.putExtra("json", TestConstants.BASIC_FORM); jsonFormActivity = spy(Robolectric.buildActivity(JsonFormActivity.class, intent).create().resume().get()); formFragment = spy(JsonFormFragment.getFormFragment("step1")); - formFragment.onFieldsInvalid = this.onFieldsInvalid; jsonFormActivity.getSupportFragmentManager().beginTransaction().add(formFragment, null).commit(); + formFragment.onFieldsInvalid = this.onFieldsInvalid; presenter = formFragment.getPresenter(); } @@ -224,7 +224,7 @@ public void testValidateAndWriteValues() { assertEquals(0, presenter.getInvalidFields().size()); verify(formFragment, times(13)).writeValue(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyBoolean()); - verify(onFieldsInvalid).passInvalidFields(presenter.getInvalidFields()); + verify(onFieldsInvalid,times(2)).passInvalidFields(presenter.getInvalidFields()); } private void setTextValue(String address, String value) {