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

Bug 1822181 - Refactor TabCounterBuilder to TabCounterView

This commit is contained in:
Gabriel Luong 2023-03-13 17:38:41 -04:00 committed by mergify[bot]
parent b2268b3937
commit bbf9b82ce7
3 changed files with 9 additions and 14 deletions

View File

@ -580,12 +580,12 @@ class HomeFragment : Fragment() {
hideOnboardingIfNeeded = ::hideOnboardingIfNeeded,
).build()
TabCounterBuilder(
TabCounterView(
context = requireContext(),
browsingModeManager = browsingModeManager,
navController = findNavController(),
tabCounter = binding.tabButton,
).build()
)
binding.toolbar.compoundDrawablePadding =
view.resources.getDimensionPixelSize(R.dimen.search_bar_search_engine_icon_padding)

View File

@ -25,17 +25,14 @@ import org.mozilla.fenix.ext.nav
* @property navController [NavController] used for navigation.
* @property tabCounter The [TabCounter] that will be setup with event handlers.
*/
class TabCounterBuilder(
class TabCounterView(
private val context: Context,
private val browsingModeManager: BrowsingModeManager,
private val navController: NavController,
private val tabCounter: TabCounter,
) {
/**
* Builds the [FenixTabCounterMenu].
*/
fun build() {
init {
val tabCounterMenu = FenixTabCounterMenu(
context = context,
onItemTapped = ::onItemTapped,

View File

@ -28,7 +28,7 @@ import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.utils.Settings
@RunWith(FenixRobolectricTestRunner::class)
class TabCounterBuilderTest {
class TabCounterViewTest {
@get:Rule
val gleanTestRule = GleanTestRule(testContext)
@ -37,7 +37,7 @@ class TabCounterBuilderTest {
private lateinit var browsingModeManager: BrowsingModeManager
private lateinit var settings: Settings
private lateinit var modeDidChange: (BrowsingMode) -> Unit
private lateinit var tabCounterBuilder: TabCounterBuilder
private lateinit var tabCounterView: TabCounterView
private lateinit var tabCounter: TabCounter
@Before
@ -54,7 +54,7 @@ class TabCounterBuilderTest {
modeDidChange = modeDidChange,
)
tabCounterBuilder = TabCounterBuilder(
tabCounterView = TabCounterView(
context = testContext,
browsingModeManager = browsingModeManager,
navController = navController,
@ -64,8 +64,6 @@ class TabCounterBuilderTest {
@Test
fun `WHEN tab counter is clicked THEN navigate to tabs tray and record metrics`() {
tabCounterBuilder.build()
assertNull(StartOnHome.openTabsTray.testGetValue())
tabCounter.performClick()
@ -82,14 +80,14 @@ class TabCounterBuilderTest {
@Test
fun `WHEN New tab menu item is tapped THEN set browsing mode to normal`() {
tabCounterBuilder.onItemTapped(TabCounterMenu.Item.NewTab)
tabCounterView.onItemTapped(TabCounterMenu.Item.NewTab)
assertEquals(BrowsingMode.Normal, browsingModeManager.mode)
}
@Test
fun `WHEN New private tab menu item is tapped THEN set browsing mode to private`() {
tabCounterBuilder.onItemTapped(TabCounterMenu.Item.NewPrivateTab)
tabCounterView.onItemTapped(TabCounterMenu.Item.NewPrivateTab)
assertEquals(BrowsingMode.Private, browsingModeManager.mode)
}