From 64072a12561476017cedc52d67db009bb39b8fba Mon Sep 17 00:00:00 2001 From: Mihai Branescu Date: Fri, 31 Jul 2020 20:12:53 +0300 Subject: [PATCH] For #11498/#11499 - added/fixed unit tests --- .../mozilla/fenix/sync/SyncedTabsLayout.kt | 6 +-- .../fenix/sync/SyncedTabsLayoutTest.kt | 51 ++++++++++++++++++- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/sync/SyncedTabsLayout.kt b/app/src/main/java/org/mozilla/fenix/sync/SyncedTabsLayout.kt index 564efb63f..8308692ba 100644 --- a/app/src/main/java/org/mozilla/fenix/sync/SyncedTabsLayout.kt +++ b/app/src/main/java/org/mozilla/fenix/sync/SyncedTabsLayout.kt @@ -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, @@ -97,7 +97,7 @@ 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 @@ -105,7 +105,7 @@ class SyncedTabsLayout @JvmOverloads constructor( 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 diff --git a/app/src/test/java/org/mozilla/fenix/sync/SyncedTabsLayoutTest.kt b/app/src/test/java/org/mozilla/fenix/sync/SyncedTabsLayoutTest.kt index 9805c4445..a04bfbb51 100644 --- a/app/src/test/java/org/mozilla/fenix/sync/SyncedTabsLayoutTest.kt +++ b/app/src/test/java/org/mozilla/fenix/sync/SyncedTabsLayoutTest.kt @@ -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 @@ -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( @@ -45,4 +49,49 @@ class SyncedTabsLayoutTest { SyncedTabsLayout.stringResourceForError(ErrorType.NO_TABS_AVAILABLE) ) } + + @Test + fun `get error item`() { + val navController = mockk() + + 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) + } }