For #18260 - Add pin to default sites. (#18618)

upstream-sync
Mihai Adrian Carare 3 years ago committed by GitHub
parent c21b44e0a3
commit a539f69cb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -14,6 +14,7 @@ import kotlinx.android.synthetic.main.top_site_item.*
import mozilla.components.browser.menu.BrowserMenuBuilder
import mozilla.components.browser.menu.item.SimpleBrowserMenuItem
import mozilla.components.feature.top.sites.TopSite
import mozilla.components.feature.top.sites.TopSite.Type.DEFAULT
import mozilla.components.feature.top.sites.TopSite.Type.FRECENT
import mozilla.components.feature.top.sites.TopSite.Type.PINNED
import org.mozilla.fenix.R
@ -63,7 +64,7 @@ class TopSiteItemViewHolder(
fun bind(topSite: TopSite) {
top_site_title.text = topSite.title
pin_indicator.visibility = if (topSite.type == PINNED) {
pin_indicator.visibility = if (topSite.type == PINNED || topSite.type == DEFAULT) {
View.VISIBLE
} else {
View.GONE

@ -6,14 +6,19 @@ package org.mozilla.fenix.home.sessioncontrol.viewholders.topsites
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import androidx.core.view.isVisible
import io.mockk.mockk
import io.mockk.verify
import kotlinx.android.synthetic.main.top_site_item.view.*
import mozilla.components.feature.top.sites.TopSite
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.home.sessioncontrol.TopSiteInteractor
@ -52,4 +57,52 @@ class TopSiteItemViewHolderTest {
view.top_site_item.performLongClick()
verify { interactor.onTopSiteMenuOpened() }
}
@Test
fun `pin indicator is visible for default top sites`() {
val defaultTopSite = TopSite(
id = 1L,
title = "Pocket",
url = "https://getpocket.com",
createdAt = 0,
type = TopSite.Type.DEFAULT
)
TopSiteItemViewHolder(view, interactor).bind(defaultTopSite)
val pinIndicator = view.findViewById<FrameLayout>(R.id.pin_indicator)
assertTrue(pinIndicator.isVisible)
}
@Test
fun `pin indicator is visible for pinned top sites`() {
val pinnedTopSite = TopSite(
id = 1L,
title = "Mozilla",
url = "https://www.mozilla.org",
createdAt = 0,
type = TopSite.Type.PINNED
)
TopSiteItemViewHolder(view, interactor).bind(pinnedTopSite)
val pinIndicator = view.findViewById<FrameLayout>(R.id.pin_indicator)
assertTrue(pinIndicator.isVisible)
}
@Test
fun `pin indicator is not visible for frecent top sites`() {
val frecentTopSite = TopSite(
id = 1L,
title = "Mozilla",
url = "https://www.mozilla.org",
createdAt = 0,
type = TopSite.Type.FRECENT
)
TopSiteItemViewHolder(view, interactor).bind(frecentTopSite)
val pinIndicator = view.findViewById<FrameLayout>(R.id.pin_indicator)
assertFalse(pinIndicator.isVisible)
}
}

Loading…
Cancel
Save