Closes #5852 - Use createAddedTestFragments in tests.
parent
55e6e00355
commit
f008d29bf3
|
@ -4,17 +4,16 @@
|
||||||
|
|
||||||
package org.mozilla.fenix.collections
|
package org.mozilla.fenix.collections
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentActivity
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import assertk.assertThat
|
import assertk.assertThat
|
||||||
import assertk.assertions.isNotNull
|
import assertk.assertions.isNotNull
|
||||||
import assertk.assertions.isNull
|
import assertk.assertions.isNull
|
||||||
import assertk.assertions.isTrue
|
import assertk.assertions.isTrue
|
||||||
import kotlinx.coroutines.ObsoleteCoroutinesApi
|
import kotlinx.coroutines.ObsoleteCoroutinesApi
|
||||||
|
import mozilla.components.support.test.robolectric.createAddedTestFragment
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mozilla.fenix.TestApplication
|
import org.mozilla.fenix.TestApplication
|
||||||
import org.robolectric.Robolectric
|
|
||||||
import org.robolectric.annotation.Config
|
import org.robolectric.annotation.Config
|
||||||
|
|
||||||
@ObsoleteCoroutinesApi
|
@ObsoleteCoroutinesApi
|
||||||
|
@ -23,18 +22,7 @@ import org.robolectric.annotation.Config
|
||||||
class CreateCollectionFragmentTest {
|
class CreateCollectionFragmentTest {
|
||||||
@Test
|
@Test
|
||||||
fun `creation dialog shows and can be dismissed`() {
|
fun `creation dialog shows and can be dismissed`() {
|
||||||
val activity = Robolectric.buildActivity(FragmentActivity::class.java)
|
val fragment = createAddedTestFragment { CreateCollectionFragment() }
|
||||||
.create()
|
|
||||||
.start()
|
|
||||||
.resume()
|
|
||||||
.get()
|
|
||||||
|
|
||||||
val fragment = CreateCollectionFragment()
|
|
||||||
|
|
||||||
activity.supportFragmentManager.beginTransaction().apply {
|
|
||||||
add(fragment, "test")
|
|
||||||
commitNow()
|
|
||||||
}
|
|
||||||
|
|
||||||
assertThat(fragment.dialog).isNotNull()
|
assertThat(fragment.dialog).isNotNull()
|
||||||
assertThat(fragment.requireDialog().isShowing).isTrue()
|
assertThat(fragment.requireDialog().isShowing).isTrue()
|
||||||
|
|
|
@ -5,18 +5,17 @@
|
||||||
package org.mozilla.fenix.components
|
package org.mozilla.fenix.components
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentActivity
|
|
||||||
import kotlinx.coroutines.ObsoleteCoroutinesApi
|
import kotlinx.coroutines.ObsoleteCoroutinesApi
|
||||||
import mozilla.components.lib.state.Action
|
import mozilla.components.lib.state.Action
|
||||||
import mozilla.components.lib.state.State
|
import mozilla.components.lib.state.State
|
||||||
import mozilla.components.lib.state.Store
|
import mozilla.components.lib.state.Store
|
||||||
|
import mozilla.components.support.test.robolectric.createAddedTestFragment
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assert.assertFalse
|
import org.junit.Assert.assertFalse
|
||||||
import org.junit.Assert.assertTrue
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mozilla.fenix.TestApplication
|
import org.mozilla.fenix.TestApplication
|
||||||
import org.robolectric.Robolectric
|
|
||||||
import org.robolectric.RobolectricTestRunner
|
import org.robolectric.RobolectricTestRunner
|
||||||
import org.robolectric.annotation.Config
|
import org.robolectric.annotation.Config
|
||||||
|
|
||||||
|
@ -46,18 +45,7 @@ class StoreProviderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `get returns store`() {
|
fun `get returns store`() {
|
||||||
val activity = Robolectric.buildActivity(FragmentActivity::class.java)
|
val fragment = createAddedTestFragment { Fragment() }
|
||||||
.create()
|
|
||||||
.start()
|
|
||||||
.resume()
|
|
||||||
.get()
|
|
||||||
|
|
||||||
val fragment = Fragment()
|
|
||||||
|
|
||||||
activity.supportFragmentManager.beginTransaction().apply {
|
|
||||||
add(fragment, "test")
|
|
||||||
commitNow()
|
|
||||||
}
|
|
||||||
|
|
||||||
val store = StoreProvider.get(fragment) { basicStore }
|
val store = StoreProvider.get(fragment) { basicStore }
|
||||||
assertEquals(basicStore, store)
|
assertEquals(basicStore, store)
|
||||||
|
@ -65,18 +53,7 @@ class StoreProviderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `get only calls createStore if needed`() {
|
fun `get only calls createStore if needed`() {
|
||||||
val activity = Robolectric.buildActivity(FragmentActivity::class.java)
|
val fragment = createAddedTestFragment { Fragment() }
|
||||||
.create()
|
|
||||||
.start()
|
|
||||||
.resume()
|
|
||||||
.get()
|
|
||||||
|
|
||||||
val fragment = Fragment()
|
|
||||||
|
|
||||||
activity.supportFragmentManager.beginTransaction().apply {
|
|
||||||
add(fragment, "test")
|
|
||||||
commitNow()
|
|
||||||
}
|
|
||||||
|
|
||||||
var createCalled = false
|
var createCalled = false
|
||||||
val createStore = {
|
val createStore = {
|
||||||
|
|
Loading…
Reference in New Issue