mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Add CommonPlaceClickActions Unit Tests (#4674)
This commit is contained in:
parent
0269894c64
commit
d1bf6d0e1d
2 changed files with 115 additions and 9 deletions
|
|
@ -74,7 +74,7 @@ class CommonPlaceClickActions @Inject constructor(
|
|||
|
||||
private fun openWebView(link: Uri): Boolean {
|
||||
Utils.handleWebUrl(activity, link)
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
|
||||
private fun PopupMenu.enableBy(menuId: Int, hasLink: Boolean) {
|
||||
|
|
@ -85,15 +85,19 @@ class CommonPlaceClickActions @Inject constructor(
|
|||
AlertDialog.Builder(activity)
|
||||
.setMessage(R.string.login_alert_message)
|
||||
.setPositiveButton(R.string.login) { dialog, which ->
|
||||
ActivityUtils.startActivityWithFlags(
|
||||
activity,
|
||||
LoginActivity::class.java,
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP,
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||
)
|
||||
applicationKvStore.putBoolean("login_skipped", false)
|
||||
activity.finish()
|
||||
setPositiveButton()
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun setPositiveButton() {
|
||||
ActivityUtils.startActivityWithFlags(
|
||||
activity,
|
||||
LoginActivity::class.java,
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP,
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||
)
|
||||
applicationKvStore.putBoolean("login_skipped", false)
|
||||
activity.finish()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,102 @@
|
|||
package fr.free.nrw.commons.nearby
|
||||
|
||||
import android.net.Uri
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.contributions.ContributionController
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||
import fr.free.nrw.commons.nearby.fragments.CommonPlaceClickActions
|
||||
import fr.free.nrw.commons.profile.ProfileActivity
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.LooperMode
|
||||
import java.lang.reflect.Method
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class CommonPlaceClickActionsUnitTest {
|
||||
|
||||
private lateinit var commonPlaceClickActions: CommonPlaceClickActions
|
||||
|
||||
@Mock
|
||||
private lateinit var store: JsonKvStore
|
||||
|
||||
@Mock
|
||||
private lateinit var contributionController: ContributionController
|
||||
|
||||
@Mock
|
||||
private lateinit var place: Place
|
||||
|
||||
@Mock
|
||||
private lateinit var uri: Uri
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
val activity = Robolectric.buildActivity(ProfileActivity::class.java).create().get()
|
||||
commonPlaceClickActions = CommonPlaceClickActions(store, activity, contributionController)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNonNull() {
|
||||
Assert.assertNotNull(commonPlaceClickActions)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFunctionDeclaration() {
|
||||
Assert.assertNotNull(commonPlaceClickActions.onCameraClicked())
|
||||
Assert.assertNotNull(commonPlaceClickActions.onGalleryClicked())
|
||||
Assert.assertNotNull(commonPlaceClickActions.onOverflowClicked())
|
||||
Assert.assertNotNull(commonPlaceClickActions.onDirectionsClicked())
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testStoreSharedPrefs() {
|
||||
val method: Method = CommonPlaceClickActions::class.java.getDeclaredMethod(
|
||||
"storeSharedPrefs",
|
||||
Place::class.java
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(commonPlaceClickActions, place)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOpenWebView() {
|
||||
val method: Method = CommonPlaceClickActions::class.java.getDeclaredMethod(
|
||||
"openWebView",
|
||||
Uri::class.java
|
||||
)
|
||||
method.isAccessible = true
|
||||
Assert.assertEquals(method.invoke(commonPlaceClickActions, uri), true)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowLoginDialog() {
|
||||
val method: Method = CommonPlaceClickActions::class.java.getDeclaredMethod(
|
||||
"showLoginDialog"
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(commonPlaceClickActions)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetPositiveButton() {
|
||||
val method: Method = CommonPlaceClickActions::class.java.getDeclaredMethod(
|
||||
"setPositiveButton"
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(commonPlaceClickActions)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue