[fenix] Close https://github.com/mozilla-mobile/fenix/issues/22305: Use TabsTrayStore for populating adapters
parent
35556e4cc2
commit
199547f94f
@ -0,0 +1,31 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.tabstray.browser
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.collect
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import mozilla.components.browser.tabstray.TabsTray
|
||||||
|
import mozilla.components.lib.state.helpers.AbstractBinding
|
||||||
|
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayState
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayStore
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An inactive tabs observer that updates the provided [TabsTray].
|
||||||
|
*/
|
||||||
|
class InactiveTabsBinding(
|
||||||
|
store: TabsTrayStore,
|
||||||
|
private val tray: TabsTray
|
||||||
|
) : AbstractBinding<TabsTrayState>(store) {
|
||||||
|
override suspend fun onState(flow: Flow<TabsTrayState>) {
|
||||||
|
flow.map { it.inactiveTabs }
|
||||||
|
.ifChanged()
|
||||||
|
.collect {
|
||||||
|
// We pass null for the selected tab id here, because inactive tabs doesn't care.
|
||||||
|
tray.updateTabs(it, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.tabstray.browser
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.collect
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import mozilla.components.browser.state.store.BrowserStore
|
||||||
|
import mozilla.components.browser.tabstray.TabsTray
|
||||||
|
import mozilla.components.lib.state.helpers.AbstractBinding
|
||||||
|
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayState
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayStore
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A normal tabs observer that updates the provided [TabsTray].
|
||||||
|
*/
|
||||||
|
class NormalTabsBinding(
|
||||||
|
store: TabsTrayStore,
|
||||||
|
private val browserStore: BrowserStore,
|
||||||
|
private val tabsTray: TabsTray
|
||||||
|
) : AbstractBinding<TabsTrayState>(store) {
|
||||||
|
override suspend fun onState(flow: Flow<TabsTrayState>) {
|
||||||
|
flow.map { it.normalTabs }
|
||||||
|
.ifChanged()
|
||||||
|
.collect {
|
||||||
|
// Getting the selectedTabId from the BrowserStore at a different time might lead to a race.
|
||||||
|
tabsTray.updateTabs(it, browserStore.state.selectedTabId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.tabstray.browser
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.collect
|
||||||
|
import mozilla.components.lib.state.helpers.AbstractBinding
|
||||||
|
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifAnyChanged
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayState
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayStore
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A tabs observer that informs [showHeader] if an "Other tabs" title should be displayed in the tray.
|
||||||
|
*/
|
||||||
|
class OtherHeaderBinding(
|
||||||
|
store: TabsTrayStore,
|
||||||
|
private val showHeader: (Boolean) -> Unit
|
||||||
|
) : AbstractBinding<TabsTrayState>(store) {
|
||||||
|
override suspend fun onState(flow: Flow<TabsTrayState>) {
|
||||||
|
flow.ifAnyChanged { arrayOf(it.normalTabs, it.searchTermGroups) }
|
||||||
|
.collect {
|
||||||
|
if (it.searchTermGroups.isNotEmpty() && it.normalTabs.isNotEmpty()) {
|
||||||
|
showHeader(true)
|
||||||
|
} else {
|
||||||
|
showHeader(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.tabstray.browser
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.collect
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import mozilla.components.browser.state.store.BrowserStore
|
||||||
|
import mozilla.components.browser.tabstray.TabsTray
|
||||||
|
import mozilla.components.lib.state.helpers.AbstractBinding
|
||||||
|
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayState
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayStore
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A private tabs observer that updates the provided [TabsTray].
|
||||||
|
*/
|
||||||
|
class PrivateTabsBinding(
|
||||||
|
store: TabsTrayStore,
|
||||||
|
private val browserStore: BrowserStore,
|
||||||
|
private val tray: TabsTray
|
||||||
|
) : AbstractBinding<TabsTrayState>(store) {
|
||||||
|
override suspend fun onState(flow: Flow<TabsTrayState>) {
|
||||||
|
flow.map { it.privateTabs }
|
||||||
|
.ifChanged()
|
||||||
|
.collect {
|
||||||
|
// Getting the selectedTabId from the BrowserStore at a different time might lead to a race.
|
||||||
|
tray.updateTabs(it, browserStore.state.selectedTabId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.tabstray.browser
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.collect
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import mozilla.components.lib.state.helpers.AbstractBinding
|
||||||
|
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayState
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayStore
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A search-term tab group observer that updates the provided [tray].
|
||||||
|
*/
|
||||||
|
class TabGroupBinding(
|
||||||
|
store: TabsTrayStore,
|
||||||
|
private val tray: (List<TabGroup>) -> Unit
|
||||||
|
) : AbstractBinding<TabsTrayState>(store) {
|
||||||
|
override suspend fun onState(flow: Flow<TabsTrayState>) {
|
||||||
|
flow.map { it.searchTermGroups }
|
||||||
|
.ifChanged()
|
||||||
|
.collect {
|
||||||
|
tray.invoke(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.tabstray.browser
|
||||||
|
|
||||||
|
import io.mockk.mockk
|
||||||
|
import io.mockk.verify
|
||||||
|
import mozilla.components.browser.state.state.createTab
|
||||||
|
import mozilla.components.browser.tabstray.TabsTray
|
||||||
|
import mozilla.components.support.test.ext.joinBlocking
|
||||||
|
import mozilla.components.support.test.rule.MainCoroutineRule
|
||||||
|
import org.junit.After
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayAction
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayStore
|
||||||
|
|
||||||
|
class InactiveTabsBindingTest {
|
||||||
|
val store = TabsTrayStore()
|
||||||
|
val tray: TabsTray = mockk(relaxed = true)
|
||||||
|
val binding = InactiveTabsBinding(store, tray)
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
val coroutinesTestRule = MainCoroutineRule()
|
||||||
|
|
||||||
|
@After
|
||||||
|
fun teardown() {
|
||||||
|
binding.stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `WHEN the store is updated THEN notify the tabs tray`() {
|
||||||
|
assertTrue(store.state.inactiveTabs.isEmpty())
|
||||||
|
|
||||||
|
store.dispatch(TabsTrayAction.UpdateInactiveTabs(listOf(createTab("https://mozilla.org")))).joinBlocking()
|
||||||
|
|
||||||
|
binding.start()
|
||||||
|
|
||||||
|
assertTrue(store.state.inactiveTabs.isNotEmpty())
|
||||||
|
|
||||||
|
verify { tray.updateTabs(any(), any()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `WHEN non-inactive tabs are updated THEN do not notify the tabs tray`() {
|
||||||
|
assertTrue(store.state.inactiveTabs.isEmpty())
|
||||||
|
|
||||||
|
store.dispatch(TabsTrayAction.UpdatePrivateTabs(listOf(createTab("https://mozilla.org")))).joinBlocking()
|
||||||
|
|
||||||
|
binding.start()
|
||||||
|
|
||||||
|
assertTrue(store.state.inactiveTabs.isEmpty())
|
||||||
|
|
||||||
|
verify { tray.updateTabs(emptyList(), null) }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.tabstray.browser
|
||||||
|
|
||||||
|
import io.mockk.mockk
|
||||||
|
import io.mockk.slot
|
||||||
|
import io.mockk.verify
|
||||||
|
import mozilla.components.browser.state.state.BrowserState
|
||||||
|
import mozilla.components.browser.state.state.TabSessionState
|
||||||
|
import mozilla.components.browser.state.state.createTab
|
||||||
|
import mozilla.components.browser.state.store.BrowserStore
|
||||||
|
import mozilla.components.browser.tabstray.TabsTray
|
||||||
|
import mozilla.components.support.test.ext.joinBlocking
|
||||||
|
import mozilla.components.support.test.rule.MainCoroutineRule
|
||||||
|
import org.junit.After
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayAction
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayStore
|
||||||
|
|
||||||
|
class NormalTabsBindingTest {
|
||||||
|
val store = TabsTrayStore()
|
||||||
|
val browserStore = BrowserStore(BrowserState(tabs = listOf(createTab("", id = "1")), selectedTabId = "1"))
|
||||||
|
val tray: TabsTray = mockk(relaxed = true)
|
||||||
|
val binding = NormalTabsBinding(store, browserStore, tray)
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
val coroutinesTestRule = MainCoroutineRule()
|
||||||
|
|
||||||
|
@After
|
||||||
|
fun teardown() {
|
||||||
|
binding.stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `WHEN the store is updated THEN notify the tabs tray`() {
|
||||||
|
val slotTabs = slot<List<TabSessionState>>()
|
||||||
|
val expectedTabs = listOf(createTab("https://mozilla.org"))
|
||||||
|
|
||||||
|
assertTrue(store.state.normalTabs.isEmpty())
|
||||||
|
|
||||||
|
store.dispatch(TabsTrayAction.UpdateNormalTabs(expectedTabs)).joinBlocking()
|
||||||
|
|
||||||
|
binding.start()
|
||||||
|
|
||||||
|
assertTrue(store.state.normalTabs.isNotEmpty())
|
||||||
|
|
||||||
|
verify { tray.updateTabs(capture(slotTabs), "1") }
|
||||||
|
assertEquals(expectedTabs, slotTabs.captured)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `WHEN non-inactive tabs are updated THEN do not notify the tabs tray`() {
|
||||||
|
assertTrue(store.state.normalTabs.isEmpty())
|
||||||
|
|
||||||
|
store.dispatch(TabsTrayAction.UpdatePrivateTabs(listOf(createTab("https://mozilla.org")))).joinBlocking()
|
||||||
|
|
||||||
|
binding.start()
|
||||||
|
|
||||||
|
assertTrue(store.state.normalTabs.isEmpty())
|
||||||
|
|
||||||
|
verify { tray.updateTabs(emptyList(), "1") }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.tabstray.browser
|
||||||
|
|
||||||
|
import io.mockk.mockk
|
||||||
|
import mozilla.components.support.test.libstate.ext.waitUntilIdle
|
||||||
|
import mozilla.components.support.test.rule.MainCoroutineRule
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayState
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayStore
|
||||||
|
|
||||||
|
class OtherHeaderBindingTest {
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
val coroutinesTestRule = MainCoroutineRule()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `WHEN there are no tabs THEN show no header`() {
|
||||||
|
val store = TabsTrayStore()
|
||||||
|
var result: Boolean? = null
|
||||||
|
val binding = OtherHeaderBinding(store) { result = it }
|
||||||
|
|
||||||
|
binding.start()
|
||||||
|
|
||||||
|
store.waitUntilIdle()
|
||||||
|
|
||||||
|
assertFalse(result!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `WHEN tabs for only groups THEN show no header`() {
|
||||||
|
val store = TabsTrayStore(TabsTrayState(searchTermGroups = listOf(mockk())))
|
||||||
|
var result: Boolean? = null
|
||||||
|
val binding = OtherHeaderBinding(store) { result = it }
|
||||||
|
|
||||||
|
binding.start()
|
||||||
|
|
||||||
|
store.waitUntilIdle()
|
||||||
|
|
||||||
|
assertFalse(result!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `WHEN tabs for only normal tabs THEN show no header`() {
|
||||||
|
val store = TabsTrayStore(TabsTrayState(normalTabs = listOf(mockk())))
|
||||||
|
var result: Boolean? = null
|
||||||
|
val binding = OtherHeaderBinding(store) { result = it }
|
||||||
|
|
||||||
|
binding.start()
|
||||||
|
|
||||||
|
store.waitUntilIdle()
|
||||||
|
|
||||||
|
assertFalse(result!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `WHEN normal tabs and groups exist THEN show header`() {
|
||||||
|
val store = TabsTrayStore(TabsTrayState(normalTabs = listOf(mockk()), searchTermGroups = listOf(mockk())))
|
||||||
|
var result: Boolean? = null
|
||||||
|
val binding = OtherHeaderBinding(store) { result = it }
|
||||||
|
|
||||||
|
binding.start()
|
||||||
|
|
||||||
|
store.waitUntilIdle()
|
||||||
|
|
||||||
|
assertTrue(result!!)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.mozilla.fenix.tabstray.browser
|
||||||
|
|
||||||
|
import io.mockk.mockk
|
||||||
|
import io.mockk.slot
|
||||||
|
import io.mockk.verify
|
||||||
|
import mozilla.components.browser.state.state.BrowserState
|
||||||
|
import mozilla.components.browser.state.state.TabSessionState
|
||||||
|
import mozilla.components.browser.state.state.createTab
|
||||||
|
import mozilla.components.browser.state.store.BrowserStore
|
||||||
|
import mozilla.components.browser.tabstray.TabsTray
|
||||||
|
import mozilla.components.support.test.ext.joinBlocking
|
||||||
|
import mozilla.components.support.test.rule.MainCoroutineRule
|
||||||
|
import org.junit.After
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayAction
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayStore
|
||||||
|
|
||||||
|
class PrivateTabsBindingTest {
|
||||||
|
val store = TabsTrayStore()
|
||||||
|
val browserStore = BrowserStore(BrowserState(tabs = listOf(createTab("", id = "1")), selectedTabId = "1"))
|
||||||
|
val tray: TabsTray = mockk(relaxed = true)
|
||||||
|
val binding = PrivateTabsBinding(store, browserStore, tray)
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
val coroutinesTestRule = MainCoroutineRule()
|
||||||
|
|
||||||
|
@After
|
||||||
|
fun teardown() {
|
||||||
|
binding.stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `WHEN the store is updated THEN notify the tabs tray`() {
|
||||||
|
val slotTabs = slot<List<TabSessionState>>()
|
||||||
|
val expectedTabs = listOf(createTab("https://mozilla.org", private = true))
|
||||||
|
|
||||||
|
assertTrue(store.state.privateTabs.isEmpty())
|
||||||
|
|
||||||
|
store.dispatch(TabsTrayAction.UpdatePrivateTabs(expectedTabs)).joinBlocking()
|
||||||
|
|
||||||
|
binding.start()
|
||||||
|
|
||||||
|
assertTrue(store.state.privateTabs.isNotEmpty())
|
||||||
|
|
||||||
|
verify { tray.updateTabs(capture(slotTabs), "1") }
|
||||||
|
assertEquals(expectedTabs, slotTabs.captured)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `WHEN non-inactive tabs are updated THEN do not notify the tabs tray`() {
|
||||||
|
assertTrue(store.state.privateTabs.isEmpty())
|
||||||
|
|
||||||
|
store.dispatch(TabsTrayAction.UpdateInactiveTabs(listOf(createTab("https://mozilla.org", private = true))))
|
||||||
|
.joinBlocking()
|
||||||
|
|
||||||
|
binding.start()
|
||||||
|
|
||||||
|
assertTrue(store.state.privateTabs.isEmpty())
|
||||||
|
|
||||||
|
verify { tray.updateTabs(emptyList(), "1") }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.tabstray.browser
|
||||||
|
|
||||||
|
import mozilla.components.browser.state.state.createTab
|
||||||
|
import mozilla.components.support.test.ext.joinBlocking
|
||||||
|
import mozilla.components.support.test.rule.MainCoroutineRule
|
||||||
|
import org.junit.After
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayAction
|
||||||
|
import org.mozilla.fenix.tabstray.TabsTrayStore
|
||||||
|
|
||||||
|
class TabGroupBindingTest {
|
||||||
|
val store = TabsTrayStore()
|
||||||
|
var captured: List<TabGroup>? = null
|
||||||
|
val binding = TabGroupBinding(store) { captured = it }
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
val coroutinesTestRule = MainCoroutineRule()
|
||||||
|
|
||||||
|
@After
|
||||||
|
fun teardown() {
|
||||||
|
binding.stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `WHEN the store is updated THEN notify the adapter`() {
|
||||||
|
val expectedGroups = listOf(TabGroup("cats", emptyList(), 0))
|
||||||
|
|
||||||
|
assertTrue(store.state.searchTermGroups.isEmpty())
|
||||||
|
|
||||||
|
store.dispatch(TabsTrayAction.UpdateSearchGroupTabs(expectedGroups)).joinBlocking()
|
||||||
|
|
||||||
|
binding.start()
|
||||||
|
|
||||||
|
assertTrue(store.state.searchTermGroups.isNotEmpty())
|
||||||
|
|
||||||
|
assertEquals(expectedGroups, captured)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `WHEN non-group tabs are updated THEN do not notify the adapter`() {
|
||||||
|
assertTrue(store.state.searchTermGroups.isEmpty())
|
||||||
|
|
||||||
|
store.dispatch(TabsTrayAction.UpdatePrivateTabs(listOf(createTab("https://mozilla.org")))).joinBlocking()
|
||||||
|
|
||||||
|
binding.start()
|
||||||
|
|
||||||
|
assertTrue(store.state.searchTermGroups.isEmpty())
|
||||||
|
|
||||||
|
assertEquals(emptyList<TabGroup>(), captured)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue