Skip to content

Commit

Permalink
Added more tests to the Homepage Module
Browse files Browse the repository at this point in the history
  • Loading branch information
karina4050 committed Jul 4, 2024
1 parent 11a3a8c commit 73ef2ee
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
2 changes: 1 addition & 1 deletion reference-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ dependencies {
// 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
Expand Up @@ -3,15 +3,25 @@
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;
Expand Down Expand Up @@ -97,6 +107,36 @@ public void userCanAccessProfile() throws InterruptedException {
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
Expand Up @@ -13,7 +13,6 @@
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.allOf;
import org.smartregister.anc.activity.LoginActivity;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
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.isRoot;
import static androidx.test.espresso.matcher.ViewMatchers.withId;

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

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.smartregister.anc.R;

public class Utils {
Expand All @@ -19,4 +26,19 @@ public void logIn(String username, String password) throws InterruptedException
onView(withId(R.id.login_login_btn)).perform(click());
Thread.sleep(30000);
}

// public static Matcher<View> withRecyclerViewId(final int recyclerViewId) {
// return new TypeSafeMatcher<View>() {
// @Override
// public void describeTo(Description description) {
// description.appendText("RecyclerView with ID: " + recyclerViewId);
// }
// @Override
// public boolean matchesSafely(View view) {
// return view.getId() == recyclerViewId;
// }
// };
// }

}

0 comments on commit 73ef2ee

Please sign in to comment.