Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Bug 1884891 - Display only private in tab strip when switched to priv…
Browse files Browse the repository at this point in the history
…ate tab
  • Loading branch information
rahulsainani authored and mergify[bot] committed Mar 14, 2024
1 parent 2b4c403 commit 6029668
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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,
)
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 6029668

Please sign in to comment.