From d755480214c4421c34325d287d0fad72151aa398 Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Wed, 8 Jan 2025 09:55:35 +0530 Subject: [PATCH 1/5] Navigate back to items screen on orders successfully completed --- .../android/ui/woopos/home/WooPosHomeViewModel.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModel.kt index 23e7eabbba2..947b3200ae1 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModel.kt @@ -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 @@ -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( @@ -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 ) From 04b09d0a956263f7fc4aab08af422728c2686d00 Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Wed, 8 Jan 2025 09:55:54 +0530 Subject: [PATCH 2/5] Remove unnecessary code --- .../android/ui/woopos/home/totals/WooPosTotalsViewModel.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewModel.kt index 5b607f56b42..40da8f0109e 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewModel.kt @@ -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 @@ -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, @@ -305,9 +303,6 @@ class WooPosTotalsViewModel @Inject constructor( } is CardReaderPaymentState.PaymentSuccessful -> { - wooPosItemsNavigator.sendNavigationEvent( - WooPosItemsNavigator.WooPosItemsScreenNavigationEvent.NavigateBackToItemListScreen - ) childrenToParentEventSender.sendToParent(OrderSuccessfullyPaidByCard) } From 8d9ce941b7aa447e49c88d429255b0391e19bd58 Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Wed, 8 Jan 2025 09:56:02 +0530 Subject: [PATCH 3/5] Remove unnecessary code in test file --- .../ui/woopos/home/totals/WooPosTotalsViewModelTest.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewModelTest.kt index 08eca2b3a60..5a2071ed68d 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewModelTest.kt @@ -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 @@ -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() @@ -1251,7 +1248,6 @@ class WooPosTotalsViewModelTest { analyticsTracker = analyticsTracker, networkStatus = networkStatus, cardReaderPaymentControllerFactory = cardReaderPaymentControllerFactory, - wooPosItemsNavigator = wooPosItemsNavigator, isReceiptSendingSupported = isReceiptSendingSupported, uiStringParser = uiStringParser, savedState = savedState, From 885f43297f70d13e2acfc86f9480cb2cf446302f Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Wed, 8 Jan 2025 09:56:22 +0530 Subject: [PATCH 4/5] Add test to verify proper navigation event is fired when payment is completed by card --- .../ui/woopos/home/WooPosHomeViewModelTest.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModelTest.kt index da236266e64..765656c3dad 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModelTest.kt @@ -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 @@ -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`() = @@ -398,9 +400,27 @@ 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 + ) + } + private fun createViewModel() = WooPosHomeViewModel( childrenToParentEventReceiver, parentToChildrenEventSender, + wooPosItemsNavigator, SavedStateHandle() ) } From ec0ca3c762a9929cefca76e29076621c64ef922b Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Wed, 8 Jan 2025 09:58:05 +0530 Subject: [PATCH 5/5] Add test to verify proper navigation event is fired when payment is completed by cash --- .../ui/woopos/home/WooPosHomeViewModelTest.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModelTest.kt index 765656c3dad..2d27b82a186 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModelTest.kt @@ -417,6 +417,23 @@ class WooPosHomeViewModelTest { ) } + @Test + fun `given OrderSuccessfullyPaid by cash, then redirect back to items screen`() = + runTest { + // GIVEN + val events = MutableSharedFlow() + 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,