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

Contacts #1004

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions opensrp-anc/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@



buildscript {
repositories {
mavenCentral()
Expand Down Expand Up @@ -229,6 +232,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'
Expand Down
36 changes: 24 additions & 12 deletions reference-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -224,6 +224,18 @@ 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 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")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;

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 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 A_setUp() throws InterruptedException {
utils.logIn(Constants.ancConstants.ancUsername, Constants.ancConstants.ancPassword);
}

@Test
public void B_StartContactVisit() throws InterruptedException {

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);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
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.RootMatchers.withDecorView;
import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
import static androidx.test.espresso.matcher.ViewMatchers.isClickable;
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.smartregister.anc.activity.utils.Utils.withRecyclerViewId;

import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.is;

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<LoginActivity> 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_SearchBarPresent() {
onView(withId(R.id.search_bar_layout)).check(matches(isDisplayed()));

}

@Test
public void C_SearchPatientByName() 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 C_SearchPatientByID() 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 D_AdvancedSearch() 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 E_OpenLibrary() 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 userCanAccessANCRegistrationForm() throws InterruptedException {
onView(withContentDescription("Register")).perform(click());
Thread.sleep(1500);
onView(withId(R.id.scan_button)).check(matches(isDisplayed()));
}
@Test
public void userCanAccessProfile() throws InterruptedException {
onView(withContentDescription("Me")).perform(click());
Thread.sleep(1500);
onView(withId(R.id.locationImageView)).check(matches(isDisplayed()));
}

@Test
public void userCanClickOnAPatient() 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 userCanClickOnNextButtonOnRegister() 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 userCanClickOnThePreviousBtnOnRegister() 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()));
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
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.replaceText;
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.withParent;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import org.smartregister.anc.activity.LoginActivity;



import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

import androidx.test.espresso.ViewInteraction;
import androidx.test.espresso.action.TypeTextAction;
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
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 {

@Rule
public ActivityScenarioRule<LoginActivity> mActivityScenario = new ActivityScenarioRule<>(LoginActivity.class);
public String correctPassword = "Amani123";



@Test
public void E_testShowPassword(){
onView(withId(R.id.login_password_edit_text)).perform(typeText(correctPassword),closeSoftKeyboard());
onView(withId(R.id.login_show_password_checkbox)).perform(click(),closeSoftKeyboard());
onView(withId(R.id.login_password_edit_text)).check(matches(withText(correctPassword)));

}

@Test
public void F_testSuccessfulLogin() throws InterruptedException {
onView(withId(R.id.login_user_name_edit_text)).perform(typeText("demo"), closeSoftKeyboard());
onView(withId(R.id.login_password_edit_text)).perform(typeText(correctPassword), 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 C_testIncorrectUsername() 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(correctPassword),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 D_testIncorrectPassword() throws InterruptedException {
onView(withId(R.id.login_user_name_edit_text)).perform(typeText("demo"),closeSoftKeyboard());
onView(withId(R.id.login_password_edit_text)).perform(typeText("mani"),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 A_testEmptyUsername() throws InterruptedException {
onView(withId(R.id.login_user_name_edit_text)).perform(typeText(" "),closeSoftKeyboard());
onView(withId(R.id.login_password_edit_text)).perform(typeText(correctPassword),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 B_testEmptyPassword() 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(" "),closeSoftKeyboard());
onView(withId(R.id.login_login_btn)).perform(click());
Thread.sleep(20000);
onView(withText("Please check the credentials")).check(matches(isDisplayed()));


}








}
Loading
Loading