GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit 8f540c55 authored by Tiger Oakes's avatar Tiger Oakes Committed by liuche
Browse files

Fix suggestions, extract layout for tab history

parent d306e37a
......@@ -23,7 +23,7 @@ class TabHistoryAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TabHistoryViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.history_list_item, parent, false)
.inflate(R.layout.tab_history_list_item, parent, false)
return TabHistoryViewHolder(view, interactor)
}
......
......@@ -57,7 +57,6 @@ class TabHistoryView(
init {
tabHistoryRecyclerView.adapter = adapter
tabHistoryRecyclerView.layoutManager = layoutManager
tabHistoryRecyclerView.itemAnimator = null
}
fun updateState(state: BrowserState) {
......
......@@ -7,7 +7,8 @@ package org.mozilla.fenix.tabhistory
import android.view.View
import androidx.core.text.bold
import androidx.core.text.buildSpannedString
import kotlinx.android.synthetic.main.history_list_item.*
import androidx.core.view.isVisible
import kotlinx.android.synthetic.main.tab_history_list_item.*
import org.mozilla.fenix.library.LibrarySiteItemView
import org.mozilla.fenix.utils.view.ViewHolder
......@@ -19,13 +20,14 @@ class TabHistoryViewHolder(
private lateinit var item: TabHistoryItem
init {
itemView.setOnClickListener { interactor.goToHistoryItem(item) }
history_layout.setOnClickListener { interactor.goToHistoryItem(item) }
}
fun bind(item: TabHistoryItem) {
this.item = item
history_layout.displayAs(LibrarySiteItemView.ItemType.SITE)
history_layout.overflowView.isVisible = false
history_layout.urlView.text = item.url
history_layout.loadFavicon(item.url)
......
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<org.mozilla.fenix.library.LibrarySiteItemView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/history_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/library_item_height" />
package org.mozilla.fenix.tabhistory
import android.view.View
import io.mockk.CapturingSlot
import io.mockk.MockKAnnotations
import io.mockk.Runs
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.just
import io.mockk.mockk
import io.mockk.slot
import io.mockk.verify
import org.junit.Before
import org.junit.Test
import org.mozilla.fenix.R
import org.mozilla.fenix.library.LibrarySiteItemView
class TabHistoryViewHolderTest {
@MockK private lateinit var view: View
@MockK private lateinit var interactor: TabHistoryViewInteractor
@MockK(relaxed = true) private lateinit var siteItemView: LibrarySiteItemView
private lateinit var holder: TabHistoryViewHolder
private lateinit var onClick: CapturingSlot<View.OnClickListener>
@Before
fun setup() {
MockKAnnotations.init(this)
onClick = slot()
every { siteItemView.setOnClickListener(capture(onClick)) } just Runs
every { view.findViewById<LibrarySiteItemView>(R.id.history_layout) } returns siteItemView
holder = TabHistoryViewHolder(view, interactor)
}
@Test
fun `calls interactor on click`() {
every { interactor.goToHistoryItem(any()) } just Runs
val item = mockk<TabHistoryItem>(relaxed = true)
holder.bind(item)
onClick.captured.onClick(mockk())
verify { interactor.goToHistoryItem(item) }
}
@Test
fun `binds title and url`() {
val item = TabHistoryItem(
title = "Firefox",
url = "https://firefox.com",
index = 1,
isSelected = false
)
holder.bind(item)
verify { siteItemView.displayAs(LibrarySiteItemView.ItemType.SITE) }
verify { siteItemView.titleView.text = "Firefox" }
verify { siteItemView.urlView.text = "https://firefox.com" }
verify { siteItemView.loadFavicon("https://firefox.com") }
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment