diff --git a/gradle/gradle-wrapper.properties b/gradle/gradle-wrapper.properties new file mode 100644 index 000000000..59da85f2f --- /dev/null +++ b/gradle/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Feb 17 10:54:24 EAT 2021 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java new file mode 100644 index 000000000..64d8aa69a --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java @@ -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 mActivityScenario = new ActivityScenarioRule<>(LoginActivity.class); + + private Utils utils = new Utils(); + + @Test + public void A_setUp() throws InterruptedException { + utils.logIn(Constants.ancConstants.ancUsername, Constants.ancConstants.ancPassword); + } + + @Test + public void B_StartContactVisit() throws Throwable { + +// Thread.sleep(2000); + + 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); + } +} + diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ProfileContainerTest.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ProfileContainerTest.java new file mode 100644 index 000000000..47bf8bfbb --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ProfileContainerTest.java @@ -0,0 +1,174 @@ +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.doubleClick; +import static androidx.test.espresso.action.ViewActions.longClick; +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.withSpinnerText; +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.espresso.contrib.PickerActions; +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.AfterClass; +import org.junit.Before; +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 ProfileContainerTest { + + @Rule + public ActivityScenarioRule mActivityScenario = new ActivityScenarioRule<>(LoginActivity.class); + + private Utils utils = new Utils(); + + @Before + public void A_setUp() throws InterruptedException { + utils.logIn(Constants.ancConstants.ancUsername, Constants.ancConstants.ancPassword); + Thread.sleep(1000); + } + + @Test + public void B_StartContactVisitAndNavigateToProfile() 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); + + onView(withSubstring("Profile")).perform(click()); + Thread.sleep(2000); + + onView(withText("Demographic Info")).check(matches(isDisplayed())); + onView(withText("Primary")).perform(click()); + onView(withText("Married or living together")).perform(scrollTo(), click()); + onView(withText("Formal employment")).perform(scrollTo(), click()); + onView(withText("NEXT")).perform(scrollTo(), click()); + +// Skip Current Pregnancy page and navigate to Obstetric History + onView(withText("Current Pregnancy")).check(matches(isDisplayed())); + onView(withId(R.id.next_icon)).perform(click()); + Thread.sleep(2000); + +// onView(withText("Current Pregnancy")).check(matches(isDisplayed())); +// onView(withSubstring("specify date")).perform(click()); +// onView(withId(R.id.date_picker)).perform(PickerActions.setDate(2024, 02,07)); +// Thread.sleep(1000); +// onView(withText("DONE")).perform(click()); +// Thread.sleep(1000); +// +// +// Activity activity = utils.getCurrentActivity(); +// onView(withSubstring("ultrasound date")).perform(scrollTo(), click()); +// onView(withId(R.id.date_picker)).perform(PickerActions.setDate(2024, 04,24)); +// Thread.sleep(1000); +// onView(withText("DONE")).perform(click()); +// Thread.sleep(1000); +// +// +// onView(withId(Utils.getViewId((JsonFormActivity) activity, "step2:ultrasound_gest_age_wks"))).perform(scrollTo(), +// typeText("6"), ViewActions.closeSoftKeyboard()); +// Thread.sleep(1000); +// onView(withId(Utils.getViewId((JsonFormActivity) activity, "step2:ultrasound_gest_age_days"))).perform(scrollTo(), +// typeText("3"), ViewActions.closeSoftKeyboard()); +// Thread.sleep(1000); +// onView(withId(Utils.getViewId((JsonFormActivity) activity, "step2:ultrasound_gest_age_selection"))).perform(click()); +// Thread.sleep(3000); +// onView(withText("NEXT")).perform(scrollTo(), click()); +// Thread.sleep(1000); + + onView(withText("Obstetric History")).check(matches(isDisplayed())); + onView(withText("1")).perform(scrollTo(), click()); + onView(withText("NEXT")).perform(scrollTo(), click()); + Thread.sleep(2000); + + onView(withText("Medical History")).check(matches(isDisplayed())); + onView(withText("Any allergies?")).check(matches(isDisplayed())); + onView(withText("Calcium")).perform(scrollTo(), click()); + onView(withText("Any surgeries?")).check(matches(isDisplayed())); + onView(withId(R.id.scroll_view)).perform(ViewActions.swipeUp()); + onView(withText("Removal of ovarian cysts")).perform(scrollTo(), click()); + onView(withId(R.id.scroll_view)).perform(ViewActions.swipeUp()); + onView(withText("Any chronic or past health conditions?")).check(matches(isDisplayed())); + onView(withId(R.id.scroll_view)).perform(ViewActions.swipeUp()); + onView(withText("Hypertension")).perform(scrollTo(), click()); + + onView(withText("NEXT")).perform(scrollTo(), click()); + Thread.sleep(2000); + + onView(withText("Immunisation Status")).check(matches(isDisplayed())); + onView(withText("TTCV immunisation status")).check(matches(isDisplayed())); + onView(withText("Fully immunized")).perform(scrollTo(), click()); + onView(withText("Flu immunisation status")).check(matches(isDisplayed())); + onView(withText("No doses")).perform(scrollTo(), click()); + onView(withText("NEXT")).perform(scrollTo(), click()); + Thread.sleep(2000); + + onView(withText("Medications")).check(matches(isDisplayed())); + onView(withText("Antacids")).perform(scrollTo(), click()); + onView(withText("Aspirin")).perform(scrollTo(), click()); + onView(withId(R.id.scroll_view)).perform(ViewActions.swipeUp()); + onView(withText("Other antibiotics")).perform(scrollTo(), click()); + onView(withText("Asthma")).perform(scrollTo(), click()); + + onView(withText("NEXT")).perform(scrollTo(), click()); + Thread.sleep(2000); + + onView(withText("Woman's Behaviour")).check(matches(isDisplayed())); + onView(withText("Daily caffeine intake")).check(matches(isDisplayed())); + onView(withText("More than 2 cups of coffee (brewed, filtered, instant or espresso)")).perform(scrollTo(), click()); + onView(withText("Uses tobacco products?")).check(matches(isDisplayed())); + onView(withText("Yes")).perform(scrollTo(), click()); + onView(withText("Anyone in the household smokes tobacco products?")).check(matches(isDisplayed())); + onView(withText("Yes")).perform(scrollTo(), click()); + onView(withText("Uses (male or female) condoms during sex?")).check(matches(isDisplayed())); + onView(withText("Yes")).perform(scrollTo(), click()); + onView(withText("Clinical enquiry for alcohol and other substance use done?")).check(matches(isDisplayed())); + onView(withText("Yes")).perform(scrollTo(), click()); + onView(withText("Uses alcohol and/or other substances?")).check(matches(isDisplayed())); + onView(withText("None")).perform(scrollTo(), click()); + + onView(withText("NEXT")).perform(scrollTo(), click()); + Thread.sleep(2000); + + onView(withText("Partner's HIV Status")).check(matches(isDisplayed())); + onView(withText("Negative")).perform(scrollTo(), click()); + onView(withText("SUBMIT")).perform(scrollTo(), click()); + Thread.sleep(2000); + + } + @AfterClass + public static void tearDown() throws InterruptedException { + onView(withContentDescription("Me")).perform(click()); + onView(withId(R.id.logout_text)).perform(click()); + Thread.sleep(1500); + onView(withId(R.id.login_login_btn)).check(matches(isDisplayed())); + } +} diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ProfilePageTests.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ProfilePageTests.java index 82d5d2d22..e18deb469 100644 --- a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ProfilePageTests.java +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ProfilePageTests.java @@ -13,6 +13,7 @@ import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription; import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility; +import static androidx.test.espresso.matcher.ViewMatchers.withHint; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withTagValue; import static androidx.test.espresso.matcher.ViewMatchers.withText; @@ -157,8 +158,4 @@ public void L_LogOut() throws InterruptedException { } - - - - } diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Configs.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Configs.java index c8db85bde..1c9a85ded 100644 --- a/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Configs.java +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Configs.java @@ -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 = "Jill Jack"; + public static final String clientID = "7224447"; } } diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Utils.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Utils.java index e898a6fd1..035db0feb 100644 --- a/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Utils.java +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Utils.java @@ -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; @@ -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 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 withRecyclerViewId(final int recyclerViewId) { // return new TypeSafeMatcher() { // @Override