mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
Fix nav graph and theme tests (#12567)
This commit is contained in:
parent
d0e9f1f165
commit
a0491b702e
@ -15,10 +15,10 @@ import mozilla.components.concept.engine.Engine
|
||||
import mozilla.components.concept.storage.HistoryStorage
|
||||
import mozilla.components.feature.toolbar.ToolbarAutocompleteFeature
|
||||
import mozilla.components.support.ktx.android.content.getColorFromAttr
|
||||
import mozilla.components.support.ktx.android.content.res.resolveAttribute
|
||||
import mozilla.components.support.ktx.android.view.hideKeyboard
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.search.SearchFragmentState
|
||||
import org.mozilla.fenix.theme.ThemeManager
|
||||
|
||||
/**
|
||||
* Interface for the Toolbar Interactor. This interface is implemented by objects that want
|
||||
@ -71,10 +71,9 @@ class ToolbarView(
|
||||
false
|
||||
}
|
||||
|
||||
background =
|
||||
AppCompatResources.getDrawable(
|
||||
context, ThemeManager.resolveAttribute(R.attr.foundation, context)
|
||||
)
|
||||
background = AppCompatResources.getDrawable(
|
||||
context, context.theme.resolveAttribute(R.attr.foundation)
|
||||
)
|
||||
|
||||
edit.hint = context.getString(R.string.search_hint)
|
||||
|
||||
|
@ -4,18 +4,13 @@
|
||||
|
||||
package org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import io.mockk.every
|
||||
import androidx.appcompat.view.ContextThemeWrapper
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.unmockkStatic
|
||||
import io.mockk.verify
|
||||
import kotlinx.android.synthetic.main.onboarding_private_browsing.view.*
|
||||
import mozilla.components.support.ktx.android.content.res.resolveAttribute
|
||||
import mozilla.components.support.test.robolectric.testContext
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
@ -31,19 +26,10 @@ class OnboardingPrivacyBrowsingViewHolderTest {
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
mockkStatic("mozilla.components.support.ktx.android.content.res.ThemeKt")
|
||||
view = LayoutInflater.from(testContext)
|
||||
val context = ContextThemeWrapper(testContext, R.style.NormalTheme)
|
||||
view = LayoutInflater.from(context)
|
||||
.inflate(OnboardingPrivateBrowsingViewHolder.LAYOUT_ID, null)
|
||||
interactor = mockk(relaxed = true)
|
||||
|
||||
every {
|
||||
any<Resources.Theme>().resolveAttribute(R.attr.onboardingSelected)
|
||||
} returns R.color.onboarding_illustration_selected_normal_theme
|
||||
}
|
||||
|
||||
@After
|
||||
fun teardown() {
|
||||
unmockkStatic("mozilla.components.support.ktx.android.content.res.ThemeKt")
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -4,18 +4,13 @@
|
||||
|
||||
package org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import io.mockk.every
|
||||
import androidx.appcompat.view.ContextThemeWrapper
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.unmockkStatic
|
||||
import io.mockk.verify
|
||||
import kotlinx.android.synthetic.main.onboarding_privacy_notice.view.*
|
||||
import mozilla.components.support.ktx.android.content.res.resolveAttribute
|
||||
import mozilla.components.support.test.robolectric.testContext
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
@ -31,19 +26,10 @@ class OnboardingPrivacyNoticeViewHolderTest {
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
mockkStatic("mozilla.components.support.ktx.android.content.res.ThemeKt")
|
||||
view = LayoutInflater.from(testContext)
|
||||
val context = ContextThemeWrapper(testContext, R.style.NormalTheme)
|
||||
view = LayoutInflater.from(context)
|
||||
.inflate(OnboardingPrivacyNoticeViewHolder.LAYOUT_ID, null)
|
||||
interactor = mockk(relaxed = true)
|
||||
|
||||
every {
|
||||
any<Resources.Theme>().resolveAttribute(R.attr.onboardingSelected)
|
||||
} returns R.color.onboarding_illustration_selected_normal_theme
|
||||
}
|
||||
|
||||
@After
|
||||
fun teardown() {
|
||||
unmockkStatic("mozilla.components.support.ktx.android.content.res.ThemeKt")
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -4,16 +4,11 @@
|
||||
|
||||
package org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import io.mockk.every
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.unmockkStatic
|
||||
import androidx.appcompat.view.ContextThemeWrapper
|
||||
import kotlinx.android.synthetic.main.onboarding_tracking_protection.view.*
|
||||
import mozilla.components.support.ktx.android.content.res.resolveAttribute
|
||||
import mozilla.components.support.test.robolectric.testContext
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
@ -28,18 +23,9 @@ class OnboardingTrackingProtectionViewHolderTest {
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
mockkStatic("mozilla.components.support.ktx.android.content.res.ThemeKt")
|
||||
view = LayoutInflater.from(testContext)
|
||||
val context = ContextThemeWrapper(testContext, R.style.NormalTheme)
|
||||
view = LayoutInflater.from(context)
|
||||
.inflate(OnboardingTrackingProtectionViewHolder.LAYOUT_ID, null)
|
||||
|
||||
every {
|
||||
any<Resources.Theme>().resolveAttribute(R.attr.onboardingSelected)
|
||||
} returns R.color.onboarding_illustration_selected_normal_theme
|
||||
}
|
||||
|
||||
@After
|
||||
fun teardown() {
|
||||
unmockkStatic("mozilla.components.support.ktx.android.content.res.ThemeKt")
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -25,6 +25,7 @@ import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
||||
import org.mozilla.fenix.components.FenixSnackbar
|
||||
import org.mozilla.fenix.ext.directionsEq
|
||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||
|
||||
// Robolectric needed for `onShareItem()`
|
||||
@ -189,15 +190,12 @@ class HistoryControllerTest {
|
||||
fun onShareItem() {
|
||||
controller.handleShare(historyItem)
|
||||
|
||||
// `verify` checks for referential equality.
|
||||
// This would fail as the NavDirections are created and used in place in the tested method.
|
||||
// Capture the NavDirections and `assert` for structural equality after.
|
||||
verify {
|
||||
navController.navigate(
|
||||
navController.navigate(directionsEq(
|
||||
HistoryFragmentDirections.actionGlobalShareFragment(
|
||||
data = arrayOf(ShareData(url = historyItem.url, title = historyItem.title))
|
||||
)
|
||||
)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
package org.mozilla.fenix.search.toolbar
|
||||
|
||||
import android.content.Context
|
||||
import androidx.appcompat.view.ContextThemeWrapper
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.Runs
|
||||
import io.mockk.every
|
||||
@ -21,6 +23,7 @@ import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||
|
||||
@RunWith(FenixRobolectricTestRunner::class)
|
||||
@ -28,12 +31,14 @@ class ToolbarViewTest {
|
||||
|
||||
@MockK(relaxed = true) private lateinit var interactor: ToolbarInteractor
|
||||
@MockK private lateinit var engine: Engine
|
||||
private lateinit var context: Context
|
||||
private lateinit var toolbar: BrowserToolbar
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
MockKAnnotations.init(this)
|
||||
toolbar = spyk(BrowserToolbar(testContext))
|
||||
context = ContextThemeWrapper(testContext, R.style.NormalTheme)
|
||||
toolbar = spyk(BrowserToolbar(context))
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -68,7 +73,7 @@ class ToolbarViewTest {
|
||||
}
|
||||
|
||||
private fun buildToolbarView(isPrivate: Boolean) = ToolbarView(
|
||||
testContext,
|
||||
context,
|
||||
interactor,
|
||||
historyStorage = null,
|
||||
isPrivate = isPrivate,
|
||||
|
Loading…
Reference in New Issue
Block a user