Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ enum class CIABAffectedFeature {
GroupedProducts,
VariableProducts,
GiftCardEditing,
ProductsStockDashboardCard
ProductsStockDashboardCard,
POS
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.woocommerce.android.ui.woopos.tab

import com.woocommerce.android.ciab.CIABAffectedFeature
import com.woocommerce.android.ciab.CIABSiteGateKeeper
import com.woocommerce.android.tools.SelectedSite
import com.woocommerce.android.ui.woopos.WooPosIsScreenSizeAllowed
import com.woocommerce.android.ui.woopos.common.util.WooPosCouldNotDetermineValueException
Expand All @@ -16,12 +18,19 @@ class WooPosTabShouldBeVisible @Inject constructor(
private val isScreenSizeAllowed: WooPosIsScreenSizeAllowed,
private val wooCommerceStore: WooCommerceStore,
private val isRemoteFeatureFlagEnabled: IsRemoteFeatureFlagEnabled,
private val ciabSiteGateKeeper: CIABSiteGateKeeper,
private val wooPosLog: WooPosLogWrapper,
) {
suspend operator fun invoke(): Result<Boolean> = withContext(Dispatchers.IO) {
val selectedSite = selectedSite.getOrNull()
?: return@withContext Result.failure(WooPosCouldNotDetermineValueException())

if (ciabSiteGateKeeper.isFeatureUnsupported(CIABAffectedFeature.POS)) {
return@withContext Result.success(false).also {
wooPosLog.i("POS Tab Not visible reason: Site is CIAB")
}
}

if (!isRemoteFeatureFlagEnabled(WOO_POS)) {
return@withContext Result.success(false).also {
wooPosLog.i("POS Tab Not visible reason: Remote feature flag is disabled")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.woocommerce.android.ui.woopos.tab

import com.woocommerce.android.ciab.CIABAffectedFeature
import com.woocommerce.android.ciab.CIABSiteGateKeeper
import com.woocommerce.android.tools.SelectedSite
import com.woocommerce.android.ui.woopos.WooPosIsScreenSizeAllowed
import com.woocommerce.android.ui.woopos.common.util.WooPosCouldNotDetermineValueException
Expand All @@ -9,6 +11,7 @@ import com.woocommerce.android.viewmodel.BaseUnitTest
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Before
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
Expand All @@ -28,6 +31,9 @@ class WooPosTabShouldBeVisibleTest : BaseUnitTest() {
private val wooCommerceStore: WooCommerceStore = mock()
private val isScreenSizeAllowed: WooPosIsScreenSizeAllowed = mock()
private val isRemoteFeatureFlagEnabled: IsRemoteFeatureFlagEnabled = mock()
private val ciabSiteGateKeeper: CIABSiteGateKeeper = mock {
on { isFeatureUnsupported(CIABAffectedFeature.POS) } doReturn false
}

private lateinit var sut: WooPosTabShouldBeVisible
private lateinit var siteModel: SiteModel
Expand All @@ -46,6 +52,7 @@ class WooPosTabShouldBeVisibleTest : BaseUnitTest() {
isScreenSizeAllowed = isScreenSizeAllowed,
wooCommerceStore = wooCommerceStore,
isRemoteFeatureFlagEnabled = isRemoteFeatureFlagEnabled,
ciabSiteGateKeeper = ciabSiteGateKeeper,
wooPosLog = mock()
)
}
Expand Down Expand Up @@ -120,6 +127,16 @@ class WooPosTabShouldBeVisibleTest : BaseUnitTest() {
assertFalse(r.getOrThrow())
}

@Test
fun `given feature unsupported for CIAB site, when invoked, then return success false`() = testBlocking {
whenever(ciabSiteGateKeeper.isFeatureUnsupported(CIABAffectedFeature.POS)).thenReturn(true)

val r = sut()

assertTrue(r.isSuccess)
assertFalse(r.getOrThrow())
}

private fun buildSiteSettings(countryCode: String = "us") =
WCSettingsTestUtils.generateSettings(
siteId = LocalOrRemoteId.LocalId(1)
Expand Down