Skip to content

Commit

Permalink
For mozilla-mobile#11498/mozilla-mobile#11499 - added/fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BranescuMihai committed Jul 31, 2020
1 parent db8fd83 commit 01a2465
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/org/mozilla/fenix/sync/SyncedTabsLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class SyncedTabsLayout @JvmOverloads constructor(

companion object {

private fun pullToRefreshEnableState(error: SyncedTabsView.ErrorType) = when (error) {
internal fun pullToRefreshEnableState(error: SyncedTabsView.ErrorType) = when (error) {
// Disable "pull-to-refresh" when we clearly can't sync tabs, and user needs to take an
// action within the app.
SyncedTabsView.ErrorType.SYNC_UNAVAILABLE,
Expand All @@ -97,15 +97,15 @@ class SyncedTabsLayout @JvmOverloads constructor(
SyncedTabsView.ErrorType.NO_TABS_AVAILABLE -> true
}

private fun stringResourceForError(error: SyncedTabsView.ErrorType) = when (error) {
internal fun stringResourceForError(error: SyncedTabsView.ErrorType) = when (error) {
SyncedTabsView.ErrorType.MULTIPLE_DEVICES_UNAVAILABLE -> R.string.synced_tabs_connect_another_device
SyncedTabsView.ErrorType.SYNC_ENGINE_UNAVAILABLE -> R.string.synced_tabs_enable_tab_syncing
SyncedTabsView.ErrorType.SYNC_UNAVAILABLE -> R.string.synced_tabs_sign_in_message
SyncedTabsView.ErrorType.SYNC_NEEDS_REAUTHENTICATION -> R.string.synced_tabs_reauth
SyncedTabsView.ErrorType.NO_TABS_AVAILABLE -> R.string.synced_tabs_no_tabs
}

private fun getErrorItem(
internal fun getErrorItem(
navController: NavController?,
error: SyncedTabsView.ErrorType,
@StringRes stringResId: Int
Expand Down
51 changes: 50 additions & 1 deletion app/src/test/java/org/mozilla/fenix/sync/SyncedTabsLayoutTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

package org.mozilla.fenix.sync

import androidx.navigation.NavController
import io.mockk.mockk
import mozilla.components.feature.syncedtabs.view.SyncedTabsView.ErrorType
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import org.mozilla.fenix.R
Expand All @@ -33,7 +37,7 @@ class SyncedTabsLayoutTest {
SyncedTabsLayout.stringResourceForError(ErrorType.SYNC_ENGINE_UNAVAILABLE)
)
assertEquals(
R.string.synced_tabs_connect_to_sync_account,
R.string.synced_tabs_sign_in_message,
SyncedTabsLayout.stringResourceForError(ErrorType.SYNC_UNAVAILABLE)
)
assertEquals(
Expand All @@ -45,4 +49,49 @@ class SyncedTabsLayoutTest {
SyncedTabsLayout.stringResourceForError(ErrorType.NO_TABS_AVAILABLE)
)
}

@Test
fun `get error item`() {
val navController = mockk<NavController>()

var errorItem = SyncedTabsLayout.getErrorItem(
navController,
ErrorType.MULTIPLE_DEVICES_UNAVAILABLE,
R.string.synced_tabs_connect_another_device
)
assertNull((errorItem as SyncedTabsAdapter.AdapterItem.Error).navController)
assertEquals(R.string.synced_tabs_connect_another_device, errorItem.descriptionResId)

errorItem = SyncedTabsLayout.getErrorItem(
navController,
ErrorType.SYNC_ENGINE_UNAVAILABLE,
R.string.synced_tabs_enable_tab_syncing
)
assertNull((errorItem as SyncedTabsAdapter.AdapterItem.Error).navController)
assertEquals(R.string.synced_tabs_enable_tab_syncing, errorItem.descriptionResId)

errorItem = SyncedTabsLayout.getErrorItem(
navController,
ErrorType.SYNC_NEEDS_REAUTHENTICATION,
R.string.synced_tabs_reauth
)
assertNull((errorItem as SyncedTabsAdapter.AdapterItem.Error).navController)
assertEquals(R.string.synced_tabs_reauth, errorItem.descriptionResId)

errorItem = SyncedTabsLayout.getErrorItem(
navController,
ErrorType.NO_TABS_AVAILABLE,
R.string.synced_tabs_no_tabs
)
assertNull((errorItem as SyncedTabsAdapter.AdapterItem.Error).navController)
assertEquals(R.string.synced_tabs_no_tabs, errorItem.descriptionResId)

errorItem = SyncedTabsLayout.getErrorItem(
navController,
ErrorType.SYNC_UNAVAILABLE,
R.string.synced_tabs_sign_in_message
)
assertNotNull((errorItem as SyncedTabsAdapter.AdapterItem.Error).navController)
assertEquals(R.string.synced_tabs_sign_in_message, errorItem.descriptionResId)
}
}

0 comments on commit 01a2465

Please sign in to comment.