2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-11 13:11:01 +00:00

Close #19011: Always have a click listener in TabTrayViewHolder

This commit is contained in:
Jonathan Almeida 2021-04-13 22:20:27 -04:00 committed by Jonathan Almeida
parent 0a4927a495
commit b9881372ef
2 changed files with 106 additions and 2 deletions

View File

@ -87,8 +87,10 @@ abstract class TabsTrayViewHolder(
updateSelectedTabIndicator(isSelected) updateSelectedTabIndicator(isSelected)
updateMediaState(tab) updateMediaState(tab)
selectionHolder?.let { if (selectionHolder != null) {
setSelectionInteractor(tab, it, browserTrayInteractor) setSelectionInteractor(tab, selectionHolder, browserTrayInteractor)
} else {
itemView.setOnClickListener { browserTrayInteractor.open(tab) }
} }
if (tab.thumbnail != null) { if (tab.thumbnail != null) {

View File

@ -0,0 +1,102 @@
/* 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
import android.view.LayoutInflater
import android.view.View
import io.mockk.mockk
import io.mockk.verify
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.base.images.ImageLoader
import mozilla.components.concept.tabstray.Tab
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.selection.SelectionHolder
import org.mozilla.fenix.tabstray.browser.BrowserTrayInteractor
import org.mozilla.fenix.tabstray.browser.createTab
@RunWith(FenixRobolectricTestRunner::class)
class TabsTrayViewHolderTest {
val store = TabsTrayStore()
val browserStore = BrowserStore()
val interactor = mockk<BrowserTrayInteractor>(relaxed = true)
@Test
fun `WHEN itemView is clicked THEN interactor invokes open`() {
val view = LayoutInflater.from(testContext).inflate(R.layout.tab_tray_item, null)
val holder = TestTabTrayViewHolder(
view,
mockk(relaxed = true),
store,
null,
browserStore,
mockk(relaxed = true),
interactor
)
holder.bind(createTab(), false, mockk(), mockk())
holder.itemView.performClick()
verify { interactor.open(any()) }
}
@Test
fun `WHEN itemView is clicked with a selection holder THEN the select holder is invoked`() {
val view = LayoutInflater.from(testContext).inflate(R.layout.tab_tray_item, null)
val selectionHolder = TestSelectionHolder(emptySet())
val holder = TestTabTrayViewHolder(
view,
mockk(relaxed = true),
store,
selectionHolder,
browserStore,
mockk(relaxed = true),
interactor
)
holder.bind(createTab(), false, mockk(), mockk())
holder.itemView.performClick()
verify { interactor.open(any()) }
assertTrue(selectionHolder.invoked)
}
@Suppress("LongParameterList")
class TestTabTrayViewHolder(
itemView: View,
imageLoader: ImageLoader,
trayStore: TabsTrayStore,
selectionHolder: SelectionHolder<Tab>?,
store: BrowserStore,
metrics: MetricController,
override val browserTrayInteractor: BrowserTrayInteractor
) : TabsTrayViewHolder(itemView, imageLoader, trayStore, selectionHolder, store, metrics) {
override val thumbnailSize: Int
get() = 30
override fun updateSelectedTabIndicator(showAsSelected: Boolean) {
// do nothing
}
}
class TestSelectionHolder(
private val testItems: Set<Tab>
) : SelectionHolder<Tab> {
override val selectedItems: Set<Tab>
get() {
invoked = true
return testItems
}
var invoked = false
}
}