mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Added option for sharing achievements and a back button in ProfileActivity (#4489)
* UI done * Share added * Minor modification * tests added * tests added * tests added * modified * modifications * modification * Entered if * Entered if * 97% coverage * Separate * Minor modifications * Minor modifications
This commit is contained in:
parent
9643d8d0b8
commit
3b7aa0376d
5 changed files with 189 additions and 118 deletions
|
|
@ -1,30 +1,46 @@
|
|||
package fr.free.nrw.commons.profile
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Looper
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.powermock.api.mockito.PowerMockito
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.Shadows
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.fakes.RoboMenu
|
||||
import org.robolectric.fakes.RoboMenuItem
|
||||
import java.lang.reflect.Method
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class ProfileActivityTest {
|
||||
|
||||
@Mock
|
||||
private lateinit var activity: ProfileActivity
|
||||
private lateinit var profileActivity: ProfileActivity
|
||||
|
||||
@Mock
|
||||
private lateinit var mockContext: Context
|
||||
|
||||
@Mock
|
||||
private lateinit var bitmap: Bitmap
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
activity = Robolectric.buildActivity(ProfileActivity::class.java).create().get()
|
||||
mockContext = PowerMockito.mock(Context::class.java)
|
||||
profileActivity = PowerMockito.mock(ProfileActivity::class.java)
|
||||
mockContext = RuntimeEnvironment.application.applicationContext
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -41,8 +57,53 @@ class ProfileActivityTest {
|
|||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testStartYourself() {
|
||||
ProfileActivity.startYourself(mockContext)
|
||||
fun testOnCreateOptionsMenu() {
|
||||
val menu: Menu = RoboMenu(mockContext)
|
||||
activity.onCreateOptionsMenu(menu)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnOptionsItemSelected() {
|
||||
val menuItem: MenuItem = RoboMenuItem(R.menu.menu_about)
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
activity.onOptionsItemSelected(menuItem)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnOptionsShareItemSelected() {
|
||||
val menuItemShare: MenuItem = RoboMenuItem(R.id.share_app_icon)
|
||||
activity.onOptionsItemSelected(menuItemShare)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testStartYourself() {
|
||||
ProfileActivity.startYourself(activity)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowAlert() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
activity.showAlert(bitmap)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShareScreen() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = ProfileActivity::class.java.getDeclaredMethod(
|
||||
"shareScreen", Bitmap::class.java
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, bitmap)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnSupportNavigateUp() {
|
||||
activity.onSupportNavigateUp()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package fr.free.nrw.commons.profile.achievements
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Looper
|
||||
import android.view.MenuItem
|
||||
import android.widget.ImageView
|
||||
|
|
@ -83,9 +82,6 @@ class AchievementsFragmentUnitTests {
|
|||
@Mock
|
||||
private lateinit var imageUploadedText: TextView
|
||||
|
||||
@Mock
|
||||
private lateinit var bitmap: Bitmap
|
||||
|
||||
@Mock
|
||||
private lateinit var progressBar: ProgressBar
|
||||
|
||||
|
|
@ -143,14 +139,6 @@ class AchievementsFragmentUnitTests {
|
|||
Assert.assertNotNull(fragment)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowAlert() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.showAlert(bitmap)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowInfoDialog() {
|
||||
|
|
@ -329,16 +317,4 @@ class AchievementsFragmentUnitTests {
|
|||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShareScreen() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
|
||||
"shareScreen", Bitmap::class.java
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, bitmap)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue