Bug 1884891 - Display only private in tab strip when switched to private tab

fenix/125.0
rahulsainani 3 months ago committed by mergify[bot]
parent 63ca1419c6
commit 96c6d08a66

@ -5,6 +5,7 @@
package org.mozilla.fenix.browser.tabstrip package org.mozilla.fenix.browser.tabstrip
import mozilla.components.browser.state.selector.getNormalOrPrivateTabs import mozilla.components.browser.state.selector.getNormalOrPrivateTabs
import mozilla.components.browser.state.selector.selectedTab
import mozilla.components.browser.state.state.BrowserState import mozilla.components.browser.state.state.BrowserState
/** /**
@ -41,16 +42,16 @@ data class TabStripItem(
* Converts [BrowserState] to [TabStripState] that contains the information needed to render the * Converts [BrowserState] to [TabStripState] that contains the information needed to render the
* tabs strip. * tabs strip.
* *
* @param isSelectDisabled When true, the tabs will show as selected. * @param isSelectDisabled When true, the tabs will show as unselected.
* @param isPrivateMode Whether or not the browser is in private mode. * @param isPrivateMode Whether or not the browser is in private mode.
*/ */
internal fun BrowserState.toTabStripState( internal fun BrowserState.toTabStripState(
isSelectDisabled: Boolean, isSelectDisabled: Boolean,
isPrivateMode: Boolean, isPrivateMode: Boolean,
): TabStripState { ): TabStripState = TabStripState(
return TabStripState( tabs = getNormalOrPrivateTabs(
tabs = getNormalOrPrivateTabs(isPrivateMode) private = isPrivateMode || (!isSelectDisabled && selectedTab?.content?.private == true),
.map { ).map {
TabStripItem( TabStripItem(
id = it.id, id = it.id,
title = it.content.title.ifBlank { it.content.url }, title = it.content.title.ifBlank { it.content.url },
@ -59,5 +60,4 @@ internal fun BrowserState.toTabStripState(
isSelected = !isSelectDisabled && it.id == selectedTabId, isSelected = !isSelectDisabled && it.id == selectedTabId,
) )
}, },
) )
}

@ -156,6 +156,55 @@ class TabStripStateTest {
assertEquals(expected, actual) assertEquals(expected, actual)
} }
@Test
fun `WHEN isSelectDisabled is false and selected tab is private THEN tabs strip state tabs should have private tabs including the selected tab`() {
val browserState = BrowserState(
tabs = listOf(
createTab(
url = "https://example.com",
title = "Example 1",
private = false,
id = "1",
),
createTab(
url = "https://example2.com",
title = "Example 2",
private = true,
id = "2",
),
createTab(
url = "https://example3.com",
title = "Example 3",
private = true,
id = "3",
),
),
selectedTabId = "2",
)
val actual = browserState.toTabStripState(isSelectDisabled = false, isPrivateMode = false)
val expected = TabStripState(
tabs = listOf(
TabStripItem(
id = "2",
title = "Example 2",
url = "https://example2.com",
isSelected = true,
isPrivate = true,
),
TabStripItem(
id = "3",
title = "Example 3",
url = "https://example3.com",
isSelected = false,
isPrivate = true,
),
),
)
assertEquals(expected, actual)
}
@Test @Test
fun `WHEN isSelectDisabled is true THEN tabs strip state tabs should not have a selected tab`() { fun `WHEN isSelectDisabled is true THEN tabs strip state tabs should not have a selected tab`() {
val browserState = BrowserState( val browserState = BrowserState(

Loading…
Cancel
Save