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