Convert instrumentation tests to Kotlin (#2689)

* Convert SettingsActivityTest to Kotlin

* Convert NavigationBaseActivityTest to Kotlin

* Convert UploadTest to Kotlin
This commit is contained in:
Adam Jones 2019-03-21 04:56:36 +00:00 committed by Vivek Maskara
parent 0612519e1c
commit 268ba07648
5 changed files with 317 additions and 343 deletions

View file

@ -0,0 +1,65 @@
package fr.free.nrw.commons
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.contrib.DrawerActions
import androidx.test.espresso.contrib.NavigationViewActions
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import androidx.test.runner.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@LargeTest
@RunWith(AndroidJUnit4::class)
class NavigationBaseActivityTest {
@get:Rule
var activityRule: ActivityTestRule<*> = ActivityTestRule(AboutActivity::class.java)
/**
* 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
fun 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
fun doubleNavigateToExploreThenReturnHome() {
// Explore
openNavigationDrawerAndNavigateTo(R.id.action_explore)
// Explore
openNavigationDrawerAndNavigateTo(R.id.action_explore)
// Home
openNavigationDrawerAndNavigateTo(R.id.action_home)
}
private fun openNavigationDrawerAndNavigateTo(menuItemId: Int) {
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())
onView(withId(R.id.navigation_view)).perform(NavigationViewActions.navigateTo(menuItemId))
}
}