|
5 | 5 | import com.vijay.jsonwizard.R;
|
6 | 6 | import com.vijay.jsonwizard.constants.JsonFormConstants;
|
7 | 7 |
|
| 8 | +import org.jeasy.rules.api.Facts; |
| 9 | +import org.json.JSONObject; |
8 | 10 | import org.junit.Assert;
|
9 | 11 | import org.junit.Before;
|
10 | 12 | import org.junit.Test;
|
11 | 13 | import org.mockito.MockitoAnnotations;
|
| 14 | +import org.powermock.reflect.Whitebox; |
12 | 15 | import org.robolectric.Robolectric;
|
13 | 16 | import org.robolectric.RuntimeEnvironment;
|
14 | 17 | import org.robolectric.android.controller.ActivityController;
|
15 | 18 |
|
16 | 19 | public class JsonFormActivityTest extends BaseActivityTest {
|
17 |
| - |
18 | 20 | private JsonFormActivity activity;
|
19 | 21 | private ActivityController<JsonFormActivity> controller;
|
20 | 22 |
|
@@ -47,4 +49,33 @@ public void testSetConfirmationMessageUpdatesConfirmationMessageCorrectly() {
|
47 | 49 | activity.setConfirmCloseMessage(DUMMY_TEST_STRING);
|
48 | 50 | Assert.assertEquals(DUMMY_TEST_STRING, activity.getConfirmCloseMessage());
|
49 | 51 | }
|
| 52 | + |
| 53 | + @Test |
| 54 | + public void testGetValueFromAddressCoreForEditTexts() throws Exception { |
| 55 | + JSONObject jsonObject = new JSONObject("{\"key\":\"pregest_weight\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"person\",\"openmrs_entity_id\":\"5090\",\"type\":\"normal_edit_text\",\"edit_text_style\":\"bordered\",\"edit_type\":\"number\",\"relevance\":{\"step1:pregest_weight_unknown\":{\"ex-checkbox\":[{\"not\":[\"pregest_weight_unknown\"]}]}},\"v_numeric\":{\"value\":\"true\",\"err\":\"\"},\"v_min\":{\"value\":\"30\",\"err\":\"Weight must be equal or greater than 30\"},\"v_max\":{\"value\":\"180\",\"err\":\"Weight must be equal or less than 180\"},\"v_required\":{\"value\":\"true\",\"err\":\"Pre-gestational weight is required\"},\"step\":\"step1\",\"is-rule-check\":true}"); |
| 56 | + Facts facts = Whitebox.invokeMethod(activity, "getValueFromAddressCore", jsonObject); |
| 57 | + Assert.assertNotNull(facts); |
| 58 | + Assert.assertTrue(facts.asMap().containsKey("step1_pregest_weight")); |
| 59 | + Assert.assertEquals(0, facts.asMap().get("step1_pregest_weight")); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public void testGetValueFromAddressCoreForRadioButtons() throws Exception { |
| 64 | + JSONObject jsonObject = new JSONObject("{\"key\":\"blood_type_test_status\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_entity_id\":\"165383AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\"label\":\"Blood type test\",\"label_text_style\":\"bold\",\"text_color\":\"#000000\",\"type\":\"extended_radio_button\",\"options\":[{\"key\":\"done_today\",\"text\":\"Done today\",\"type\":\"done_today\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_entity_id\":\"165383AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},{\"key\":\"done_earlier\",\"text\":\"Done earlier\",\"type\":\"done_earlier\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_entity_id\":\"165385AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},{\"key\":\"ordered\",\"text\":\"Ordered\",\"type\":\"ordered\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_entity_id\":\"165384AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"},{\"key\":\"not_done\",\"text\":\"Not done\",\"type\":\"not_done\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"concept\",\"openmrs_entity_id\":\"1118AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"}],\"v_required\":{\"value\":true,\"err\":\"Blood type status is required\"},\"index\":\"0\",\"step\":\"step1\",\"is-rule-check\":true,\"value\":\"done_today\"}"); |
| 65 | + Facts facts = Whitebox.invokeMethod(activity, "getValueFromAddressCore", jsonObject); |
| 66 | + Assert.assertNotNull(facts); |
| 67 | + Assert.assertTrue(facts.asMap().containsKey("step1_blood_type_test_status")); |
| 68 | + Assert.assertEquals("done_today", facts.asMap().get("step1_blood_type_test_status")); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void testGetValueFromAddressCoreForCheckBoxes() throws Exception{ |
| 73 | + JSONObject jsonObject = new JSONObject("{\"key\":\"respiratory_exam_abnormal\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"check_box\",\"label\":\"Abnormal\",\"label_text_style\":\"bold\",\"text_color\":\"#000000\",\"options\":[{\"key\":\"rapid_breathing\",\"text\":\"Rapid breathing\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"TACHYPNEA\",\"openmrs_entity_id\":\"125061\",\"value\":true},{\"key\":\"slow_breathing\",\"text\":\"Slow breathing\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"value\":false},{\"key\":\"other\",\"text\":\"Other (specify)\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"value\":false}],\"value\":[\"rapid_breathing\"],\"is-rule-check\":false}"); |
| 74 | + Facts facts = Whitebox.invokeMethod(activity,"getValueFromAddressCore", jsonObject); |
| 75 | + Assert.assertNotNull(facts); |
| 76 | + Assert.assertTrue(facts.asMap().containsKey("slow_breathing")); |
| 77 | + Assert.assertEquals("false",facts.asMap().get("slow_breathing")); |
| 78 | + Assert.assertTrue(facts.asMap().containsKey("rapid_breathing")); |
| 79 | + Assert.assertEquals("true",facts.asMap().get("rapid_breathing")); |
| 80 | + } |
50 | 81 | }
|
0 commit comments