Skip to content

Commit

Permalink
Test DatePickerDialog 'okbutton' click
Browse files Browse the repository at this point in the history
  • Loading branch information
LZRS committed Mar 2, 2023
1 parent 3f72b03 commit 0b69e87
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.content.DialogInterface;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -27,6 +29,10 @@

public class DatePickerDialog extends DialogFragment {
private DatePicker datePicker;

private Button okButton;

private Button cancelButton;
private android.app.DatePickerDialog.OnDateSetListener onDateSetListener;
private DialogInterface.OnShowListener onShowListener;
private Date date;
Expand Down Expand Up @@ -67,9 +73,6 @@ public void setOnShowListener(DialogInterface.OnShowListener onShowListener_) {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup dialogView = (ViewGroup) inflater.inflate(R.layout.native_form_dialog_date_picker, container, false);

Button cancelButton;
Button okButton;

setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Expand Down Expand Up @@ -179,4 +182,14 @@ public DatePicker getDatePicker() {
public void setNumericDatePicker(boolean numericDatePicker) {
isNumericDatePicker = numericDatePicker;
}

@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
public Button getOkButton(){
return okButton;
}

@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
public Button getCancelButton(){
return cancelButton;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1138,28 +1138,30 @@ public JSONArray getSecondaryValues(JSONObject jsonObject, String type) {
*/
public JSONArray getFormFields(String stepName, Context context) {
Activity activity = (Activity) context;
JsonApi jsonApi = (JsonApi) activity;
JSONArray fields = new JSONArray();
JSONObject mJSONObject = jsonApi.getmJSONObject();
if (mJSONObject != null) {
JSONObject parentJson = jsonApi.getStep(stepName);
try {
if (parentJson.has(JsonFormConstants.SECTIONS) && parentJson
.get(JsonFormConstants.SECTIONS) instanceof JSONArray) {
JSONArray sections = parentJson.getJSONArray(JsonFormConstants.SECTIONS);
for (int i = 0; i < sections.length(); i++) {
JSONObject sectionJson = sections.getJSONObject(i);
if (sectionJson.has(JsonFormConstants.FIELDS)) {
fields = concatArray(fields, sectionJson.getJSONArray(JsonFormConstants.FIELDS));
if (activity instanceof JsonApi) {
JsonApi jsonApi = (JsonApi) activity;
JSONObject mJSONObject = jsonApi.getmJSONObject();
if (mJSONObject != null) {
JSONObject parentJson = jsonApi.getStep(stepName);
try {
if (parentJson.has(JsonFormConstants.SECTIONS) && parentJson
.get(JsonFormConstants.SECTIONS) instanceof JSONArray) {
JSONArray sections = parentJson.getJSONArray(JsonFormConstants.SECTIONS);
for (int i = 0; i < sections.length(); i++) {
JSONObject sectionJson = sections.getJSONObject(i);
if (sectionJson.has(JsonFormConstants.FIELDS)) {
fields = concatArray(fields, sectionJson.getJSONArray(JsonFormConstants.FIELDS));
}
}
}
} else if (parentJson.has(JsonFormConstants.FIELDS) && parentJson
.get(JsonFormConstants.FIELDS) instanceof JSONArray) {
fields = parentJson.getJSONArray(JsonFormConstants.FIELDS);
} else if (parentJson.has(JsonFormConstants.FIELDS) && parentJson
.get(JsonFormConstants.FIELDS) instanceof JSONArray) {
fields = parentJson.getJSONArray(JsonFormConstants.FIELDS);

}
} catch (JSONException e) {
Timber.e(e);
}
} catch (JSONException e) {
Timber.e(e);
}
}
return fields;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import static com.vijay.jsonwizard.presenters.JsonFormFragmentPresenter.RESULT_LOAD_IMG;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
Expand Down Expand Up @@ -182,6 +183,10 @@ public void testOnClickShouldDisplayDatePickerDialog() throws InterruptedExcepti
dialogFragment = (DatePickerDialog) fragmentManager.findFragmentByTag(NativeRadioButtonFactory.TAG);
}
assertNotNull(dialogFragment);

View okButton = dialogFragment.getOkButton();
okButton.performClick();
assertTrue(radioButton.getText().length() > 0);
}

}

0 comments on commit 0b69e87

Please sign in to comment.