1
0
Fork 0

Closes #5852 - Use createAddedTestFragments in tests.

master
Ahmed I. Khalil 2019-10-08 20:07:32 +02:00 committed by Emily Kager
parent 55e6e00355
commit f008d29bf3
2 changed files with 5 additions and 40 deletions

View File

@ -4,17 +4,16 @@
package org.mozilla.fenix.collections
import androidx.fragment.app.FragmentActivity
import androidx.test.ext.junit.runners.AndroidJUnit4
import assertk.assertThat
import assertk.assertions.isNotNull
import assertk.assertions.isNull
import assertk.assertions.isTrue
import kotlinx.coroutines.ObsoleteCoroutinesApi
import mozilla.components.support.test.robolectric.createAddedTestFragment
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.TestApplication
import org.robolectric.Robolectric
import org.robolectric.annotation.Config
@ObsoleteCoroutinesApi
@ -23,18 +22,7 @@ import org.robolectric.annotation.Config
class CreateCollectionFragmentTest {
@Test
fun `creation dialog shows and can be dismissed`() {
val activity = Robolectric.buildActivity(FragmentActivity::class.java)
.create()
.start()
.resume()
.get()
val fragment = CreateCollectionFragment()
activity.supportFragmentManager.beginTransaction().apply {
add(fragment, "test")
commitNow()
}
val fragment = createAddedTestFragment { CreateCollectionFragment() }
assertThat(fragment.dialog).isNotNull()
assertThat(fragment.requireDialog().isShowing).isTrue()

View File

@ -5,18 +5,17 @@
package org.mozilla.fenix.components
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import kotlinx.coroutines.ObsoleteCoroutinesApi
import mozilla.components.lib.state.Action
import mozilla.components.lib.state.State
import mozilla.components.lib.state.Store
import mozilla.components.support.test.robolectric.createAddedTestFragment
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.TestApplication
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@ -46,18 +45,7 @@ class StoreProviderTest {
@Test
fun `get returns store`() {
val activity = Robolectric.buildActivity(FragmentActivity::class.java)
.create()
.start()
.resume()
.get()
val fragment = Fragment()
activity.supportFragmentManager.beginTransaction().apply {
add(fragment, "test")
commitNow()
}
val fragment = createAddedTestFragment { Fragment() }
val store = StoreProvider.get(fragment) { basicStore }
assertEquals(basicStore, store)
@ -65,18 +53,7 @@ class StoreProviderTest {
@Test
fun `get only calls createStore if needed`() {
val activity = Robolectric.buildActivity(FragmentActivity::class.java)
.create()
.start()
.resume()
.get()
val fragment = Fragment()
activity.supportFragmentManager.beginTransaction().apply {
add(fragment, "test")
commitNow()
}
val fragment = createAddedTestFragment { Fragment() }
var createCalled = false
val createStore = {