[fenix] For https://github.com/mozilla-mobile/fenix/issues/21095 add customize home button on the home screen.
parent
b057d6a76f
commit
5ce4a31be5
@ -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.home.sessioncontrol.viewholders
|
||||
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.databinding.CustomizeHomeListItemBinding
|
||||
import org.mozilla.fenix.home.sessioncontrol.CustomizeHomeIteractor
|
||||
|
||||
class CustomizeHomeButtonViewHolder(
|
||||
view: View,
|
||||
private val interactor: CustomizeHomeIteractor
|
||||
) : RecyclerView.ViewHolder(view) {
|
||||
|
||||
init {
|
||||
val binding = CustomizeHomeListItemBinding.bind(view)
|
||||
|
||||
binding.customizeHome.setOnClickListener {
|
||||
interactor.openCustomizeHomePage()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val LAYOUT_ID = R.layout.customize_home_list_item
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?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/. -->
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/about_list_item_height"
|
||||
android:background="?android:attr/selectableItemBackground">
|
||||
|
||||
<Button
|
||||
android:id="@+id/customize_home"
|
||||
style="@style/NeutralOnboardingButton"
|
||||
android:layout_height="36dp"
|
||||
android:background="@drawable/rounded_button_background"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:text="@string/browser_menu_customize_home"
|
||||
android:gravity="center"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -0,0 +1,40 @@
|
||||
/* 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.home.sessioncontrol
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import mozilla.components.support.test.robolectric.testContext
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.fenix.databinding.CustomizeHomeListItemBinding
|
||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||
import org.mozilla.fenix.home.sessioncontrol.viewholders.CustomizeHomeButtonViewHolder
|
||||
|
||||
@RunWith(FenixRobolectricTestRunner::class)
|
||||
class CustomizeHomeButtonViewHolderTest {
|
||||
|
||||
private lateinit var binding: CustomizeHomeListItemBinding
|
||||
private lateinit var interactor: CustomizeHomeIteractor
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
binding = CustomizeHomeListItemBinding.inflate(LayoutInflater.from(testContext))
|
||||
interactor = mockk(relaxed = true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `hide view and change setting on remove placeholder click`() {
|
||||
CustomizeHomeButtonViewHolder(binding.root, interactor)
|
||||
|
||||
binding.customizeHome.performClick()
|
||||
|
||||
verify {
|
||||
interactor.openCustomizeHomePage()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,177 @@
|
||||
/* 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.home.sessioncontrol
|
||||
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.spyk
|
||||
import mozilla.components.browser.state.state.TabSessionState
|
||||
import mozilla.components.concept.storage.BookmarkNode
|
||||
import mozilla.components.concept.storage.BookmarkNodeType
|
||||
import mozilla.components.feature.tab.collections.TabCollection
|
||||
import mozilla.components.feature.top.sites.TopSite
|
||||
import mozilla.components.service.pocket.PocketRecommendedStory
|
||||
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.ext.settings
|
||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||
import org.mozilla.fenix.historymetadata.HistoryMetadataGroup
|
||||
import org.mozilla.fenix.utils.Settings
|
||||
|
||||
@RunWith(FenixRobolectricTestRunner::class)
|
||||
class SessionControlViewTest {
|
||||
@Test
|
||||
fun `GIVEN recent Bookmarks WHEN normalModeAdapterItems is called THEN add a customize home button`() {
|
||||
val topSites = emptyList<TopSite>()
|
||||
val collections = emptyList<TabCollection>()
|
||||
val expandedCollections = emptySet<Long>()
|
||||
val recentBookmarks =
|
||||
listOf(BookmarkNode(BookmarkNodeType.ITEM, "guid", null, null, null, null, 0, null))
|
||||
val recentTabs = emptyList<TabSessionState>()
|
||||
val historyMetadata = emptyList<HistoryMetadataGroup>()
|
||||
val pocketArticles = emptyList<PocketRecommendedStory>()
|
||||
|
||||
val results = normalModeAdapterItems(
|
||||
testContext,
|
||||
topSites,
|
||||
collections,
|
||||
expandedCollections,
|
||||
null,
|
||||
recentBookmarks,
|
||||
false,
|
||||
false,
|
||||
recentTabs,
|
||||
historyMetadata,
|
||||
pocketArticles
|
||||
)
|
||||
|
||||
assertTrue(results[0] is AdapterItem.RecentBookmarks)
|
||||
assertTrue(results[1] is AdapterItem.CustomizeHomeButton)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN recent tabs WHEN normalModeAdapterItems is called THEN add a customize home button`() {
|
||||
val topSites = emptyList<TopSite>()
|
||||
val collections = emptyList<TabCollection>()
|
||||
val expandedCollections = emptySet<Long>()
|
||||
val recentBookmarks = listOf<BookmarkNode>()
|
||||
val recentTabs = listOf<TabSessionState>(mockk())
|
||||
val historyMetadata = emptyList<HistoryMetadataGroup>()
|
||||
val pocketArticles = emptyList<PocketRecommendedStory>()
|
||||
|
||||
val results = normalModeAdapterItems(
|
||||
testContext,
|
||||
topSites,
|
||||
collections,
|
||||
expandedCollections,
|
||||
null,
|
||||
recentBookmarks,
|
||||
false,
|
||||
false,
|
||||
recentTabs,
|
||||
historyMetadata,
|
||||
pocketArticles
|
||||
)
|
||||
|
||||
assertTrue(results[0] is AdapterItem.RecentTabsHeader)
|
||||
assertTrue(results[1] is AdapterItem.RecentTabItem)
|
||||
assertTrue(results[2] is AdapterItem.CustomizeHomeButton)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN history metadata WHEN normalModeAdapterItems is called THEN add a customize home button`() {
|
||||
val topSites = emptyList<TopSite>()
|
||||
val collections = emptyList<TabCollection>()
|
||||
val expandedCollections = emptySet<Long>()
|
||||
val recentBookmarks = listOf<BookmarkNode>()
|
||||
val recentTabs = emptyList<TabSessionState>()
|
||||
val historyMetadata = listOf(HistoryMetadataGroup("title", emptyList(), false))
|
||||
val pocketArticles = emptyList<PocketRecommendedStory>()
|
||||
|
||||
val results = normalModeAdapterItems(
|
||||
testContext,
|
||||
topSites,
|
||||
collections,
|
||||
expandedCollections,
|
||||
null,
|
||||
recentBookmarks,
|
||||
false,
|
||||
false,
|
||||
recentTabs,
|
||||
historyMetadata,
|
||||
pocketArticles
|
||||
)
|
||||
|
||||
assertTrue(results[0] is AdapterItem.HistoryMetadataHeader)
|
||||
assertTrue(results[1] is AdapterItem.HistoryMetadataGroup)
|
||||
assertTrue(results[2] is AdapterItem.CustomizeHomeButton)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN pocket articles WHEN normalModeAdapterItems is called THEN add a customize home button`() {
|
||||
val topSites = emptyList<TopSite>()
|
||||
val collections = emptyList<TabCollection>()
|
||||
val expandedCollections = emptySet<Long>()
|
||||
val recentBookmarks = listOf<BookmarkNode>()
|
||||
val recentTabs = emptyList<TabSessionState>()
|
||||
val historyMetadata = emptyList<HistoryMetadataGroup>()
|
||||
val pocketArticles = listOf(PocketRecommendedStory("", "", "", "", 0, ""))
|
||||
val context = spyk(testContext)
|
||||
|
||||
val settings: Settings = mockk()
|
||||
every { settings.pocketRecommendations } returns true
|
||||
every { context.settings() } returns settings
|
||||
|
||||
val results = normalModeAdapterItems(
|
||||
context,
|
||||
topSites,
|
||||
collections,
|
||||
expandedCollections,
|
||||
null,
|
||||
recentBookmarks,
|
||||
false,
|
||||
false,
|
||||
recentTabs,
|
||||
historyMetadata,
|
||||
pocketArticles
|
||||
)
|
||||
|
||||
assertTrue(results[0] is AdapterItem.PocketStoriesItem)
|
||||
assertTrue(results[1] is AdapterItem.CustomizeHomeButton)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN none recentBookmarks,recentTabs, historyMetadata or pocketArticles WHEN normalModeAdapterItems is called THEN the customize home button is not added`() {
|
||||
val topSites = emptyList<TopSite>()
|
||||
val collections = emptyList<TabCollection>()
|
||||
val expandedCollections = emptySet<Long>()
|
||||
val recentBookmarks = listOf<BookmarkNode>()
|
||||
val recentTabs = emptyList<TabSessionState>()
|
||||
val historyMetadata = emptyList<HistoryMetadataGroup>()
|
||||
val pocketArticles = emptyList<PocketRecommendedStory>()
|
||||
val context = spyk(testContext)
|
||||
|
||||
val settings: Settings = mockk()
|
||||
every { settings.pocketRecommendations } returns true
|
||||
every { context.settings() } returns settings
|
||||
|
||||
val results = normalModeAdapterItems(
|
||||
context,
|
||||
topSites,
|
||||
collections,
|
||||
expandedCollections,
|
||||
null,
|
||||
recentBookmarks,
|
||||
false,
|
||||
false,
|
||||
recentTabs,
|
||||
historyMetadata,
|
||||
pocketArticles
|
||||
)
|
||||
assertTrue(results.isEmpty())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue