Skip to content

Commit

Permalink
Updating PR per review -1
Browse files Browse the repository at this point in the history
  • Loading branch information
SebaMutuku committed Jul 5, 2022
1 parent bbd309a commit b5c622c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Run unit tests with Gradle
run: ./gradlew android-json-form-wizard:clean && ./gradlew android-json-form-wizard:build && ./gradlew android-json-form-wizard:jacocoTestReport --stacktrace -Dorg.gradle.jvmargs="-Xmx4096m -XX:+HeapDumpOnOutOfMemoryError"
run: ./gradlew android-json-form-wizard:clean :android-json-form-wizard:build :android-json-form-wizard:jacocoTestReport --stacktrace -Dorg.gradle.jvmargs="-Xmx4096m -XX:+HeapDumpOnOutOfMemoryError"
- name: Upload coverage to Coveralls with Gradle
run: ./gradlew coveralls --stacktrace
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,7 @@ private ArrayList<View> addCheckBoxOptionsElements(Boolean readOnly,
@Override
public void run() {
if (StringUtils.isNotEmpty(item.optString(JsonFormConstants.VALUE))) {
widgetArgs.getFormFragment().getJsonApi().getAppExecutors().mainThread().execute(new Runnable() {
@Override
public void run() {
checkBox.setChecked(Boolean.parseBoolean(item.optString(JsonFormConstants.VALUE)));
}
});
widgetArgs.getFormFragment().getJsonApi().getAppExecutors().mainThread().execute(() -> checkBox.setChecked(Boolean.parseBoolean(item.optString(JsonFormConstants.VALUE))));
} else {
//Preselect values if they exist
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.vijay.jsonwizard.BaseTest;
Expand Down Expand Up @@ -714,13 +716,13 @@ public void testShowGenericDialogShouldInvokeExpectedMethods() {
Mockito.verify(mainLayout, Mockito.only()).clearFocus();
Mockito.verify(mockFragmentTransaction).add(ArgumentMatchers.any(DialogFragment.class), ArgumentMatchers.eq("GenericPopup"));
}

@Test
public void testGetDynamicLabelInfoList() throws JSONException {
JSONArray jsonArray = new JSONArray("[{\"dynamic_label_title\": \"sample title\",\"dynamic_label_text\": \"sample text\",\"dynamic_label_image_src\": \"img/img.png\"}]");
ArrayList<DynamicLabelInfo> expectedList = new ArrayList<>();
expectedList.add(new DynamicLabelInfo("sample title", "sample text", "img/img.png"));
ArrayList<DynamicLabelInfo> actualList = FormUtils.getDynamicLabelInfoList(jsonArray);
ArrayList<DynamicLabelInfo> actualList = FormUtils.getDynamicLabelInfoList(jsonArray);
Assert.assertEquals(expectedList.get(0).getDynamicLabelText(), actualList.get(0).getDynamicLabelText());
Assert.assertEquals(expectedList.get(0).getDynamicLabelTitle(), actualList.get(0).getDynamicLabelTitle());
Assert.assertEquals(expectedList.get(0).getDynamicLabelImageSrc(), actualList.get(0).getDynamicLabelImageSrc());
Expand All @@ -732,9 +734,48 @@ public void testCreateOptiBPDataObject() throws JSONException {

Assert.assertEquals(inputJson.toString(), "{\"clientId\":\"clientId\",\"clientOpenSRPId\":\"clientOpenSRPId\"}");
}

public void testSetEditModeShouldShowEditBtnAndDisableEditableView() throws JSONException {
View editableView = Mockito.mock(View.class);
ImageView editButton = Mockito.mock(ImageView.class);

JSONObject jsonObject = new JSONObject();
jsonObject.put(JsonFormConstants.EDITABLE, true);
FormUtils.setEditMode(jsonObject, editableView, editButton);

Mockito.verify(editableView).setEnabled(ArgumentMatchers.eq(false));
Mockito.verify(editButton).setVisibility(ArgumentMatchers.eq(View.VISIBLE));

}

@Test
public void testSetEditModeShouldHideEditBtn() throws JSONException {
View editableView = Mockito.mock(View.class);
ImageView editButton = Mockito.mock(ImageView.class);

JSONObject jsonObject = new JSONObject();
jsonObject.put(JsonFormConstants.EDITABLE, false);
FormUtils.setEditMode(jsonObject, editableView, editButton);

Mockito.verify(editButton).setVisibility(ArgumentMatchers.eq(View.GONE));
}

@Test
public void testSetEditModeShouldHideEditBtnAndDisableEditableViewIfReadOnlySet() throws JSONException {
View editableView = Mockito.mock(View.class);
ImageView editButton = Mockito.mock(ImageView.class);

JSONObject jsonObject = new JSONObject();
jsonObject.put(JsonFormConstants.READ_ONLY, false);
FormUtils.setEditMode(jsonObject, editableView, editButton);

Mockito.verify(editButton).setVisibility(ArgumentMatchers.eq(View.GONE));
Mockito.verify(editableView).setEnabled(ArgumentMatchers.eq(true));
}

@Test
public void testUpdateValueToJsonArray() throws Exception {
FormUtils mockedFormUtils=Mockito.mock(FormUtils.class);
FormUtils mockedFormUtils = Mockito.mock(FormUtils.class);
String item = "{\n" +
" \"key\": \"resThree3\",\n" +
" \"text\": \"Abnormal\",\n" +
Expand All @@ -749,6 +790,13 @@ public void testUpdateValueToJsonArray() throws Exception {
NativeFormsProperties mockedNativeProps = Mockito.mock(NativeFormsProperties.class);
Mockito.when(mockedNativeProps.isTrue(NativeFormsProperties.KEY.WIDGET_VALUE_TRANSLATED)).thenReturn(true);
Mockito.verify(mockedFormUtils, Mockito.times(0)).updateValueToJSONArray(new JSONObject(item), new JSONObject(item).optString(JsonFormConstants.VALUE));
}

@Test
public void testGetRadioButtonTextShouldReturnText() throws JSONException {
String field = "{\"key\":\"fetal_heartbeat\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"native_radio\",\"label\":\"Which medications is she still taking ? Which medications is she still taking ?\",\"label_text_style\":\"bold\",\"text_color\":\"#000000\",\"extra_rel\":true,\"has_extra_rel\":\"yes\",\"options\":[{\"key\":\"yes\",\"text\":\"Yes\"},{\"key\":\"no\",\"text\":\"No\"}]}";
JSONObject jsonObject = new JSONObject(field);
String result = formUtils.getRadioButtonText(jsonObject, "yes");
Assert.assertEquals(result, "Yes");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,22 @@ public void testResourceBundleWithPropertiesFromDbIsEmptyWhenClientFormDoesntExi
public void testGetDatabaseString() {
String stringToTranslate = "form_strings.step1.danger_signs.danger_bleeding.text";
String expected_string = "Danger Bleeding";
String actual = "";
Locale locale = new Locale(Locale.ENGLISH.getLanguage());
ResourceBundle bundle = ResourceBundle.getBundle("form_strings", locale);
boolean keyIsFound = bundle.containsKey(stringToTranslate);
Assert.assertTrue(keyIsFound);
actual = NativeFormLangUtils.translateDatabaseString(stringToTranslate, context);
String actual = NativeFormLangUtils.translateDatabaseString(stringToTranslate, context);
assertEquals(expected_string, actual);

}
@Test
public void testInvalidDatabaseString() {
String stringToTranslate = "form_strings.step2.danger_signs.danger_bleeding.text";
String actual = "";
Locale locale = new Locale(Locale.ENGLISH.getLanguage());
ResourceBundle bundle = ResourceBundle.getBundle("form_strings", locale);
boolean keyIsFound = bundle.containsKey(stringToTranslate);
actual = NativeFormLangUtils.translateDatabaseString(stringToTranslate, context);
assertNotNull(actual);
String actual = NativeFormLangUtils.translateDatabaseString(stringToTranslate, context);
assertEquals("",actual);
assertFalse(keyIsFound);

}
Expand Down

0 comments on commit b5c622c

Please sign in to comment.