parent
447b134fe9
commit
96b68948b5
@ -0,0 +1,17 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix
|
||||||
|
|
||||||
|
import org.mozilla.fenix.components.Components
|
||||||
|
import org.mozilla.fenix.components.TestComponents
|
||||||
|
|
||||||
|
class TestApplication : FenixApplication() {
|
||||||
|
|
||||||
|
override val components: Components
|
||||||
|
get() = TestComponents(this)
|
||||||
|
|
||||||
|
override fun setupApplication() {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.components
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import mozilla.components.browser.storage.sync.PlacesBookmarksStorage
|
||||||
|
import mozilla.components.browser.storage.sync.PlacesHistoryStorage
|
||||||
|
import mozilla.components.feature.sync.BackgroundSyncManager
|
||||||
|
|
||||||
|
class TestBackgroundServices(
|
||||||
|
context: Context,
|
||||||
|
historyStorage: PlacesHistoryStorage,
|
||||||
|
bookmarksStorage: PlacesBookmarksStorage
|
||||||
|
) : BackgroundServices(context, historyStorage, bookmarksStorage) {
|
||||||
|
override val syncManager = BackgroundSyncManager("")
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package org.mozilla.fenix.components
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import io.mockk.mockk
|
||||||
|
|
||||||
|
class TestComponents(private val context: Context) : Components(context) {
|
||||||
|
override val backgroundServices by lazy {
|
||||||
|
mockk<BackgroundServices>(relaxed = true)
|
||||||
|
}
|
||||||
|
override val services by lazy { Services(backgroundServices.accountManager, useCases.tabsUseCases) }
|
||||||
|
override val core by lazy { TestCore(context) }
|
||||||
|
override val search by lazy { Search(context) }
|
||||||
|
override val useCases by lazy { UseCases(context, core.sessionManager, search.searchEngineManager) }
|
||||||
|
override val utils by lazy {
|
||||||
|
Utilities(
|
||||||
|
context,
|
||||||
|
core.sessionManager,
|
||||||
|
useCases.sessionUseCases,
|
||||||
|
useCases.searchUseCases
|
||||||
|
)
|
||||||
|
}
|
||||||
|
override val analytics by lazy { Analytics(context) }
|
||||||
|
override val storage by lazy { Storage(context) }
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.components
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import io.mockk.mockk
|
||||||
|
import kotlinx.coroutines.ObsoleteCoroutinesApi
|
||||||
|
import mozilla.components.browser.engine.gecko.GeckoEngine
|
||||||
|
import mozilla.components.browser.session.SessionManager
|
||||||
|
import org.mozilla.geckoview.GeckoRuntime
|
||||||
|
|
||||||
|
@ObsoleteCoroutinesApi
|
||||||
|
class TestCore(private val context: Context) : Core(context) {
|
||||||
|
|
||||||
|
override val runtime = mockk<GeckoRuntime>(relaxed = true)
|
||||||
|
override val engine = mockk<GeckoEngine>(relaxed = true)
|
||||||
|
override val sessionManager = SessionManager(engine)
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.library.bookmarks
|
||||||
|
|
||||||
|
import androidx.fragment.app.testing.FragmentScenario
|
||||||
|
import androidx.fragment.app.testing.launchFragmentInContainer
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import androidx.navigation.Navigation
|
||||||
|
import io.mockk.Runs
|
||||||
|
import io.mockk.every
|
||||||
|
import io.mockk.just
|
||||||
|
import io.mockk.mockk
|
||||||
|
import kotlinx.coroutines.ObsoleteCoroutinesApi
|
||||||
|
import mozilla.appservices.places.BookmarkRoot
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.mozilla.fenix.R
|
||||||
|
import org.mozilla.fenix.TestApplication
|
||||||
|
import org.mozilla.fenix.TestUtils
|
||||||
|
import org.robolectric.RobolectricTestRunner
|
||||||
|
import org.robolectric.annotation.Config
|
||||||
|
|
||||||
|
@ObsoleteCoroutinesApi
|
||||||
|
@RunWith(RobolectricTestRunner::class)
|
||||||
|
@Config(application = TestApplication::class)
|
||||||
|
class BookmarkFragmentTest {
|
||||||
|
|
||||||
|
private lateinit var scenario: FragmentScenario<BookmarkFragment>
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
TestUtils.setRxSchedulers()
|
||||||
|
|
||||||
|
val mockNavController = mockk<NavController>()
|
||||||
|
every { mockNavController.addOnDestinationChangedListener(any()) } just Runs
|
||||||
|
|
||||||
|
val args = BookmarkFragmentArgs(BookmarkRoot.Mobile.id).toBundle()
|
||||||
|
scenario =
|
||||||
|
launchFragmentInContainer<BookmarkFragment>(fragmentArgs = args, themeResId = R.style.NormalTheme) {
|
||||||
|
BookmarkFragment().also { fragment ->
|
||||||
|
fragment.viewLifecycleOwnerLiveData.observeForever {
|
||||||
|
if (it != null) {
|
||||||
|
Navigation.setViewNavController(fragment.requireView(), mockNavController)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test initial bookmarks fragment ui`() {
|
||||||
|
scenario.onFragment { fragment ->
|
||||||
|
assertEquals(fragment.getString(R.string.library_bookmarks), fragment.activity?.title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +0,0 @@
|
|||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
package org.mozilla.fenix.test
|
|
||||||
|
|
||||||
annotation class Mockable
|
|
@ -0,0 +1,18 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.test
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Annotate a class with [OpenClass] to open a class for mocking purposes while keeping it final in release builds
|
||||||
|
*/
|
||||||
|
@Target(AnnotationTarget.ANNOTATION_CLASS)
|
||||||
|
annotation class OpenClass
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Annotate a class with [Mockable] to make it extensible in debug builds
|
||||||
|
*/
|
||||||
|
@OpenClass
|
||||||
|
@Target(AnnotationTarget.CLASS)
|
||||||
|
annotation class Mockable
|
Loading…
Reference in New Issue