mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Add NavigationBaseActivityTest (#2633)
This commit is contained in:
parent
f983a99f45
commit
d24bf20c80
2 changed files with 68 additions and 0 deletions
|
|
@ -66,6 +66,7 @@ dependencies {
|
|||
// Android testing
|
||||
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$KOTLIN_VERSION"
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.1'
|
||||
androidTestImplementation 'androidx.test:runner:1.1.1'
|
||||
androidTestImplementation 'androidx.test:rules:1.1.1'
|
||||
androidTestImplementation 'androidx.annotation:annotation:1.0.2'
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import androidx.test.espresso.contrib.DrawerActions;
|
||||
import androidx.test.espresso.contrib.NavigationViewActions;
|
||||
import androidx.test.filters.LargeTest;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||
|
||||
@LargeTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class NavigationBaseActivityTest {
|
||||
@Rule
|
||||
public ActivityTestRule activityRule = new ActivityTestRule<>(AboutActivity.class);
|
||||
|
||||
/**
|
||||
* Goes through all the activities in the app and checks we don't crash
|
||||
* NB: This is not realistic if we're not logged in; we can access 'home', 'notifications', 'settings' and 'achievements' which we wouldn't otherwise be able to.
|
||||
*/
|
||||
@Test
|
||||
public void goThroughNavigationBaseActivityActivities() {
|
||||
// Home
|
||||
openNavigationDrawerAndNavigateTo(R.id.action_home);
|
||||
|
||||
// Explore
|
||||
openNavigationDrawerAndNavigateTo(R.id.action_explore);
|
||||
|
||||
// Bookmarks
|
||||
openNavigationDrawerAndNavigateTo(R.id.action_bookmarks);
|
||||
|
||||
// About
|
||||
openNavigationDrawerAndNavigateTo(R.id.action_about);
|
||||
|
||||
// Settings
|
||||
openNavigationDrawerAndNavigateTo(R.id.action_settings);
|
||||
|
||||
// Achievements
|
||||
openNavigationDrawerAndNavigateTo(R.id.action_login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clicks 'Explore' in the navigation drawer twice, then clicks 'home'
|
||||
* Testing to avoid regression of #2200
|
||||
*/
|
||||
@Test
|
||||
public void doubleNavigateToExploreThenReturnHome() {
|
||||
// Explore
|
||||
openNavigationDrawerAndNavigateTo(R.id.action_explore);
|
||||
|
||||
// Explore
|
||||
openNavigationDrawerAndNavigateTo(R.id.action_explore);
|
||||
|
||||
// Home
|
||||
openNavigationDrawerAndNavigateTo(R.id.action_home);
|
||||
}
|
||||
|
||||
public void openNavigationDrawerAndNavigateTo(int menuItemId) {
|
||||
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
|
||||
onView(withId(R.id.navigation_view)).perform(NavigationViewActions.navigateTo(menuItemId));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue