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

Tests for Contact Visit 1 #1005

Open
wants to merge 7 commits into
base: opensrp_client_anc_qa
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.smartregister.anc.activity.anc;

import static androidx.test.espresso.Espresso.closeSoftKeyboard;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.scrollTo;
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withSubstring;
import static androidx.test.espresso.matcher.ViewMatchers.withText;

import android.app.Activity;

import androidx.test.espresso.NoMatchingViewException;
import androidx.test.espresso.action.ViewActions;
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;

import com.vijay.jsonwizard.activities.JsonFormActivity;

import org.junit.FixMethodOrder;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.smartregister.anc.R;
import org.smartregister.anc.activity.LoginActivity;
import org.smartregister.anc.activity.utils.Configs;
import org.smartregister.anc.activity.utils.Constants;
import org.smartregister.anc.activity.utils.Utils;

@LargeTest
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@RunWith(AndroidJUnit4.class)
public class ContactsActivityTest {

@Rule
public ActivityScenarioRule<LoginActivity> mActivityScenario = new ActivityScenarioRule<>(LoginActivity.class);

private Utils utils = new Utils();

@Test
public void setUp() throws InterruptedException {
utils.logIn(Constants.ancConstants.ancUsername, Constants.ancConstants.ancPassword);
onView(withId(R.id.search_bar_layout)).check(matches(isDisplayed()));
}

@Test
public void startContactVisit() throws Throwable {

onView(withId(R.id.edt_search)).perform(typeText(Configs.TestDataConfigs.clientName), ViewActions.closeSoftKeyboard());
onView(withId(R.id.patient_name)).check(matches(isDisplayed()));

onView(withId(R.id.due_button_wrapper)).perform(click());
Thread.sleep(2000);

try {
onView(withText("Form Update")).check(matches(isDisplayed()));
onView(withText("OK")).perform(click());
Thread.sleep(2000);
} catch (NoMatchingViewException e) {
}
onView(withId(R.id.contact_title)).check(matches(isDisplayed()));
onView(withContentDescription("First contact"));
Activity activity = utils.getCurrentActivity();
onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:contact_reason"))).perform(click());
onView(withSubstring("First contact")).perform(click());
Thread.sleep(4000);
onView(withSubstring("None")).perform(click());
Thread.sleep(2000);
onView(withSubstring("PROCEED TO NORMAL CONTACT")).perform(click());;
Thread.sleep(2000);

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ public class Configs {


public static class TestDataConfigs{
public static final String clientName = "Lauren Hill";
public static final String clientID = "7138845";
public static final String clientName = "Las Mas";
public static final String clientID = "7226962";

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;

import androidx.test.espresso.core.internal.deps.guava.collect.Iterables;
import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry;
import androidx.test.runner.lifecycle.Stage;

import com.vijay.jsonwizard.activities.JsonFormActivity;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
Expand All @@ -27,6 +36,23 @@ public void logIn(String username, String password) throws InterruptedException
Thread.sleep(30000);
}

public Activity getCurrentActivity() throws Throwable {
getInstrumentation().waitForIdleSync();
final Activity[] activity = new Activity[1];
runOnUiThread(() -> {
java.util.Collection<Activity> activities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
activity[0] = (Activity) Iterables.getOnlyElement(activities);
});
return activity[0];
}

public static int getViewId(JsonFormActivity jsonFormActivity, String key)
{
return jsonFormActivity.getFormDataView(key).getId();

}


// public static Matcher<View> withRecyclerViewId(final int recyclerViewId) {
// return new TypeSafeMatcher<View>() {
// @Override
Expand Down