Skip to content

Commit

Permalink
Merge pull request #13256 from woocommerce/issue/13255-redirect-after…
Browse files Browse the repository at this point in the history
…-cash-payment

[Woo POS][Non-Simple Products] Redirect to Items screen after cash payment
  • Loading branch information
malinajirka authored Jan 8, 2025
2 parents 6b7781f + ec0ca3c commit 2016f5a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.woocommerce.android.ui.woopos.home.ParentToChildrenEvent.OrderSuccess
import com.woocommerce.android.ui.woopos.home.WooPosHomeState.ExitConfirmationDialog
import com.woocommerce.android.ui.woopos.home.WooPosHomeState.ProductsInfoDialog
import com.woocommerce.android.ui.woopos.home.WooPosHomeState.ScreenPositionState
import com.woocommerce.android.ui.woopos.home.items.navigation.WooPosItemsNavigator
import com.woocommerce.android.viewmodel.getStateFlow
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableSharedFlow
Expand All @@ -20,6 +21,7 @@ import javax.inject.Inject
class WooPosHomeViewModel @Inject constructor(
private val childrenToParentEventReceiver: WooPosChildrenToParentEventReceiver,
private val parentToChildrenEventSender: WooPosParentToChildrenEventSender,
private val wooPosItemsNavigator: WooPosItemsNavigator,
savedStateHandle: SavedStateHandle,
) : ViewModel() {
private val _state = savedStateHandle.getStateFlow(
Expand Down Expand Up @@ -200,6 +202,11 @@ class WooPosHomeViewModel @Inject constructor(
}

private fun onOrderSuccessfullyPaid(paymentMethod: PaymentMethod) {
viewModelScope.launch {
wooPosItemsNavigator.sendNavigationEvent(
WooPosItemsNavigator.WooPosItemsScreenNavigationEvent.NavigateBackToItemListScreen
)
}
_state.value = _state.value.copy(
screenPositionState = ScreenPositionState.Checkout.FullScreenTotals
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import com.woocommerce.android.ui.woopos.home.ParentToChildrenEvent.OrderSuccess
import com.woocommerce.android.ui.woopos.home.WooPosChildrenToParentEventSender
import com.woocommerce.android.ui.woopos.home.WooPosParentToChildrenEventReceiver
import com.woocommerce.android.ui.woopos.home.items.WooPosItemsViewModel
import com.woocommerce.android.ui.woopos.home.items.navigation.WooPosItemsNavigator
import com.woocommerce.android.ui.woopos.home.totals.WooPosTotalsViewState.PaymentFailed
import com.woocommerce.android.ui.woopos.home.totals.WooPosTotalsViewState.PaymentInProgress
import com.woocommerce.android.ui.woopos.util.WooPosNetworkStatus
Expand Down Expand Up @@ -62,7 +61,6 @@ class WooPosTotalsViewModel @Inject constructor(
private val priceFormat: WooPosFormatPrice,
private val analyticsTracker: WooPosAnalyticsTracker,
private val networkStatus: WooPosNetworkStatus,
private val wooPosItemsNavigator: WooPosItemsNavigator,
private val isReceiptSendingSupported: WooPosEmailReceiptIsSendingSupported,
private val cardReaderPaymentControllerFactory: CardReaderPaymentControllerFactory,
private val uiStringParser: UiStringParser,
Expand Down Expand Up @@ -305,9 +303,6 @@ class WooPosTotalsViewModel @Inject constructor(
}

is CardReaderPaymentState.PaymentSuccessful -> {
wooPosItemsNavigator.sendNavigationEvent(
WooPosItemsNavigator.WooPosItemsScreenNavigationEvent.NavigateBackToItemListScreen
)
childrenToParentEventSender.sendToParent(OrderSuccessfullyPaidByCard)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.lifecycle.SavedStateHandle
import com.woocommerce.android.R
import com.woocommerce.android.ui.woopos.home.ParentToChildrenEvent.OrderSuccessfullyPaid.PaymentMethod
import com.woocommerce.android.ui.woopos.home.items.WooPosItemsViewModel.ItemClickedData
import com.woocommerce.android.ui.woopos.home.items.navigation.WooPosItemsNavigator
import com.woocommerce.android.ui.woopos.util.WooPosCoroutineTestRule
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableSharedFlow
Expand All @@ -30,6 +31,7 @@ class WooPosHomeViewModelTest {

private val childrenToParentEventReceiver: WooPosChildrenToParentEventReceiver = mock()
private val parentToChildrenEventSender: WooPosParentToChildrenEventSender = mock()
private val wooPosItemsNavigator: WooPosItemsNavigator = mock()

@Test
fun `given state checkout, when SystemBackClicked passed, then BackFromCheckoutToCartClicked event should be sent`() =
Expand Down Expand Up @@ -398,9 +400,44 @@ class WooPosHomeViewModelTest {
.isEqualTo(WooPosHomeState.ScreenPositionState.Checkout.FullScreenTotals)
}

@Test
fun `given OrderSuccessfullyPaid by card, then redirect back to items screen`() =
runTest {
// GIVEN
whenever(childrenToParentEventReceiver.events).thenReturn(
flowOf(ChildToParentEvent.OrderSuccessfullyPaidByCard)
)

// WHEN
createViewModel()

// THEN
verify(wooPosItemsNavigator).sendNavigationEvent(
WooPosItemsNavigator.WooPosItemsScreenNavigationEvent.NavigateBackToItemListScreen
)
}

@Test
fun `given OrderSuccessfullyPaid by cash, then redirect back to items screen`() =
runTest {
// GIVEN
val events = MutableSharedFlow<ChildToParentEvent>()
whenever(childrenToParentEventReceiver.events).thenReturn(events)
val viewModel = createViewModel()

// WHEN
viewModel.onUIEvent(WooPosHomeUIEvent.OnPaymentCompletedViaCash)

// THEN
verify(wooPosItemsNavigator).sendNavigationEvent(
WooPosItemsNavigator.WooPosItemsScreenNavigationEvent.NavigateBackToItemListScreen
)
}

private fun createViewModel() = WooPosHomeViewModel(
childrenToParentEventReceiver,
parentToChildrenEventSender,
wooPosItemsNavigator,
SavedStateHandle()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import com.woocommerce.android.ui.woopos.home.ParentToChildrenEvent.OrderSuccess
import com.woocommerce.android.ui.woopos.home.WooPosChildrenToParentEventSender
import com.woocommerce.android.ui.woopos.home.WooPosParentToChildrenEventReceiver
import com.woocommerce.android.ui.woopos.home.items.WooPosItemsViewModel
import com.woocommerce.android.ui.woopos.home.items.navigation.WooPosItemsNavigator
import com.woocommerce.android.ui.woopos.util.WooPosCoroutineTestRule
import com.woocommerce.android.ui.woopos.util.WooPosNetworkStatus
import com.woocommerce.android.ui.woopos.util.analytics.WooPosAnalyticsEvent
Expand Down Expand Up @@ -81,8 +80,6 @@ class WooPosTotalsViewModelTest {

private val networkStatus: WooPosNetworkStatus = mock()

private val wooPosItemsNavigator: WooPosItemsNavigator = mock()

private val childrenToParentEventSender: WooPosChildrenToParentEventSender = mock()
private val resourceProvider: ResourceProvider = mock()
private val cardReaderManager: CardReaderManager = mock()
Expand Down Expand Up @@ -1251,7 +1248,6 @@ class WooPosTotalsViewModelTest {
analyticsTracker = analyticsTracker,
networkStatus = networkStatus,
cardReaderPaymentControllerFactory = cardReaderPaymentControllerFactory,
wooPosItemsNavigator = wooPosItemsNavigator,
isReceiptSendingSupported = isReceiptSendingSupported,
uiStringParser = uiStringParser,
savedState = savedState,
Expand Down

0 comments on commit 2016f5a

Please sign in to comment.