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

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

@ -5,6 +5,7 @@
package org.mozilla.fenix.browser.tabstrip
import mozilla.components.browser.state.selector.getNormalOrPrivateTabs
import mozilla.components.browser.state.selector.selectedTab
import mozilla.components.browser.state.state.BrowserState
/**
@ -41,23 +42,22 @@ data class TabStripItem(
* Converts [BrowserState] to [TabStripState] that contains the information needed to render the
* 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.
*/
internal fun BrowserState.toTabStripState(
isSelectDisabled: Boolean,
isPrivateMode: Boolean,
): TabStripState {
return TabStripState(
tabs = getNormalOrPrivateTabs(isPrivateMode)
.map {
TabStripItem(
id = it.id,
title = it.content.title.ifBlank { it.content.url },
url = it.content.url,
isPrivate = it.content.private,
isSelected = !isSelectDisabled && it.id == selectedTabId,
)
},
)
}
): TabStripState = TabStripState(
tabs = getNormalOrPrivateTabs(
private = isPrivateMode || (!isSelectDisabled && selectedTab?.content?.private == true),
).map {
TabStripItem(
id = it.id,
title = it.content.title.ifBlank { it.content.url },
url = it.content.url,
isPrivate = it.content.private,
isSelected = !isSelectDisabled && it.id == selectedTabId,
)
},
)

@ -156,6 +156,55 @@ class TabStripStateTest {
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
fun `WHEN isSelectDisabled is true THEN tabs strip state tabs should not have a selected tab`() {
val browserState = BrowserState(

Loading…
Cancel
Save