2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-17 15:26:23 +00:00

Bug 1831083 - Refactor DefaultReaderModeController to improve testing.

This commit is contained in:
mcarare 2023-05-03 15:30:22 +03:00 committed by mergify[bot]
parent 0d83254b5f
commit 5a1ecb81f5
2 changed files with 34 additions and 20 deletions

View File

@ -8,6 +8,7 @@ import android.view.View
import android.widget.Button
import android.widget.RadioButton
import androidx.appcompat.content.res.AppCompatResources
import com.google.android.gms.common.util.VisibleForTesting
import mozilla.components.feature.readerview.ReaderViewFeature
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import org.mozilla.fenix.R
@ -27,6 +28,21 @@ class DefaultReaderModeController(
private val isPrivate: Boolean = false,
private val onReaderModeChanged: () -> Unit = {},
) : ReaderModeController {
@VisibleForTesting
internal val privateButtonColor
get() = AppCompatResources.getColorStateList(
readerViewControlsBar.context,
R.color.readerview_private_button_color,
)
@VisibleForTesting
internal val privateRadioButtonColor
get() = AppCompatResources.getColorStateList(
readerViewControlsBar.context,
R.color.readerview_private_radio_color,
)
override fun hideReaderView() {
onReaderModeChanged()
readerViewFeature.withFeature {
@ -56,12 +72,7 @@ class DefaultReaderModeController(
).map {
findViewById<Button>(it)
}.forEach {
it.setTextColor(
AppCompatResources.getColorStateList(
context,
R.color.readerview_private_button_color,
),
)
it.setTextColor(privateButtonColor)
}
listOf(
@ -70,12 +81,7 @@ class DefaultReaderModeController(
).map {
findViewById<RadioButton>(it)
}.forEach {
it.setTextColor(
AppCompatResources.getColorStateList(
context,
R.color.readerview_private_radio_color,
),
)
it.setTextColor(privateRadioButtonColor)
}
}
}

View File

@ -99,12 +99,20 @@ class DefaultReaderModeControllerTest {
@Test
fun testShowControlsPrivateTab() {
val controller = DefaultReaderModeController(
val controller = spyk(
DefaultReaderModeController(
featureWrapper,
readerViewControlsBar,
isPrivate = true,
),
)
val privateButtonColor = mockk<ColorStateList>()
val privateRadioButtonColor = mockk<ColorStateList>()
every { controller.privateButtonColor } returns privateButtonColor
every { controller.privateRadioButtonColor } returns privateRadioButtonColor
val decrease = mockk<Button>(relaxUnitFun = true)
val increase = mockk<Button>(relaxUnitFun = true)
val serif = mockk<RadioButton>(relaxUnitFun = true)
@ -126,10 +134,10 @@ class DefaultReaderModeControllerTest {
controller.showControls()
verify { readerViewFeature.showControls() }
verifyAll {
decrease.setTextColor(any<ColorStateList>())
increase.setTextColor(any<ColorStateList>())
serif.setTextColor(any<ColorStateList>())
sansSerif.setTextColor(any<ColorStateList>())
decrease.setTextColor(privateButtonColor)
increase.setTextColor(privateButtonColor)
serif.setTextColor(privateRadioButtonColor)
sansSerif.setTextColor(privateRadioButtonColor)
}
}
}