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 @@ -16,6 +16,8 @@ import com.woocommerce.android.analytics.AnalyticsTracker.Companion.KEY_ERROR
import com.woocommerce.android.analytics.AnalyticsTracker.Companion.KEY_STATE
import com.woocommerce.android.analytics.AnalyticsTracker.Companion.VALUE_STARTED
import com.woocommerce.android.analytics.AnalyticsTrackerWrapper
import com.woocommerce.android.ciab.CIABAffectedFeature
import com.woocommerce.android.ciab.CIABSiteGateKeeper
import com.woocommerce.android.extensions.combine
import com.woocommerce.android.extensions.sumByFloat
import com.woocommerce.android.model.Address
Expand Down Expand Up @@ -124,6 +126,7 @@ class WooShippingLabelCreationViewModel @Inject constructor(
private val fetchShippingLabelFile: FetchShippingLabelFile,
private val observeShippingLabelStatus: ObserveShippingLabelStatus,
private val downloadAndPrintInvoiceUseCase: DownloadAndPrintInvoiceUseCase,
private val ciabSiteGateKeeper: CIABSiteGateKeeper,
private val analyticsTracker: AnalyticsTrackerWrapper,
) : ScopedViewModel(savedState) {
private val navArgs: WooShippingLabelCreationFragmentArgs by savedState.navArgs()
Expand Down Expand Up @@ -779,6 +782,9 @@ class WooShippingLabelCreationViewModel @Inject constructor(
formattedPrice = shipmentUIList[uiState.selectedIndex].shipmentCostUI?.formattedTotalPrice,
onMarkOrderCompleteChange = ::onMarkOrderCompleteChange,
onPurchaseShippingLabel = ::onPurchaseShippingLabel
),
isSplitShipmentsSupported = ciabSiteGateKeeper.isFeatureSupported(
feature = CIABAffectedFeature.WooShippingSplitShipments
)
)
}.combine(loadTrigger.onStart { emit(Unit) }) { viewState, _ ->
Expand Down Expand Up @@ -1283,16 +1289,17 @@ class WooShippingLabelCreationViewModel @Inject constructor(
val uiState: UIControlsState,
val destinationStatus: AddressStatus,
val paymentsSectionUI: PaymentsSectionUI,
val purchaseSectionUI: PurchaseSectionUI
val purchaseSectionUI: PurchaseSectionUI,
val isSplitShipmentsSupported: Boolean
) : WooShippingViewState() {
val shouldShowSplitShipmentButton: Boolean
get() {
val unpurchasedShipments = shipmentUIList.filterNot { it.isPurchased }
return shipmentUIList.none { it.isPurchaseInProgress } &&
(
unpurchasedShipments.size > 1 ||
(unpurchasedShipments.firstOrNull()?.totalItemQuantity ?: 0) > 1
)
val hasMultipleUnfulfilledItems = unpurchasedShipments.size > 1 ||
(unpurchasedShipments.firstOrNull()?.totalItemQuantity ?: 0) > 1
return isSplitShipmentsSupported &&
shipmentUIList.none { it.isPurchaseInProgress } &&
hasMultipleUnfulfilledItems
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import com.woocommerce.android.analytics.AnalyticsTracker
import com.woocommerce.android.analytics.AnalyticsTracker.Companion.KEY_ERROR
import com.woocommerce.android.analytics.AnalyticsTracker.Companion.KEY_STATE
import com.woocommerce.android.analytics.AnalyticsTrackerWrapper
import com.woocommerce.android.ciab.CIABAffectedFeature
import com.woocommerce.android.ciab.CIABSiteGateKeeper
import com.woocommerce.android.model.Address
import com.woocommerce.android.model.AmbiguousLocation
import com.woocommerce.android.model.Location
Expand Down Expand Up @@ -330,6 +332,9 @@ class WooShippingLabelCreationViewModelTest : BaseUnitTest() {
private val file: File = mock()
private val analyticsTracker: AnalyticsTrackerWrapper = mock()
private val createDefaultCustomsData = CreateDefaultCustomsData(mock())
private val ciabSiteGateKeeper: CIABSiteGateKeeper = mock {
on { isFeatureSupported(CIABAffectedFeature.WooShippingSplitShipments) } doReturn true
}

private lateinit var sut: WooShippingLabelCreationViewModel

Expand All @@ -355,6 +360,7 @@ class WooShippingLabelCreationViewModelTest : BaseUnitTest() {
observeShippingLabelStatus = observeShippingLabelStatus,
downloadAndPrintInvoiceUseCase = mock(),
analyticsTracker = analyticsTracker,
ciabSiteGateKeeper = ciabSiteGateKeeper,
savedState = savedState
)
}
Expand Down Expand Up @@ -1809,4 +1815,30 @@ class WooShippingLabelCreationViewModelTest : BaseUnitTest() {
@Suppress("UnusedFlow")
verify(observeShippingLabelStatus).invoke(orderId, inProgressLabel.labelId)
}

@Test
fun `given split shipments unsupported, when displaying shipments, then hide split option`() = testBlocking {
// The default `getShipments` mock already returns a shipment with multiple items
given(ciabSiteGateKeeper.isFeatureSupported(CIABAffectedFeature.WooShippingSplitShipments))
.willReturn(false)

createViewModel()

val currentViewState = sut.viewState.value as DataState

assertThat(currentViewState.shouldShowSplitShipmentButton).isFalse
}

@Test
fun `given split shipments supported, when displaying shipments, then hide split option`() = testBlocking {
// The default `getShipments` mock already returns a shipment with multiple items
given(ciabSiteGateKeeper.isFeatureSupported(CIABAffectedFeature.WooShippingSplitShipments))
.willReturn(true)

createViewModel()

val currentViewState = sut.viewState.value as DataState

assertThat(currentViewState.shouldShowSplitShipmentButton).isTrue
}
}
Loading