diff --git a/app/build.gradle b/app/build.gradle index a3cfe838..fad96a88 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -76,7 +76,9 @@ dependencies { testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' + androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.5.1' androidTestImplementation 'androidx.test:rules:1.5.0' + implementation "androidx.tracing:tracing:1.2.0" implementation "androidx.lifecycle:lifecycle-viewmodel:2.7.0" implementation "androidx.lifecycle:lifecycle-livedata:2.7.0" implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.7.0" diff --git a/app/src/androidTest/java/mobi/maptrek/SimpleRunTest.java b/app/src/androidTest/java/mobi/maptrek/SimpleRunTest.java index 5ff3114e..ebac45d0 100644 --- a/app/src/androidTest/java/mobi/maptrek/SimpleRunTest.java +++ b/app/src/androidTest/java/mobi/maptrek/SimpleRunTest.java @@ -44,6 +44,7 @@ import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.action.ViewActions.longClick; import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition; import static androidx.test.espresso.matcher.RootMatchers.isDialog; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.withClassName; @@ -72,8 +73,9 @@ public void beforeTest() { @Test public void mainActivityTest() { + // Close Introduction panel if test is running separately + try { - // Close Introduction panel if test is running separately ViewInteraction appCompatButton = onView( allOf( withId(R.id.skip), @@ -87,6 +89,7 @@ public void mainActivityTest() { } // World map download dialog is displayed - close it + ViewInteraction appCompatButton2 = onView( allOf( withId(android.R.id.button2), @@ -102,13 +105,7 @@ public void mainActivityTest() { allOf( withId(R.id.moreButton), childAtPosition( - allOf( - withId(R.id.actionPanel), - childAtPosition( - withClassName(is("android.widget.RelativeLayout")), - 1 - ) - ), + withId(R.id.actionPanel), 4 ), isDisplayed() @@ -116,39 +113,68 @@ public void mainActivityTest() { ); appCompatImageButton.perform(click()); - // Press 'About' menu item + // Press 'Settings' menu item DataInteraction linearLayout = onData(anything()) .inAdapterView( allOf( withId(android.R.id.list), childAtPosition( - withClassName(is("android.widget.FrameLayout")), - 0 + withClassName(is("android.widget.FrameLayout")), + 0 ) ) ) - .atPosition(0); + .atPosition(1); linearLayout.perform(click()); - // Check for 'Trekarta' title + // Check for 'About' preference item ViewInteraction textView = onView( + allOf( + withId(android.R.id.title), + withText("About"), + isDisplayed() + ) + ); + textView.check(matches(withText("About"))); + + // Press 'About' preference item + + ViewInteraction recyclerView = onView( + allOf( + withId(androidx.preference.R.id.recycler_view), + childAtPosition( + withId(android.R.id.list_container), + 0 + ) + ) + ); + recyclerView.perform(actionOnItemAtPosition(3, click())); + + // Check for 'Trekarta' title + + ViewInteraction imageView = onView( allOf( withId(R.id.title), withContentDescription("Trekarta"), - childAtPosition( - childAtPosition( - IsInstanceOf.instanceOf(android.widget.LinearLayout.class), - 0 - ), - 1 - ), isDisplayed() ) ); - textView.check(matches(withContentDescription("Trekarta"))); + imageView.check(matches(isDisplayed())); + + // Check for 'trekarta.info' link + + ViewInteraction textView2 = onView( + allOf( + withId(R.id.links), + withText("https://trekarta.info/"), + isDisplayed() + ) + ); + textView2.check(matches(withText("https://trekarta.info/"))); + pressBack(); pressBack(); // Press 'Places' button @@ -157,13 +183,7 @@ public void mainActivityTest() { allOf( withId(R.id.placesButton), childAtPosition( - allOf( - withId(R.id.actionPanel), - childAtPosition( - withClassName(is("android.widget.RelativeLayout")), - 1 - ) - ), + withId(R.id.actionPanel), 2 ), isDisplayed() @@ -179,13 +199,7 @@ public void mainActivityTest() { allOf( withId(R.id.mapsButton), childAtPosition( - allOf( - withId(R.id.actionPanel), - childAtPosition( - withClassName(is("android.widget.RelativeLayout")), - 1 - ) - ), + withId(R.id.actionPanel), 3 ), isDisplayed() @@ -200,8 +214,8 @@ public void mainActivityTest() { allOf( withId(android.R.id.list), childAtPosition( - withClassName(is("android.widget.FrameLayout")), - 0 + withClassName(is("android.widget.FrameLayout")), + 0 ) ) ) @@ -210,7 +224,7 @@ public void mainActivityTest() { // Find first legend title - ViewInteraction textView2 = onView( + ViewInteraction textView3 = onView( allOf( withId(R.id.name), withText("Administrative"), @@ -224,7 +238,7 @@ public void mainActivityTest() { isDisplayed() ) ); - textView2.check(matches(withText("Administrative"))); + textView3.check(matches(withText("Administrative"))); pressBack(); @@ -234,13 +248,7 @@ public void mainActivityTest() { allOf( withId(R.id.locationButton), childAtPosition( - allOf( - withId(R.id.actionPanel), - childAtPosition( - withClassName(is("android.widget.RelativeLayout")), - 1 - ) - ), + withId(R.id.actionPanel), 0 ), isDisplayed()