Closes #4719: Get rid of fragment-testing dependency and create fragments in StoreProviderTest manually. (#4722)
parent
e6f9445d11
commit
b733fcdbd5
|
@ -415,12 +415,6 @@ dependencies {
|
|||
}
|
||||
|
||||
testImplementation 'org.apache.maven:maven-ant-tasks:2.1.3'
|
||||
debugImplementation Deps.fragment_testing, {
|
||||
exclude group: 'androidx.test', module: 'core'
|
||||
}
|
||||
forPerformanceTestImplementation Deps.fragment_testing, {
|
||||
exclude group: 'androidx.test', module: 'core'
|
||||
}
|
||||
// For production builds, the native code for all `org.mozilla.appservices`
|
||||
// dependencies gets compiled together into a single "megazord" build, and
|
||||
// different megazords are published for different subsets of features. Ref
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
package org.mozilla.fenix.components
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.testing.launchFragmentInContainer
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import kotlinx.coroutines.ObsoleteCoroutinesApi
|
||||
import mozilla.components.lib.state.Action
|
||||
import mozilla.components.lib.state.State
|
||||
|
@ -16,6 +16,7 @@ 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
|
||||
|
||||
|
@ -45,31 +46,49 @@ class StoreProviderTest {
|
|||
|
||||
@Test
|
||||
fun `get returns store`() {
|
||||
val scenario = launchFragmentInContainer { Fragment() }
|
||||
scenario.onFragment {
|
||||
val store = StoreProvider.get(it) { basicStore }
|
||||
assertEquals(basicStore, store)
|
||||
val activity = Robolectric.buildActivity(FragmentActivity::class.java)
|
||||
.create()
|
||||
.start()
|
||||
.resume()
|
||||
.get()
|
||||
|
||||
val fragment = Fragment()
|
||||
|
||||
activity.supportFragmentManager.beginTransaction().apply {
|
||||
add(fragment, "test")
|
||||
commitNow()
|
||||
}
|
||||
|
||||
val store = StoreProvider.get(fragment) { basicStore }
|
||||
assertEquals(basicStore, store)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `get only calls createStore if needed`() {
|
||||
val scenario = launchFragmentInContainer { Fragment() }
|
||||
val activity = Robolectric.buildActivity(FragmentActivity::class.java)
|
||||
.create()
|
||||
.start()
|
||||
.resume()
|
||||
.get()
|
||||
|
||||
val fragment = Fragment()
|
||||
|
||||
activity.supportFragmentManager.beginTransaction().apply {
|
||||
add(fragment, "test")
|
||||
commitNow()
|
||||
}
|
||||
|
||||
var createCalled = false
|
||||
val createStore = {
|
||||
createCalled = true
|
||||
basicStore
|
||||
}
|
||||
|
||||
scenario.onFragment {
|
||||
StoreProvider.get(it, createStore)
|
||||
}
|
||||
StoreProvider.get(fragment, createStore)
|
||||
assertTrue(createCalled)
|
||||
|
||||
createCalled = false
|
||||
scenario.onFragment {
|
||||
StoreProvider.get(it, createStore)
|
||||
}
|
||||
StoreProvider.get(fragment, createStore)
|
||||
assertFalse(createCalled)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -203,7 +203,6 @@ object Deps {
|
|||
const val tools_test_runner = "androidx.test:runner:${Versions.tools_test_runner}"
|
||||
const val uiautomator = "com.android.support.test.uiautomator:uiautomator-v18:${Versions.uiautomator}"
|
||||
const val robolectric = "org.robolectric:robolectric:${Versions.robolectric}"
|
||||
const val fragment_testing = "androidx.fragment:fragment-testing:${Versions.androidx_fragment}"
|
||||
const val androidx_junit = "androidx.test.ext:junit:${Versions.androidx_test_ext}"
|
||||
const val androidx_test_core = "androidx.test:core:${Versions.androidx_testing}"
|
||||
|
||||
|
|
Loading…
Reference in New Issue