From 922888efbf989b001483fd49737ef184a6f23cf2 Mon Sep 17 00:00:00 2001 From: Priyansh Bhuva Date: Sun, 26 Nov 2023 23:27:00 -0500 Subject: [PATCH] Added test cases for the options to choose to be shown in notification. --- .../IntroductionActivityTest.java | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/androidTest/java/de/dennisguse/opentracks/introduction/IntroductionActivityTest.java diff --git a/src/androidTest/java/de/dennisguse/opentracks/introduction/IntroductionActivityTest.java b/src/androidTest/java/de/dennisguse/opentracks/introduction/IntroductionActivityTest.java new file mode 100644 index 000000000..26059e934 --- /dev/null +++ b/src/androidTest/java/de/dennisguse/opentracks/introduction/IntroductionActivityTest.java @@ -0,0 +1,95 @@ + +import androidx.test.espresso.DataInteraction; +import androidx.test.espresso.ViewInteraction; +import androidx.test.filters.LargeTest; +import androidx.test.ext.junit.rules.ActivityScenarioRule; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewParent; + +import static androidx.test.InstrumentationRegistry.getInstrumentation; +import static androidx.test.espresso.Espresso.onData; +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.Espresso.pressBack; +import static androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu; +import static androidx.test.espresso.action.ViewActions.*; +import static androidx.test.espresso.assertion.ViewAssertions.*; +import static androidx.test.espresso.matcher.ViewMatchers.*; + +import de.dennisguse.opentracks.debug.R; + +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; +import org.hamcrest.core.IsInstanceOf; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.anything; +import static org.hamcrest.Matchers.is; + +@LargeTest +@RunWith(AndroidJUnit4.class) +public class IntroductionActivityTest { + + @Rule + public ActivityScenarioRule mActivityScenarioRule = + new ActivityScenarioRule<>(IntroductionActivity.class); + + @Test + public void introductionActivityTest() { + ViewInteraction floatingActionButton = onView( + allOf(withId(R.id.track_list_fab_action), withContentDescription("Record"), + childAtPosition( + childAtPosition( + withId(android.R.id.content), + 0), + 3), + isDisplayed())); + floatingActionButton.perform(click()); + + ViewInteraction textView = onView( + allOf(withId(android.R.id.text1), withText("Speed"), + withParent(allOf(IsInstanceOf.instanceOf(android.widget.ListView.class), + withParent(IsInstanceOf.instanceOf(android.widget.FrameLayout.class)))), + isDisplayed())); + textView.check(matches(withText("Speed"))); + + ViewInteraction textView2 = onView( + allOf(withId(android.R.id.text1), withText("Heart Rate"), + withParent(allOf(IsInstanceOf.instanceOf(android.widget.ListView.class), + withParent(IsInstanceOf.instanceOf(android.widget.FrameLayout.class)))), + isDisplayed())); + textView2.check(matches(withText("Heart Rate"))); + + ViewInteraction textView3 = onView( + allOf(withId(android.R.id.text1), withText("Distance"), + withParent(allOf(IsInstanceOf.instanceOf(android.widget.ListView.class), + withParent(IsInstanceOf.instanceOf(android.widget.FrameLayout.class)))), + isDisplayed())); + textView3.check(matches(withText("Distance"))); + } + + private static Matcher childAtPosition( + final Matcher parentMatcher, final int position) { + + return new TypeSafeMatcher() { + @Override + public void describeTo(Description description) { + description.appendText("Child at position " + position + " in parent "); + parentMatcher.describeTo(description); + } + + @Override + public boolean matchesSafely(View view) { + ViewParent parent = view.getParent(); + return parent instanceof ViewGroup && parentMatcher.matches(parent) + && view.equals(((ViewGroup) parent).getChildAt(position)); + } + }; + } +}