Skip to content

Commit d24bf20

Browse files
domdomeggmaskaravivek
authored andcommitted
Add NavigationBaseActivityTest (commons-app#2633)
1 parent f983a99 commit d24bf20

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ dependencies {
6666
// Android testing
6767
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$KOTLIN_VERSION"
6868
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
69+
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.1'
6970
androidTestImplementation 'androidx.test:runner:1.1.1'
7071
androidTestImplementation 'androidx.test:rules:1.1.1'
7172
androidTestImplementation 'androidx.annotation:annotation:1.0.2'
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package fr.free.nrw.commons;
2+
3+
import org.junit.Rule;
4+
import org.junit.Test;
5+
import org.junit.runner.RunWith;
6+
7+
import androidx.test.espresso.contrib.DrawerActions;
8+
import androidx.test.espresso.contrib.NavigationViewActions;
9+
import androidx.test.filters.LargeTest;
10+
import androidx.test.rule.ActivityTestRule;
11+
import androidx.test.runner.AndroidJUnit4;
12+
13+
import static androidx.test.espresso.Espresso.onView;
14+
import static androidx.test.espresso.matcher.ViewMatchers.withId;
15+
16+
@LargeTest
17+
@RunWith(AndroidJUnit4.class)
18+
public class NavigationBaseActivityTest {
19+
@Rule
20+
public ActivityTestRule activityRule = new ActivityTestRule<>(AboutActivity.class);
21+
22+
/**
23+
* Goes through all the activities in the app and checks we don't crash
24+
* 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.
25+
*/
26+
@Test
27+
public void goThroughNavigationBaseActivityActivities() {
28+
// Home
29+
openNavigationDrawerAndNavigateTo(R.id.action_home);
30+
31+
// Explore
32+
openNavigationDrawerAndNavigateTo(R.id.action_explore);
33+
34+
// Bookmarks
35+
openNavigationDrawerAndNavigateTo(R.id.action_bookmarks);
36+
37+
// About
38+
openNavigationDrawerAndNavigateTo(R.id.action_about);
39+
40+
// Settings
41+
openNavigationDrawerAndNavigateTo(R.id.action_settings);
42+
43+
// Achievements
44+
openNavigationDrawerAndNavigateTo(R.id.action_login);
45+
}
46+
47+
/**
48+
* Clicks 'Explore' in the navigation drawer twice, then clicks 'home'
49+
* Testing to avoid regression of #2200
50+
*/
51+
@Test
52+
public void doubleNavigateToExploreThenReturnHome() {
53+
// Explore
54+
openNavigationDrawerAndNavigateTo(R.id.action_explore);
55+
56+
// Explore
57+
openNavigationDrawerAndNavigateTo(R.id.action_explore);
58+
59+
// Home
60+
openNavigationDrawerAndNavigateTo(R.id.action_home);
61+
}
62+
63+
public void openNavigationDrawerAndNavigateTo(int menuItemId) {
64+
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
65+
onView(withId(R.id.navigation_view)).perform(NavigationViewActions.navigateTo(menuItemId));
66+
}
67+
}

0 commit comments

Comments
 (0)