mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/19988 - Part 2: Load tab icon from BrowserIcons cache if needed for the recent tab
Co-authored-by: Jonathan Almeida <jalmeida@mozilla.com>
This commit is contained in:
parent
71ca6f7f5d
commit
756e54a037
@ -6,8 +6,11 @@ package org.mozilla.fenix.home.recenttabs.view
|
||||
|
||||
import android.view.View
|
||||
import kotlinx.android.synthetic.main.recent_tabs_list_row.*
|
||||
import mozilla.components.browser.icons.BrowserIcons
|
||||
import mozilla.components.browser.state.state.TabSessionState
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.loadIntoView
|
||||
import org.mozilla.fenix.home.recenttabs.interactor.RecentTabInteractor
|
||||
import org.mozilla.fenix.utils.view.ViewHolder
|
||||
|
||||
@ -15,15 +18,22 @@ import org.mozilla.fenix.utils.view.ViewHolder
|
||||
* View holder for a recent tab item.
|
||||
*
|
||||
* @param interactor [RecentTabInteractor] which will have delegated to all user interactions.
|
||||
* @param icons
|
||||
*/
|
||||
class RecentTabViewHolder(
|
||||
view: View,
|
||||
private val interactor: RecentTabInteractor
|
||||
private val interactor: RecentTabInteractor,
|
||||
private val icons: BrowserIcons = view.context.components.core.icons
|
||||
) : ViewHolder(view) {
|
||||
|
||||
fun bindTab(tab: TabSessionState) {
|
||||
recent_tab_title.text = tab.content.title
|
||||
|
||||
if (tab.content.icon != null) {
|
||||
recent_tab_icon.setImageBitmap(tab.content.icon)
|
||||
} else {
|
||||
icons.loadIntoView(recent_tab_icon, tab.content.url)
|
||||
}
|
||||
|
||||
itemView.setOnClickListener {
|
||||
interactor.onRecentTabClicked(tab.id)
|
||||
|
@ -6,9 +6,13 @@ package org.mozilla.fenix.home.recenttabs.view
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import kotlinx.android.synthetic.main.recent_tabs_list_row.*
|
||||
import kotlinx.android.synthetic.main.recent_tabs_list_row.view.*
|
||||
import mozilla.components.browser.icons.BrowserIcons
|
||||
import mozilla.components.browser.icons.IconRequest
|
||||
import mozilla.components.browser.state.state.createTab
|
||||
import mozilla.components.support.test.robolectric.testContext
|
||||
import org.junit.Assert.assertEquals
|
||||
@ -23,6 +27,7 @@ class RecentTabViewHolderTest {
|
||||
|
||||
private lateinit var view: View
|
||||
private lateinit var interactor: SessionControlInteractor
|
||||
private lateinit var icons: BrowserIcons
|
||||
|
||||
private val tab = createTab(
|
||||
url = "https://mozilla.org",
|
||||
@ -33,18 +38,23 @@ class RecentTabViewHolderTest {
|
||||
fun setup() {
|
||||
view = LayoutInflater.from(testContext).inflate(RecentTabViewHolder.LAYOUT_ID, null)
|
||||
interactor = mockk(relaxed = true)
|
||||
icons = mockk(relaxed = true)
|
||||
|
||||
every { icons.loadIntoView(view.recent_tab_icon, any()) } returns mockk()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN a new recent tab on bind THEN set the title text`() {
|
||||
RecentTabViewHolder(view, interactor).bindTab(tab)
|
||||
fun `GIVEN a new recent tab on bind THEN set the title text and load the tab icon`() {
|
||||
RecentTabViewHolder(view, interactor, icons).bindTab(tab)
|
||||
|
||||
assertEquals(tab.content.title, view.recent_tab_title.text)
|
||||
|
||||
verify { icons.loadIntoView(view.recent_tab_icon, IconRequest(tab.content.url)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN a recent tab item is clicked THEN interactor iis called`() {
|
||||
RecentTabViewHolder(view, interactor).bindTab(tab)
|
||||
fun `WHEN a recent tab item is clicked THEN interactor is called`() {
|
||||
RecentTabViewHolder(view, interactor, icons).bindTab(tab)
|
||||
|
||||
view.performClick()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user