Add More Bottom Sheet Fragments Unit Tests (#4172)

* Add More Bottom Sheet Fragment Unit Tests

* Add More Bottom Sheet Logged Out Fragment Unit Tests
This commit is contained in:
Madhur Gupta 2021-01-13 22:08:31 +05:30 committed by GitHub
parent bd90497936
commit 7f2316fe46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 168 additions and 0 deletions

View file

@ -0,0 +1,93 @@
package fr.free.nrw.commons.navtab
import android.content.Context
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import fr.free.nrw.commons.TestCommonsApplication
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.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [21], application = TestCommonsApplication::class)
class MoreBottomSheetFragmentUnitTests {
private lateinit var fragment: MoreBottomSheetFragment
private lateinit var context: Context
@Before
fun setUp() {
context = RuntimeEnvironment.application.applicationContext
val activity = Robolectric.buildActivity(ProfileActivity::class.java).create().get()
fragment = MoreBottomSheetFragment()
val fragmentManager: FragmentManager = activity.supportFragmentManager
val fragmentTransaction: FragmentTransaction = fragmentManager.beginTransaction()
fragmentTransaction.add(fragment, null)
fragmentTransaction.commit()
}
@Test
@Throws(Exception::class)
fun checkFragmentNotNull() {
Assert.assertNotNull(fragment)
}
@Test
@Throws(Exception::class)
fun testOnAttach() {
fragment.onAttach(context)
}
@Test
@Throws(Exception::class)
fun testOnLogoutClicked() {
fragment.onLogoutClicked()
}
@Test
@Throws(Exception::class)
fun testOnFeedbackClicked() {
fragment.onFeedbackClicked()
}
@Test
@Throws(Exception::class)
fun testOnAboutClicked() {
fragment.onAboutClicked()
}
@Test
@Throws(Exception::class)
fun testOnTutorialClicked() {
fragment.onTutorialClicked()
}
@Test
@Throws(Exception::class)
fun testOnSettingsClicked() {
fragment.onSettingsClicked()
}
@Test
@Throws(Exception::class)
fun testOnProfileClicked() {
fragment.onProfileClicked()
}
@Test
@Throws(Exception::class)
fun testOnPeerReviewClicked() {
fragment.onPeerReviewClicked()
}
}

View file

@ -0,0 +1,75 @@
package fr.free.nrw.commons.navtab
import android.content.Context
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import fr.free.nrw.commons.TestCommonsApplication
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.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [21], application = TestCommonsApplication::class)
class MoreBottomSheetLoggedOutFragmentUnitTests {
private lateinit var fragment: MoreBottomSheetLoggedOutFragment
private lateinit var context: Context
@Before
fun setUp() {
context = RuntimeEnvironment.application.applicationContext
val activity = Robolectric.buildActivity(ProfileActivity::class.java).create().get()
fragment = MoreBottomSheetLoggedOutFragment()
val fragmentManager: FragmentManager = activity.supportFragmentManager
val fragmentTransaction: FragmentTransaction = fragmentManager.beginTransaction()
fragmentTransaction.add(fragment, null)
fragmentTransaction.commit()
}
@Test
@Throws(Exception::class)
fun checkFragmentNotNull() {
Assert.assertNotNull(fragment)
}
@Test
@Throws(Exception::class)
fun testOnTutorialClicked() {
fragment.onTutorialClicked()
}
@Test
@Throws(Exception::class)
fun testOnSettingsClicked() {
fragment.onSettingsClicked()
}
@Test
@Throws(Exception::class)
fun testOnAboutClicked() {
fragment.onAboutClicked()
}
@Test
@Throws(Exception::class)
fun testOnFeedbackClicked() {
fragment.onFeedbackClicked()
}
@Test
@Throws(Exception::class)
fun testOnLogoutClicked() {
fragment.onLogoutClicked()
}
}