diff --git a/build.gradle b/build.gradle index 76d59302b..55b3ca57c 100644 --- a/build.gradle +++ b/build.gradle @@ -10,9 +10,9 @@ buildscript { maven{ url 'https://plugins.gradle.org/m2/' } } dependencies { - classpath 'com.android.tools.build:gradle:4.0.0' + classpath 'com.android.tools.build:gradle:4.0.2' classpath 'gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.12.0' - classpath 'com.palantir:jacoco-coverage:0.4.0' + classpath 'com.palantir.jacoco-coverage:com.palantir.jacoco-coverage.gradle.plugin:0.4.0' classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.11.0" classpath 'com.google.gms:google-services:4.3.5' classpath 'io.fabric.tools:gradle:1.31.2' diff --git a/libs/circleprogressbar-1.0.7.aar b/libs/circleprogressbar-1.0.7.aar new file mode 100644 index 000000000..1d729d579 Binary files /dev/null and b/libs/circleprogressbar-1.0.7.aar differ diff --git a/opensrp-anc/build.gradle b/opensrp-anc/build.gradle index 88bcf7a00..d0a0ef0f7 100644 --- a/opensrp-anc/build.gradle +++ b/opensrp-anc/build.gradle @@ -1,3 +1,6 @@ + + + buildscript { repositories { mavenCentral() @@ -181,6 +184,7 @@ tasks.withType(Test) { dependencies { implementation 'androidx.appcompat:appcompat:1.3.1' + implementation files('../libs/circleprogressbar-1.0.7.aar') implementation('org.smartregister:opensrp-client-native-form:3.1.1-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'recyclerview-v7' @@ -191,6 +195,7 @@ dependencies { exclude group: 'com.android.support', module: 'design' exclude group: 'org.yaml', module: 'snakeyaml' exclude group: 'io.ona.rdt-capture', module: 'lib' + exclude group: 'io.ona.CircleProgressbar', module: 'lib' } implementation('org.smartregister:opensrp-client-core:6.0.0-SNAPSHOT@aar') { transitive = true @@ -229,6 +234,7 @@ dependencies { implementation group: 'org.apache.commons', name: 'commons-text', version: '1.9' implementation 'junit:junit:4.12' implementation 'androidx.test:core:1.4.0' + testImplementation project(':opensrp-anc') annotationProcessor 'com.jakewharton:butterknife:10.2.3' implementation 'net.zetetic:android-database-sqlcipher:4.4.0@aar' implementation 'commons-validator:commons-validator:1.7' diff --git a/reference-app/build.gradle b/reference-app/build.gradle index 1165dd516..277ab0d02 100644 --- a/reference-app/build.gradle +++ b/reference-app/build.gradle @@ -39,18 +39,18 @@ android { * This allows you to run the app in the release variant. make sure to add this configs to the * local.properties files when you need to use them * */ - signingConfigs { - release { - //Store your local.properties file in the project root folder - v1SigningEnabled true - v2SigningEnabled true - keyAlias System.getenv("KEYSTORE_ALIAS") ?: project.KEYSTORE_ALIAS - keyPassword System.getenv("KEY_PASSWORD") ?: project.KEY_PASSWORD - storePassword System.getenv("KEYSTORE_PASSWORD") ?: project.KEYSTORE_PASSWORD - //Save your keystore file as ~/opensrp-release-upload-key.jks (in your home directory) - storeFile file(System.getProperty("user.home") + "/anckey.keystore.jks") - } - } + signingConfigs { + release { + //Store your local.properties file in the project root folder + v1SigningEnabled true + v2SigningEnabled true + keyAlias System.getenv("KEYSTORE_ALIAS") ?: project.KEYSTORE_ALIAS + keyPassword System.getenv("KEY_PASSWORD") ?: project.KEY_PASSWORD + storePassword System.getenv("KEYSTORE_PASSWORD") ?: project.KEYSTORE_PASSWORD + //Save your keystore file as ~/opensrp-release-upload-key.jks (in your home directory) + storeFile file(System.getProperty("user.home") + "/anckey.keystore.jks") + } + } useLibrary 'org.apache.http.legacy' compileSdkVersion androidCompileSdkVersion buildToolsVersion androidBuildToolsVersion @@ -224,9 +224,23 @@ tasks.withType(Test) { } dependencies { + + // AndroidX Test libraries + androidTestImplementation 'androidx.test:runner:1.5.2' + androidTestImplementation 'androidx.test:rules:1.5.0' + + // AndroidX Core testing libraries + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' + androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.3.0' + androidTestImplementation 'androidx.test.espresso:espresso-intents:3.4.0' + androidTestImplementation project(':reference-app') + debugImplementation "androidx.test:monitor:1.6.0" + androidTestImplementation 'androidx.test:core:1.4.0' coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' def powerMockVersion = '2.0.7' implementation project(":opensrp-anc") + implementation files('../libs/circleprogressbar-1.0.7.aar') implementation('org.smartregister:opensrp-client-native-form:3.1.1-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'recyclerview-v7' @@ -237,6 +251,7 @@ dependencies { exclude group: 'com.android.support', module: 'design' exclude group: 'org.yaml', module: 'snakeyaml' exclude group: 'io.ona.rdt-capture', module: 'lib' + exclude group: 'io.ona.CircleProgressbar', module: 'lib' } implementation('org.smartregister:opensrp-client-core:6.0.0-SNAPSHOT@aar') { @@ -299,8 +314,6 @@ dependencies { implementation 'de.hdodenhof:circleimageview:3.1.0' implementation 'org.jeasy:easy-rules-core:3.3.0' implementation 'org.jeasy:easy-rules-mvel:3.3.0' - implementation 'com.flurry.android:analytics:11.6.0@aar' - implementation 'com.flurry.android:analytics:11.6.0@aar' implementation 'androidx.multidex:multidex:2.0.1' // Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:28.3.1') diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/AdvancedSearchTests.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/AdvancedSearchTests.java new file mode 100644 index 000000000..320874b8c --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/AdvancedSearchTests.java @@ -0,0 +1,169 @@ +package org.smartregister.anc.activity.anc; + + +import static androidx.test.espresso.Espresso.onData; +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.swipeUp; +import static androidx.test.espresso.action.ViewActions.typeText; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom; +import static androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withClassName; +import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription; +import static androidx.test.espresso.matcher.ViewMatchers.withHint; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withParent; +import static androidx.test.espresso.matcher.ViewMatchers.withText; + +import static org.hamcrest.Matchers.anything; +import static org.hamcrest.core.AllOf.allOf; + +import android.view.View; +import android.widget.DatePicker; + +import androidx.test.espresso.action.ViewActions; +import androidx.test.espresso.contrib.PickerActions; +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.ext.junit.rules.ActivityScenarioRule; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; +import androidx.test.espresso.matcher.ViewMatchers; + +import org.hamcrest.CoreMatchers; +import org.hamcrest.Matcher; +import org.hamcrest.Matchers; +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 AdvancedSearchTests { + @Rule + public ActivityScenarioRule mActivityScenario = new ActivityScenarioRule<>(LoginActivity.class); + + private final Utils utils = new Utils(); + + @Test + public void A_setUp() throws InterruptedException { + utils.logIn(Constants.ancConstants.ancUsername, Constants.ancConstants.ancPassword); + } + + @Test + public void userCanSearchOutsideAndInsideMyHealthFacilityByFirstName() throws InterruptedException { + onView(withId(R.id.action_search)).perform(click()); + Thread.sleep(2000); + onView(withId(R.id.first_name)).perform(typeText(Configs.TestDataConfigs.firstNameA),ViewActions.closeSoftKeyboard()); + onView(withId(R.id.search)).perform(click()); + Thread.sleep(5000); + Matcher parentMatcher = withId(R.id.list_view_layout); + onView(allOf(withId(R.id.recycler_view), withParent(parentMatcher))).perform(RecyclerViewActions.scrollTo(ViewMatchers.hasDescendant(withText("Terence Howard")))).check(matches(isDisplayed())); + + } + @Test + public void userCanSearchOutsideAndInsideMyHealthFacilityByLastName() throws InterruptedException { + onView(withId(R.id.action_search)).perform(click()); + Thread.sleep(2000); + onView(withId(R.id.last_name)).perform(typeText(Configs.TestDataConfigs.lastNameA),ViewActions.closeSoftKeyboard()); + onView(withId(R.id.search)).perform(click()); + Matcher parentMatcher = withId(R.id.list_view_layout); + Thread.sleep(5000); + onView(allOf(withId(R.id.recycler_view), withParent(parentMatcher))).perform(RecyclerViewActions.scrollTo(ViewMatchers.hasDescendant(withText("Two Direction")))).check(matches(isDisplayed())); + + } + + @Test + public void userCanSearchOutsideAndInsideMyHealthFacilityByANCID() throws InterruptedException { + onView(withId(R.id.action_search)).perform(click()); + Thread.sleep(2000); + onView(allOf(withId(R.id.anc_id),isDescendantOfA(withId(R.id.nested_scroll_view)), withHint("ANC ID"))).perform(typeText(Configs.TestDataConfigs.clientID),ViewActions.closeSoftKeyboard()); + onView(withId(R.id.search)).perform(click()); + Thread.sleep(5000); + Matcher parentMatcher = withId(R.id.list_view_layout); + onView(allOf(withId(R.id.recycler_view), withParent(parentMatcher))).perform(RecyclerViewActions.scrollTo(ViewMatchers.hasDescendant(withText("ID: 7138845")))).check(matches(isDisplayed())); + + } + + @Test + public void userCanSearchOutsideAndInsideMyHealthFacilityByExpectedDateOfDelivery() throws InterruptedException { + onView(withId(R.id.action_search)).perform(click()); + Thread.sleep(2000); + onView(withHint("Expected date of delivery")).perform(click()); + onView(isAssignableFrom(DatePicker.class)).perform(PickerActions.setDate(2025, 4, 25)); + onView(withText("OK")).perform(click()); + onView(withId(R.id.search)).perform(click()); + Thread.sleep(5000); + Matcher parentMatcher = withId(R.id.list_view_layout); + onView(allOf(withId(R.id.recycler_view), withParent(parentMatcher))).perform(RecyclerViewActions.scrollTo(ViewMatchers.hasDescendant(withText(Configs.TestDataConfigs.clientName2)))).check(matches(isDisplayed())); + + } + @Test + public void userCanSearchOutsideAndInsideMyHealthFacilityByDateOfBirth() throws InterruptedException{ + onView(withId(R.id.action_search)).perform(click()); + Thread.sleep(2000); + onView(withHint("Expected date of delivery")).perform(swipeUp()); + onView(withId(R.id.dob)).perform(click()); + onView(isAssignableFrom(DatePicker.class)).perform(PickerActions.setDate(1992, 7, 19)); + onView(withText("OK")).perform(click()); + onView(withId(R.id.search)).perform(click()); + Thread.sleep(5000); + Matcher parentMatcher = withId(R.id.list_view_layout); + onView(allOf(withId(R.id.recycler_view), withParent(parentMatcher))).perform(RecyclerViewActions.scrollTo(ViewMatchers.hasDescendant(withText(Configs.TestDataConfigs.clientName2)))).check(matches(isDisplayed())); + + } + @Test + public void userCanSearchOutsideAndInsideMyHealthFacilityByPhoneNumber() throws InterruptedException{ + onView(withId(R.id.action_search)).perform(click()); + Thread.sleep(2000); + onView(withHint("Expected date of delivery")).perform(swipeUp()); + onView(withId(R.id.dob)).perform(swipeUp()); + onView(withId(R.id.phone_number)).perform(typeText(Configs.TestDataConfigs.phoneNumberA)); + onView(withId(R.id.search)).perform(click()); + Thread.sleep(5000); + Matcher parentMatcher = withId(R.id.list_view_layout); + onView(allOf(withId(R.id.recycler_view), withParent(parentMatcher))).perform(RecyclerViewActions.scrollTo(ViewMatchers.hasDescendant(withText(Configs.TestDataConfigs.clientName2)))).check(matches(isDisplayed())); + + } + @Test + public void userCanSearchOutsideAndInsideMyHealthFacilityByAlternateName()throws InterruptedException { + onView(withId(R.id.action_search)).perform(click()); + Thread.sleep(2000); + onView(withHint("Expected date of delivery")).perform(swipeUp()); + onView(withId(R.id.edd)).perform(swipeUp()); + onView(withId(R.id.dob)).perform(swipeUp()); + onView(withId(R.id.phone_number)).perform(swipeUp()); + onView(withId(R.id.alternate_contact_name)).perform(typeText(Configs.TestDataConfigs.alternateContactName),ViewActions.closeSoftKeyboard()); + onView(withId(R.id.search)).perform(click()); + Thread.sleep(5000); + Matcher parentMatcher = withId(R.id.list_view_layout); + onView(allOf(withId(R.id.recycler_view), withParent(parentMatcher))).perform(RecyclerViewActions.scrollTo(ViewMatchers.hasDescendant(withText(Configs.TestDataConfigs.clientName2)))).check(matches(isDisplayed())); + } + @Test + public void userCanSearchOutsideAndInsideMyHealthFacilityByScanningAQRCOde() throws InterruptedException{ + onView(withId(R.id.action_search)).perform(click()); + Thread.sleep(2000); + onView(withId(R.id.qrCodeButton)).perform(click()); + onView(withText("Scan QR Code")).check(matches(isDisplayed())); + } + @Test + public void userCanSearchInMyHealthFacilityByFirstName () { + onView(withId(R.id.action_search)).perform(click()); + onView(withId(R.id.my_catchment)).perform(click()); + onView(withId(R.id.first_name)).perform(typeText(Configs.TestDataConfigs.firstNameA),ViewActions.closeSoftKeyboard()); + onView(withId(R.id.search)).perform(click()); + } + +} \ No newline at end of file diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/HomePageActivityTest.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/HomePageActivityTest.java new file mode 100644 index 000000000..22b1ac919 --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/HomePageActivityTest.java @@ -0,0 +1,133 @@ +package org.smartregister.anc.activity.anc; + + +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.withText; +import static org.hamcrest.CoreMatchers.allOf; +import androidx.test.espresso.action.ViewActions; +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.ext.junit.rules.ActivityScenarioRule; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; + +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 HomePageActivityTest { + @Rule + public ActivityScenarioRule mActivityScenario = new ActivityScenarioRule<>(LoginActivity.class); + + private Utils utils = new Utils(); + + @Test + public void asetUp() throws InterruptedException { + utils.logIn(Constants.ancConstants.ancUsername, Constants.ancConstants.ancPassword); + } + + @Test + public void bSearchBarPresent() { + onView(withId(R.id.search_bar_layout)).check(matches(isDisplayed())); + + } + + @Test + public void cSearchPatientByName() throws InterruptedException { + + onView(withId(R.id.edt_search)).perform(typeText(Configs.TestDataConfigs.clientName), ViewActions.closeSoftKeyboard()); + onView(withId(R.id.patient_name)).check(matches(isDisplayed())); + Thread.sleep(1000); + onView(withId(R.id.btn_search_cancel)).perform(click()); + } + + @Test + public void dSearchPatientByID() throws InterruptedException { + + onView(withId(R.id.edt_search)).perform(typeText(Configs.TestDataConfigs.clientID), ViewActions.closeSoftKeyboard()); + onView(withId(R.id.patient_name)).check(matches(isDisplayed())); + Thread.sleep(1000); + onView(withId(R.id.btn_search_cancel)).perform(click()); + } + + @Test + public void eAdvancedSearch() throws InterruptedException { + onView(withId(R.id.action_search)).perform(click()); + onView(withId(R.id.qrCodeButton)).check(matches(isDisplayed())); + Thread.sleep(1000); + onView(withId(R.id.action_clients)).perform(click()); + } + + @Test + public void fOpenLibrary() throws InterruptedException { + onView(withId(R.id.action_library)).perform(click()); + onView(withId(R.id.library_toolbar_title)).check(matches(isDisplayed())); + Thread.sleep(1000); + onView(withId(R.id.action_clients)).perform(click()); + + + } + @Test + public void guserCanAccessANCRegistrationForm() throws InterruptedException { + onView(withContentDescription("Register")).perform(click()); + Thread.sleep(1500); + onView(withId(R.id.scan_button)).check(matches(isDisplayed())); + } + @Test + public void huserCanAccessProfile() throws InterruptedException { + onView(withContentDescription("Me")).perform(click()); + Thread.sleep(1500); + onView(withId(R.id.locationImageView)).check(matches(isDisplayed())); + } + + @Test + public void iuserCanClickOnAPatient() throws InterruptedException { + onView(allOf(withId(R.id.recycler_view), isDisplayed())) + .perform(RecyclerViewActions.actionOnItemAtPosition(0, click())); + Thread.sleep(2000); + onView(withId(R.id.btn_profile_registration_info)).check(matches(isDisplayed())); + } + + @Test + public void juserCanClickOnNextButtonOnRegister() throws InterruptedException { + Thread.sleep(2000); + onView(allOf(withId(R.id.recycler_view), isDisplayed())) + .perform(RecyclerViewActions.scrollToPosition(20)); + Thread.sleep(2000); + onView(withId(R.id.btn_next_page)).perform(click()); + onView(withId(R.id.btn_previous_page)).check(matches(isDisplayed())); + } + @Test + public void kuserCanClickOnThePreviousBtnOnRegister() throws InterruptedException { + Thread.sleep(2000); + onView(allOf(withId(R.id.recycler_view), isDisplayed())) + .perform(RecyclerViewActions.scrollToPosition(20)); + Thread.sleep(2000); + onView(withId(R.id.btn_next_page)).perform(click()); + Thread.sleep(2000); + onView(withId(R.id.btn_previous_page)).perform(scrollTo()).perform(click()); + Thread.sleep(2000); + onView(withText("Page 1 of 9")).perform(scrollTo()).check(matches(isDisplayed())); + } +} + + diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/LoginActivityTest.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/LoginActivityTest.java new file mode 100644 index 000000000..04935f44e --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/LoginActivityTest.java @@ -0,0 +1,110 @@ +package org.smartregister.anc.activity.anc; + + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard; + +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.withId; + +import static androidx.test.espresso.matcher.ViewMatchers.withText; +import org.smartregister.anc.activity.LoginActivity; + + + +import androidx.test.ext.junit.rules.ActivityScenarioRule; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; + + +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.utils.Constants; +import org.smartregister.anc.activity.utils.Utils; + + +@LargeTest +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@RunWith(AndroidJUnit4.class) +public class LoginActivityTest { + Utils utils = new Utils(); + + @Rule + public ActivityScenarioRule mActivityScenario = new ActivityScenarioRule<>(LoginActivity.class); + + + + + @Test + public void eTestShowPassword(){ + onView(withId(R.id.login_password_edit_text)).perform(typeText(Constants.ancConstants.ancPassword),closeSoftKeyboard()); + onView(withId(R.id.login_show_password_checkbox)).perform(click(),closeSoftKeyboard()); + onView(withId(R.id.login_password_edit_text)).check(matches(withText(Constants.ancConstants.ancPassword))); + + } + + @Test + public void fTestSuccessfulLogin() throws InterruptedException { + onView(withId(R.id.login_user_name_edit_text)).perform(typeText(Constants.ancConstants.ancUsername), closeSoftKeyboard()); + onView(withId(R.id.login_password_edit_text)).perform(typeText(Constants.ancConstants.ancPassword), closeSoftKeyboard()); + onView(withId(R.id.login_login_btn)).perform(click()); + Thread.sleep(30000); + //fix error caused by the id edt_search + onView(withId(R.id.edt_search)).check(matches(isDisplayed())); + + } + + @Test + public void cTestIncorrectUsername() throws InterruptedException { + onView(withId(R.id.login_user_name_edit_text)).perform(typeText("Beba"),closeSoftKeyboard()); + onView(withId(R.id.login_password_edit_text)).perform(typeText(Constants.ancConstants.ancPassword),closeSoftKeyboard()); + onView(withId(R.id.login_login_btn)).perform(click()); + Thread.sleep(20000); + onView(withText("Please check the credentials")).check(matches(isDisplayed())); + + + + } + + + @Test + public void dTestIncorrectPassword() throws InterruptedException { + onView(withId(R.id.login_user_name_edit_text)).perform(typeText(Constants.ancConstants.ancUsername),closeSoftKeyboard()); + onView(withId(R.id.login_password_edit_text)).perform(typeText("koko"),closeSoftKeyboard()); + onView(withId(R.id.login_login_btn)).perform(click()); + Thread.sleep(20000); + onView(withText("Please check the credentials")).check(matches(isDisplayed())); + + + } + + @Test + public void aTestEmptyUsername() throws InterruptedException { + onView(withId(R.id.login_user_name_edit_text)).perform(typeText(" "),closeSoftKeyboard()); + onView(withId(R.id.login_password_edit_text)).perform(typeText(Constants.ancConstants.ancPassword),closeSoftKeyboard()); + onView(withId(R.id.login_login_btn)).perform(click()); + Thread.sleep(20000); + onView(withText("Please check the credentials")).check(matches(isDisplayed())); + + + } + + @Test + public void bTestEmptyPassword() throws InterruptedException { + onView(withId(R.id.login_user_name_edit_text)).perform(typeText(Constants.ancConstants.ancPassword),closeSoftKeyboard()); + onView(withId(R.id.login_password_edit_text)).perform(typeText(" "),closeSoftKeyboard()); + onView(withId(R.id.login_login_btn)).perform(click()); + Thread.sleep(20000); + onView(withText("Please check the credentials")).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 new file mode 100644 index 000000000..5dffa0e22 --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ProfilePageTests.java @@ -0,0 +1,167 @@ +package org.smartregister.anc.activity.anc; + + + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; + +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant; + +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 static org.hamcrest.CoreMatchers.allOf; + +import android.app.Activity; + +import androidx.test.espresso.contrib.RecyclerViewActions; + +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.Constants; +import org.smartregister.anc.activity.utils.Utils; + +@LargeTest +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@RunWith(AndroidJUnit4.class) + +public class ProfilePageTests { + +@Rule + public ActivityScenarioRule mActivityScenario = new ActivityScenarioRule<>(LoginActivity.class); + +Utils utils = new Utils(); + + @Test + public void aSetUp() throws InterruptedException { + utils.logIn(Constants.ancConstants.ancUsername, Constants.ancConstants.ancPassword); + } + + @Test + public void bUserLocationIsDisplayed() throws InterruptedException { + onView(withContentDescription("Me")).perform(click()); + onView(withId(R.id.facility_selection)).perform(click()); + onView(withId(R.id.locations_lv)).check(matches(isDisplayed())); + onView(withId(R.id.locations_lv)).perform(click()); + Thread.sleep(1000); + } + + + + @Test + public void cChangeLanguageToBahasa() throws InterruptedException { + onView(withContentDescription("Me")).perform(click()); + onView(withId(R.id.language_switcher_text)).perform(click()); + onView(withText("Bahasa (Indonesia)")).perform(click()); + Thread.sleep(3000); + onView(withId(R.id.opensrp_logo_image_view)).check(matches(isDisplayed())); + Thread.sleep(1000); + } + + + @Test + public void eChangeLanguageToFrench() throws InterruptedException { + onView(withContentDescription("Me")).perform(click()); + onView(withId(R.id.language_switcher_text)).perform(click()); + onView(withText("French")).perform(click()); + Thread.sleep(3000); + onView(withId(R.id.opensrp_logo_image_view)).check(matches(isDisplayed())); + Thread.sleep(1000); + } + + @Test + public void fChangeLanguageToPortuguese() throws InterruptedException { + onView(withContentDescription("Moi")).perform(click()); + onView(withId(R.id.language_switcher_text)).perform(click()); + onView(withText("Portuguese (Brazil)")).perform(click()); + Thread.sleep(3000); + onView(withId(R.id.opensrp_logo_image_view)).check(matches(isDisplayed())); + Thread.sleep(1000); + } + + @Test + public void gChangeLanguageToEnglish() throws InterruptedException { + onView(withContentDescription("Eu")).perform(click()); + onView(withId(R.id.language_switcher_text)).perform(click()); + onView(withText("English")).perform(click()); + Thread.sleep(2000); + onView(withId(R.id.opensrp_logo_image_view)).check(matches(isDisplayed())); + Thread.sleep(1000); + } + @Test + public void hLoadPopulationXstics() throws InterruptedException { + onView(withContentDescription("Me")).perform(click()); + onView(withId(R.id.pop_characteristics_text)).perform(click()); + onView(withId(R.id.characteristics_toolbar_title)).check(matches(isDisplayed())); + Thread.sleep(1500); + + } + + @Test + public void iPopulationXsticScrollDown() { + onView(withContentDescription("Me")).perform(click()); + onView(withId(R.id.pop_characteristics_text)).perform(click()); + onView(withId(R.id.population_characteristics)).perform(RecyclerViewActions.scrollTo(hasDescendant(withText("Syphilis prevalence 5% or higher")))).check(matches(isDisplayed())); + + + } + + + + + + @Test + public void jLoadSiteXstics() { + onView(withContentDescription("Me")).perform(click()); + onView(withId(R.id.site_characteristics_text)).perform(click()); + onView(withId(R.id.characteristics_toolbar_title)).check(matches(isDisplayed())); + + + } +// @Test +// public void kEditSiteXstics() throws Throwable { +// onView(withContentDescription("Me")).perform(click()); +// onView(withId(R.id.site_characteristics_text)).perform(click()); +// onView(withId(R.id.characteristics_toolbar_edit)).perform(click()); +// Thread.sleep(1500); +// Activity activity = utils.getCurrentActivity(); +// onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:site_ultrasound"))).perform(click()); +// //fix the ambiguous error +// // onView(withSubstring("Yes")).perform(click()); +// onView(withId(R.id.action_save)).perform(click()); +// onView(withId(R.id.opensrp_logo_image_view)).check(matches(isDisplayed())); + + // } + // Device to device sync tests skipped because module is not implemented + + @Test + public void lLogOut() 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/RegisterFamilyMemberPageTests.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/RegisterFamilyMemberPageTests.java new file mode 100644 index 000000000..dc2011c41 --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/RegisterFamilyMemberPageTests.java @@ -0,0 +1,108 @@ +package org.smartregister.anc.activity.anc; + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard; +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.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withSubstring; +import static androidx.test.espresso.matcher.ViewMatchers.withText; + + + +import android.app.Activity; + +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 RegisterFamilyMemberPageTests { + + @Rule + + public ActivityScenarioRule mActivityScenario = new ActivityScenarioRule<>(LoginActivity.class); + + Utils utils = new Utils(); + + + +@Test +public void aSetUp() throws InterruptedException { + utils.logIn(Constants.ancConstants.ancUsername, Constants.ancConstants.ancPassword); +} + + @Test + public void bAddAFamilyMember() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(3000); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).check(matches(isDisplayed())); + + } + +//Always run below test after the test above +@Test + public void cRemoveFamilyMemberAdded() throws Throwable { + + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(2000); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(2000); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("Moved away")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + + + } + + @Test + public void dAddMemberWithMissingMandatoryFields() throws Throwable { + onView(withId(R.id.action_register)).perform(click()); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:first_name"))).perform(typeText(Configs.TestDataConfigs.firstName), closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:last_name"))).perform(typeText(Configs.TestDataConfigs.lastName), closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:dob_unknown"))).perform(click()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:age_entered"))).perform(typeText(Configs.TestDataConfigs.clientAge),closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:home_address"))).perform(typeText(Configs.TestDataConfigs.clientAddress), closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:phone_number"))).perform(typeText(Configs.TestDataConfigs.phoneNumber), closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:reminders"))).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + onView(withSubstring("Found 1 error(s) in the form. Please correct them to submit.")).check(matches(isDisplayed())); + Thread.sleep(500); + + } + + + + + + + + + + + + + + +} diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/RemoveFamilyMemberTest.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/RemoveFamilyMemberTest.java new file mode 100644 index 000000000..2915285e2 --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/RemoveFamilyMemberTest.java @@ -0,0 +1,254 @@ +package org.smartregister.anc.activity.anc; + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +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.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 +@RunWith(AndroidJUnit4.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) + +public class RemoveFamilyMemberTest { + @Rule + public ActivityScenarioRule mActivityScenario = new ActivityScenarioRule<>(LoginActivity.class); + + Utils utils = new Utils(); + + + @Test + + public void aSetUp() throws InterruptedException { + utils.logIn(Constants.ancConstants.ancUsername, Constants.ancConstants.ancPassword); + } + + @Test + public void bRemoveByMovedAway() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1500); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(1000); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(2000); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("Moved away")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(1000); + + + } + @Test + public void cRemoveByDeath() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1000); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(2000); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(500); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("Woman died")).perform(click()); + Thread.sleep(1000); + onView(withId(utils.getViewId((JsonFormActivity) activity, "step1:death_date"))).perform(click()); + onView(withId(R.id.ok_button)).perform(click()); + onView(withSubstring("Cause of death")).perform(click()); + onView(withSubstring("Eclampsia")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(1000); + + + } + @Test + public void dRemoveByOther() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1500); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(2000); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(2000); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("Other")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(1000); + + + } + @Test + public void eRemoveByMiscarriage() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1500); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(2000); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(500); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("Miscarriage")).perform(click()); + + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:miscarriage_abortion_date"))).perform(click()); + + onView(withId(R.id.ok_button)).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(1000); + + + } + + + @Test + public void fRemoveByStillBirth() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1500); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(2000); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(500); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("Stillbirth")).perform(click()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:delivery_date"))).perform(click()); + onView(withId(R.id.ok_button)).perform(click()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:delivery_place"))).perform(click()); + onView(withSubstring("Health facility")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + + + + } + + @Test + public void gRemoveByAbortion() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1500); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(1500); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(500); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("Abortion")).perform(click()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:miscarriage_abortion_date"))).perform(click()); + onView(withId(R.id.ok_button)).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(1000); + + + } + + + + @Test + public void iRemoveByLiveBirth() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1500); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(1500); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(500); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + Thread.sleep(500); + onView(withSubstring("Live birth")).perform(click()); + Thread.sleep(500); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:delivery_date"))).perform(click()); + onView(withId(R.id.ok_button)).perform(click()); + Thread.sleep(500); + onView(withSubstring("Place of delivery")).perform(click()); + onView(withSubstring("Health facility")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(1000); + + + } + @Test + public void jRemoveByFalsePregnancy() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1500); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(1500); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(500); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("False pregnancy")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(1000); + + + + } + + @Test + public void kRemoveByLostToFollowUp() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1500); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(1500); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(500); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("Lost to follow-up")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(1000); + + + + } + + @Test + public void lRemoveByWrongEntry() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1500); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(1500); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(500); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("Wrong entry")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(1000); + + + + } + + + + + + +} 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 new file mode 100644 index 000000000..7b7e44b2c --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Configs.java @@ -0,0 +1,21 @@ +package org.smartregister.anc.activity.utils; +public class Configs { + + + public static class TestDataConfigs{ + public static final String clientName = "Lauren Hill"; + public static final String clientID = "7138845"; + public static final String firstNameA = "Terence"; + public static final String lastNameA = "Direction"; + public static final String clientName2 = "Lily Woods"; + public static final String phoneNumberA = "584555"; + public static final String alternateContactName = "Lu"; + public static final String firstName = "Test"; + public static final String lastName = "Client"; + public static final String clientAge = "29"; + public static final String clientAddress = "28th strt Nrb"; + public static final String phoneNumber = "+254700100200"; + public static final String firstAndLastName = "Test Client"; + + } +} diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Constants.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Constants.java new file mode 100644 index 000000000..dc7bd6879 --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Constants.java @@ -0,0 +1,10 @@ +package org.smartregister.anc.activity.utils; +public class Constants { + public static class ancConstants { + + //values to be input each time a test is run + + public static final String ancUsername = ""; + public static final String ancPassword = ""; + } +} 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 new file mode 100644 index 000000000..57c044ff2 --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Utils.java @@ -0,0 +1,96 @@ +package org.smartregister.anc.activity.utils; + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard; +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.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withInputType; +import static androidx.test.espresso.matcher.ViewMatchers.withSubstring; +import static androidx.test.espresso.matcher.ViewMatchers.withText; +import static androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + +import static org.apache.commons.lang3.Validate.isAssignableFrom; + +import android.view.View; +import android.view.ViewGroup; + +import androidx.core.widget.NestedScrollView; +import androidx.test.espresso.UiController; +import androidx.test.espresso.ViewAction; +import androidx.test.espresso.matcher.BoundedMatcher; + +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; + +import android.app.Activity; + +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.apache.commons.lang3.RandomStringUtils; +import org.smartregister.anc.R; + + +public class Utils { + + + public void logIn(String username, String password) throws InterruptedException { + onView(withId(R.id.login_user_name_edit_text)).perform(typeText(username), closeSoftKeyboard()); + onView(withId(R.id.login_password_edit_text)).perform(typeText(password), closeSoftKeyboard()); + onView(withId(R.id.login_login_btn)).perform(click()); + 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 void addAFamilyMember() throws Throwable { + onView(withId(R.id.action_register)).perform(click()); + //get Activity + Activity activity = getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:first_name"))).perform(typeText(Configs.TestDataConfigs.firstName), closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:last_name"))).perform(typeText(Configs.TestDataConfigs.lastName), closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:dob_unknown"))).perform(click()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:age_entered"))).perform(typeText(Configs.TestDataConfigs.clientAge),closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:home_address"))).perform(typeText(Configs.TestDataConfigs.clientAddress), closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:phone_number"))).perform(typeText(Configs.TestDataConfigs.phoneNumber), closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:reminders"))).perform(click()); + onView(withSubstring("Yes")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(3000); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).check(matches(isDisplayed())); + + } + +} + + + + + + diff --git a/reference-app/src/main/java/org/smartregister/anc/application/AncApplication.java b/reference-app/src/main/java/org/smartregister/anc/application/AncApplication.java index 85dd5281c..b6f4836bb 100644 --- a/reference-app/src/main/java/org/smartregister/anc/application/AncApplication.java +++ b/reference-app/src/main/java/org/smartregister/anc/application/AncApplication.java @@ -9,7 +9,6 @@ import androidx.annotation.NonNull; import com.evernote.android.job.JobManager; -import com.flurry.android.FlurryAgent; import com.google.firebase.crashlytics.FirebaseCrashlytics; import com.vijay.jsonwizard.NativeFormLibrary; @@ -113,15 +112,7 @@ public void onCreate() { //init Job Manager JobManager.create(this).addJobCreator(new AncJobCreator()); - //Only integrate Flurry Analytics for production. Remove negation to test in debug - if (!BuildConfig.DEBUG) { - new FlurryAgent.Builder() - .withLogEnabled(true) - .withCaptureUncaughtExceptions(true) - .withContinueSessionMillis(10000) - .withLogLevel(Log.VERBOSE) - .build(this, BuildConfig.FLURRY_API_KEY); - } + NativeFormLibrary .getInstance() .setClientFormDao(CoreLibrary.getInstance().context().getClientFormRepository());