Commit 4415702f authored by Tiger Oakes's avatar Tiger Oakes Committed by Emily Kager
Browse files

Add tests for share sheet

parent 183ba1bc
......@@ -33,7 +33,11 @@ class ShareTabsAdapter :
class ShareTabViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(item: ShareData) = with(itemView) {
context.components.core.icons.loadIntoView(itemView.share_tab_favicon, item.url.orEmpty())
val url = item.url
if (!url.isNullOrEmpty()) {
context.components.core.icons.loadIntoView(itemView.share_tab_favicon, url)
}
itemView.share_tab_title.text = item.title
itemView.share_tab_url.text = item.url
}
......
......@@ -8,15 +8,13 @@ import android.content.Context
import android.view.View
import androidx.annotation.VisibleForTesting
import androidx.core.content.ContextCompat.getColor
import androidx.core.graphics.BlendModeColorFilterCompat.createBlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat.SRC_IN
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.account_share_list_item.view.*
import mozilla.components.concept.sync.DeviceType
import org.mozilla.fenix.R
import org.mozilla.fenix.utils.Do
import org.mozilla.fenix.share.ShareToAccountDevicesInteractor
import org.mozilla.fenix.share.listadapters.SyncShareOption
import org.mozilla.fenix.utils.Do
class AccountDeviceViewHolder(
itemView: View,
......@@ -52,7 +50,7 @@ class AccountDeviceViewHolder(
itemView.deviceIcon.apply {
setImageResource(drawableRes)
background.colorFilter = createBlendModeColorFilterCompat(getColor(context, colorRes), SRC_IN)
background.setTint(getColor(context, colorRes))
drawable.setTint(getColor(context, R.color.device_foreground))
}
itemView.isClickable = option != SyncShareOption.Offline
......
/* 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.share
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.recyclerview.widget.LinearLayoutManager
import io.mockk.mockk
import io.mockk.verify
import kotlinx.android.synthetic.main.share_close.view.*
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.share.listadapters.ShareTabsAdapter
@RunWith(FenixRobolectricTestRunner::class)
class ShareCloseViewTest {
private lateinit var container: ViewGroup
private lateinit var interactor: ShareCloseInteractor
@Before
fun setup() {
container = FrameLayout(testContext)
interactor = mockk(relaxUnitFun = true)
}
@Test
fun `binds adapter and close button`() {
ShareCloseView(container, interactor)
assertTrue(container.shared_site_list.layoutManager is LinearLayoutManager)
assertTrue(container.shared_site_list.adapter is ShareTabsAdapter)
container.closeButton.performClick()
verify { interactor.onShareClosed() }
}
}
/* 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.share.viewholders
import android.view.LayoutInflater
import io.mockk.Called
import io.mockk.mockk
import io.mockk.verify
import kotlinx.android.synthetic.main.account_share_list_item.view.*
import mozilla.components.concept.sync.Device
import mozilla.components.concept.sync.DeviceType
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.share.ShareToAccountDevicesInteractor
import org.mozilla.fenix.share.listadapters.SyncShareOption
@RunWith(FenixRobolectricTestRunner::class)
class AccountDeviceViewHolderTest {
private val baseDevice = Device(
id = "",
displayName = "",
deviceType = DeviceType.UNKNOWN,
isCurrentDevice = true,
lastAccessTime = 0L,
capabilities = emptyList(),
subscriptionExpired = false,
subscription = null
)
private lateinit var viewHolder: AccountDeviceViewHolder
private lateinit var interactor: ShareToAccountDevicesInteractor
@Before
fun setup() {
interactor = mockk(relaxUnitFun = true)
val view = LayoutInflater.from(testContext).inflate(AccountDeviceViewHolder.LAYOUT_ID, null)
viewHolder = AccountDeviceViewHolder(view, interactor)
}
@Test
fun `bind SignIn option`() {
viewHolder.bind(SyncShareOption.SignIn)
assertEquals("Sign in to Sync", viewHolder.itemView.deviceName.text)
viewHolder.itemView.performClick()
verify { interactor.onSignIn() }
assertFalse(viewHolder.itemView.hasOnClickListeners())
}
@Test
fun `bind Reconnect option`() {
viewHolder.bind(SyncShareOption.Reconnect)
assertEquals("Reconnect to Sync", viewHolder.itemView.deviceName.text)
viewHolder.itemView.performClick()
verify { interactor.onReauth() }
assertFalse(viewHolder.itemView.hasOnClickListeners())
}
@Test
fun `bind Offline option`() {
viewHolder.bind(SyncShareOption.Offline)
assertEquals("Offline", viewHolder.itemView.deviceName.text)
viewHolder.itemView.performClick()
verify { interactor wasNot Called }
assertFalse(viewHolder.itemView.hasOnClickListeners())
}
@Test
fun `bind AddNewDevice option`() {
viewHolder.bind(SyncShareOption.AddNewDevice)
assertEquals("Connect another device", viewHolder.itemView.deviceName.text)
viewHolder.itemView.performClick()
verify { interactor.onAddNewDevice() }
assertFalse(viewHolder.itemView.hasOnClickListeners())
}
@Test
fun `bind SendAll option`() {
val devices = listOf<Device>(mockk())
viewHolder.bind(SyncShareOption.SendAll(devices))
assertEquals("Send to all devices", viewHolder.itemView.deviceName.text)
viewHolder.itemView.performClick()
verify { interactor.onShareToAllDevices(devices) }
assertFalse(viewHolder.itemView.hasOnClickListeners())
}
@Test
fun `bind mobile SingleDevice option`() {
val device = baseDevice.copy(
deviceType = DeviceType.MOBILE,
displayName = "Mobile"
)
viewHolder.bind(SyncShareOption.SingleDevice(device))
assertEquals("Mobile", viewHolder.itemView.deviceName.text)
viewHolder.itemView.performClick()
verify { interactor.onShareToDevice(device) }
assertFalse(viewHolder.itemView.hasOnClickListeners())
}
@Test
fun `bind desktop SingleDevice option`() {
val device = baseDevice.copy(
deviceType = DeviceType.DESKTOP,
displayName = "Desktop"
)
viewHolder.bind(SyncShareOption.SingleDevice(device))
assertEquals("Desktop", viewHolder.itemView.deviceName.text)
viewHolder.itemView.performClick()
verify { interactor.onShareToDevice(device) }
assertFalse(viewHolder.itemView.hasOnClickListeners())
}
}
/* 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.share.viewholders
import android.view.LayoutInflater
import androidx.appcompat.content.res.AppCompatResources.getDrawable
import io.mockk.Called
import io.mockk.mockk
import io.mockk.verify
import kotlinx.android.synthetic.main.app_share_list_item.view.*
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals
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.share.ShareToAppsInteractor
import org.mozilla.fenix.share.listadapters.AppShareOption
@RunWith(FenixRobolectricTestRunner::class)
class AppViewHolderTest {
private lateinit var viewHolder: AppViewHolder
private lateinit var interactor: ShareToAppsInteractor
@Before
fun setup() {
interactor = mockk(relaxUnitFun = true)
val view = LayoutInflater.from(testContext).inflate(AppViewHolder.LAYOUT_ID, null)
viewHolder = AppViewHolder(view, interactor)
}
@Test
fun `bind app share option`() {
val app = AppShareOption(
name = "Pocket",
icon = getDrawable(testContext, R.drawable.ic_pocket)!!,
packageName = "com.mozilla.pocket",
activityName = "MainActivity"
)
viewHolder.bind(app)
assertEquals("Pocket", viewHolder.itemView.appName.text)
assertEquals(app.icon, viewHolder.itemView.appIcon.drawable)
}
@Test
fun `trigger interactor if application is bound`() {
val app = AppShareOption(
name = "Pocket",
icon = getDrawable(testContext, R.drawable.ic_pocket)!!,
packageName = "com.mozilla.pocket",
activityName = "MainActivity"
)
viewHolder.itemView.performClick()
verify { interactor wasNot Called }
viewHolder.bind(app)
viewHolder.itemView.performClick()
verify { interactor.onShareToApp(app) }
}
}
Supports Markdown
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