From 364726d6ebef454069c01c06ea28dc75a1dcfd57 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 26 Nov 2024 09:30:08 +0100 Subject: [PATCH 01/14] Payment success state modification if it can send receipts --- .../android/ui/woopos/home/totals/WooPosTotalsViewModel.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 194da209f86..2ff0a141c7b 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 @@ -120,7 +120,10 @@ class WooPosTotalsViewModel @Inject constructor( is WooPosCardReaderPaymentStatus.Success -> { val state = uiState.value check(state is WooPosTotalsViewState.Totals) - uiState.value = WooPosTotalsViewState.PaymentSuccess(orderTotalText = state.orderTotalText) + uiState.value = WooPosTotalsViewState.PaymentSuccess( + orderTotalText = state.orderTotalText, + + ) childrenToParentEventSender.sendToParent(ChildToParentEvent.OrderSuccessfullyPaid) } is WooPosCardReaderPaymentStatus.Failure, From a10e2418a6a60e417cf31ef8c21c48a46170bfc9 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 26 Nov 2024 09:37:29 +0100 Subject: [PATCH 02/14] Payment success state modification if it can send receipts --- .../ui/woopos/home/totals/WooPosTotalsViewState.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewState.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewState.kt index 23a78af03d4..e578611e85e 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewState.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewState.kt @@ -8,12 +8,15 @@ sealed class WooPosTotalsViewState : Parcelable { data object Loading : WooPosTotalsViewState() data class Totals( - var orderSubtotalText: String, - var orderTaxText: String, - var orderTotalText: String, + val orderSubtotalText: String, + val orderTaxText: String, + val orderTotalText: String, ) : WooPosTotalsViewState() - data class PaymentSuccess(var orderTotalText: String) : WooPosTotalsViewState() + data class PaymentSuccess( + val orderTotalText: String, + val canSendReceipt: Boolean, + ) : WooPosTotalsViewState() data class Error(val message: String) : WooPosTotalsViewState() } From e9d9bfdf1bb9f410e773427c29b81e5465564065 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 26 Nov 2024 09:37:54 +0100 Subject: [PATCH 03/14] WooPosIsReceiptSendingAvailable checker --- .../WooPosIsReceiptSendingAvailable.kt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/receipt/WooPosIsReceiptSendingAvailable.kt diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/receipt/WooPosIsReceiptSendingAvailable.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/receipt/WooPosIsReceiptSendingAvailable.kt new file mode 100644 index 00000000000..23ff416e240 --- /dev/null +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/receipt/WooPosIsReceiptSendingAvailable.kt @@ -0,0 +1,33 @@ +package com.woocommerce.android.ui.woopos.home.totals.receipt + +import com.woocommerce.android.extensions.semverCompareTo +import com.woocommerce.android.ui.woopos.featureflags.WooPosIsReceiptsEnabled +import com.woocommerce.android.util.GetWooCorePluginCachedVersion +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import javax.inject.Inject + +class WooPosIsReceiptSendingAvailable @Inject constructor( + private val isReceiptsEnabled: WooPosIsReceiptsEnabled, + private val getWooCoreVersion: GetWooCorePluginCachedVersion, +) { + suspend fun invoke() = + if (!isReceiptsEnabled()) { + false + } else { + isWooCoreSupportsSendingReceiptsByEmail() + } + + private suspend fun isWooCoreSupportsSendingReceiptsByEmail() = withContext(Dispatchers.IO) { + val wooCoreVersion = getWooCoreVersion() + if (wooCoreVersion == null) { + false + } else { + wooCoreVersion.semverCompareTo(WC_VERSION_SUPPORTS_SENDING_RECEIPTS_BY_EMAIL) >= 0 + } + } + + private companion object { + const val WC_VERSION_SUPPORTS_SENDING_RECEIPTS_BY_EMAIL = "9.5.0" + } +} From e17d2869953b6f0f666fd8bf480d65709cc5fde4 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 26 Nov 2024 09:41:48 +0100 Subject: [PATCH 04/14] Set value if receipt available to the view state --- .../android/ui/woopos/home/totals/WooPosTotalsViewModel.kt | 4 +++- .../android/ui/woopos/home/totals/WooPosTotalsViewState.kt | 2 +- .../home/totals/receipt/WooPosIsReceiptSendingAvailable.kt | 2 +- 3 files changed, 5 insertions(+), 3 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 2ff0a141c7b..7b7dae83e0e 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 @@ -12,6 +12,7 @@ import com.woocommerce.android.ui.woopos.home.ChildToParentEvent import com.woocommerce.android.ui.woopos.home.ParentToChildrenEvent import com.woocommerce.android.ui.woopos.home.WooPosChildrenToParentEventSender import com.woocommerce.android.ui.woopos.home.WooPosParentToChildrenEventReceiver +import com.woocommerce.android.ui.woopos.home.totals.receipt.WooPosIsReceiptSendingAvailable import com.woocommerce.android.ui.woopos.util.WooPosNetworkStatus import com.woocommerce.android.ui.woopos.util.analytics.WooPosAnalyticsEvent import com.woocommerce.android.ui.woopos.util.analytics.WooPosAnalyticsTracker @@ -37,6 +38,7 @@ class WooPosTotalsViewModel @Inject constructor( private val priceFormat: WooPosFormatPrice, private val analyticsTracker: WooPosAnalyticsTracker, private val networkStatus: WooPosNetworkStatus, + private val isReceiptSendingAvailable: WooPosIsReceiptSendingAvailable, savedState: SavedStateHandle, ) : ViewModel() { @@ -122,7 +124,7 @@ class WooPosTotalsViewModel @Inject constructor( check(state is WooPosTotalsViewState.Totals) uiState.value = WooPosTotalsViewState.PaymentSuccess( orderTotalText = state.orderTotalText, - + isReceiptAvailable = isReceiptSendingAvailable() ) childrenToParentEventSender.sendToParent(ChildToParentEvent.OrderSuccessfullyPaid) } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewState.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewState.kt index e578611e85e..a1424b4d76b 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewState.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewState.kt @@ -15,7 +15,7 @@ sealed class WooPosTotalsViewState : Parcelable { data class PaymentSuccess( val orderTotalText: String, - val canSendReceipt: Boolean, + val isReceiptAvailable: Boolean, ) : WooPosTotalsViewState() data class Error(val message: String) : WooPosTotalsViewState() diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/receipt/WooPosIsReceiptSendingAvailable.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/receipt/WooPosIsReceiptSendingAvailable.kt index 23ff416e240..1dc717803ae 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/receipt/WooPosIsReceiptSendingAvailable.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/receipt/WooPosIsReceiptSendingAvailable.kt @@ -11,7 +11,7 @@ class WooPosIsReceiptSendingAvailable @Inject constructor( private val isReceiptsEnabled: WooPosIsReceiptsEnabled, private val getWooCoreVersion: GetWooCorePluginCachedVersion, ) { - suspend fun invoke() = + suspend operator fun invoke() = if (!isReceiptsEnabled()) { false } else { From 6ac8e194de9ffb291ff4d72b427b23ee6cffb30f Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 26 Nov 2024 09:43:18 +0100 Subject: [PATCH 05/14] Pass whole string from VM --- .../android/ui/woopos/home/totals/WooPosTotalsViewModel.kt | 7 ++++++- .../payment/success/WooPosTotalsPaymentSuccessScreen.kt | 7 +++++-- 2 files changed, 11 insertions(+), 3 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 7b7dae83e0e..ee6f554203a 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 @@ -122,8 +122,13 @@ class WooPosTotalsViewModel @Inject constructor( is WooPosCardReaderPaymentStatus.Success -> { val state = uiState.value check(state is WooPosTotalsViewState.Totals) + val orderTotalText = + resourceProvider.getString( + R.string.woopos_success_screen_total, + state.orderTotalText + ) uiState.value = WooPosTotalsViewState.PaymentSuccess( - orderTotalText = state.orderTotalText, + orderTotalText = orderTotalText, isReceiptAvailable = isReceiptSendingAvailable() ) childrenToParentEventSender.sendToParent(ChildToParentEvent.OrderSuccessfullyPaid) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/success/WooPosTotalsPaymentSuccessScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/success/WooPosTotalsPaymentSuccessScreen.kt index c93f42d1a78..3fd2ab36d38 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/success/WooPosTotalsPaymentSuccessScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/success/WooPosTotalsPaymentSuccessScreen.kt @@ -107,7 +107,7 @@ fun WooPosPaymentSuccessScreen( val marginBetweenButtonAndTextAdaptive = marginBetweenButtonAndText.toAdaptivePadding() Text( - text = stringResource(R.string.woopos_success_screen_total, state.orderTotalText), + text = state.orderTotalText, style = MaterialTheme.typography.h6, textAlign = TextAlign.Center, fontWeight = FontWeight.Normal, @@ -183,7 +183,10 @@ private fun CheckMarkIcon( fun WooPosPaymentSuccessScreenPreview() { WooPosTheme { WooPosPaymentSuccessScreen( - state = WooPosTotalsViewState.PaymentSuccess(orderTotalText = "$13.18"), + state = WooPosTotalsViewState.PaymentSuccess( + orderTotalText = "A payment of 13.18 was successfully made", + isReceiptAvailable = true, + ), bottomAnimationStarted = true, iconAnimationStarted = true, onNewTransactionClicked = {} From a77935de5fcfebcb7ca06117c3792ffce3b8c428 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 26 Nov 2024 09:45:48 +0100 Subject: [PATCH 06/14] Tests compilable --- .../woopos/home/totals/WooPosTotalsViewModelTest.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 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 dffaff896ea..715d9f9dc66 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 @@ -9,6 +9,7 @@ import com.woocommerce.android.ui.woopos.home.ChildToParentEvent import com.woocommerce.android.ui.woopos.home.ParentToChildrenEvent import com.woocommerce.android.ui.woopos.home.WooPosChildrenToParentEventSender import com.woocommerce.android.ui.woopos.home.WooPosParentToChildrenEventReceiver +import com.woocommerce.android.ui.woopos.home.totals.receipt.WooPosIsReceiptSendingAvailable 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 @@ -59,6 +60,7 @@ class WooPosTotalsViewModelTest { on { paymentStatus }.thenReturn(MutableStateFlow(WooPosCardReaderPaymentStatus.Unknown)) } private val analyticsTracker: WooPosAnalyticsTracker = mock() + private val isReceiptSendingAvailable: WooPosIsReceiptSendingAvailable = mock() private companion object { private const val EMPTY_ORDER_ID = -1L @@ -517,12 +519,15 @@ class WooPosTotalsViewModelTest { // THEN val state = viewModel.state.value assertThat(state).isEqualTo( - WooPosTotalsViewState.PaymentSuccess(orderTotalText = "$3.00") + WooPosTotalsViewState.PaymentSuccess( + orderTotalText = "$3.00", + isReceiptAvailable = false, + ) ) verify(childrenToParentEventSender).sendToParent(ChildToParentEvent.OrderSuccessfullyPaid) } - @org.junit.Test + @Test fun `given there is no internet, when trying to complete payment, then trigger proper event`() = runTest { // GIVEN whenever(networkStatus.isConnected()).thenReturn(false) @@ -573,7 +578,7 @@ class WooPosTotalsViewModelTest { verify(childrenToParentEventSender).sendToParent(ChildToParentEvent.NoInternet) } - @org.junit.Test + @Test fun `given there is no internet, when trying to complete payment, then collect payment method is not called`() = runTest { // GIVEN whenever(networkStatus.isConnected()).thenReturn(false) @@ -639,6 +644,7 @@ class WooPosTotalsViewModelTest { priceFormat, analyticsTracker, networkStatus, + isReceiptSendingAvailable, savedState ) } From 18f3326c142a4ddb37f8d622ef337d5c1a89c504 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 27 Nov 2024 12:24:38 +0100 Subject: [PATCH 07/14] Optional receipt button --- .../woopos/home/totals/WooPosTotalsScreen.kt | 6 ++- .../home/totals/WooPosTotalsViewModel.kt | 9 ++-- .../WooPosTotalsPaymentSuccessScreen.kt | 44 +++++++++++++++++-- WooCommerce/src/main/res/values/strings.xml | 1 + 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsScreen.kt index 6d9ad6b3c69..81c2c55ce4a 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsScreen.kt @@ -71,7 +71,11 @@ private fun WooPosTotalsScreen( StateChangeAnimated(visible = state is WooPosTotalsViewState.PaymentSuccess) { if (state is WooPosTotalsViewState.PaymentSuccess) { - WooPosPaymentSuccessScreen(state) { onUIEvent(WooPosTotalsUIEvent.OnNewTransactionClicked) } + WooPosPaymentSuccessScreen( + state, + onReceiptClicked = {}, + onNewTransactionClicked = { onUIEvent(WooPosTotalsUIEvent.OnNewTransactionClicked) } + ) } } 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 f76a0d37035..68d73fa1793 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 @@ -123,11 +123,10 @@ class WooPosTotalsViewModel @Inject constructor( is WooPosCardReaderPaymentStatus.Success -> { val state = uiState.value check(state is WooPosTotalsViewState.Totals) - val orderTotalText = - resourceProvider.getString( - R.string.woopos_success_screen_total, - state.orderTotalText - ) + val orderTotalText = resourceProvider.getString( + R.string.woopos_success_screen_total, + state.orderTotalText + ) uiState.value = WooPosTotalsViewState.PaymentSuccess( orderTotalText = orderTotalText, isReceiptAvailable = isReceiptSendingAvailable() diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/success/WooPosTotalsPaymentSuccessScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/success/WooPosTotalsPaymentSuccessScreen.kt index 3fd2ab36d38..debc7aafe3b 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/success/WooPosTotalsPaymentSuccessScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/success/WooPosTotalsPaymentSuccessScreen.kt @@ -40,6 +40,7 @@ import kotlinx.coroutines.delay @Composable fun WooPosPaymentSuccessScreen( state: WooPosTotalsViewState.PaymentSuccess, + onReceiptClicked: () -> Unit, onNewTransactionClicked: () -> Unit, ) { var bottomAnimationStarted by remember { mutableStateOf(false) } @@ -56,6 +57,7 @@ fun WooPosPaymentSuccessScreen( state = state, iconAnimationStarted = iconAnimationStarted, bottomAnimationStarted = bottomAnimationStarted, + onReceiptClicked = onReceiptClicked, onNewTransactionClicked = onNewTransactionClicked, ) } @@ -65,6 +67,7 @@ fun WooPosPaymentSuccessScreen( state: WooPosTotalsViewState.PaymentSuccess, iconAnimationStarted: Boolean, bottomAnimationStarted: Boolean, + onReceiptClicked: () -> Unit, onNewTransactionClicked: () -> Unit, ) { Box( @@ -79,7 +82,7 @@ fun WooPosPaymentSuccessScreen( ) @Suppress("DestructuringDeclarationWithTooManyEntries") ConstraintLayout { - val (icon, title, message, button) = createRefs() + val (icon, title, message, buttonReceipt, buttonNewOrder) = createRefs() val checkMarkIconMargin = 56.dp.toAdaptivePadding() CheckMarkIcon( @@ -106,6 +109,7 @@ fun WooPosPaymentSuccessScreen( ) val marginBetweenButtonAndTextAdaptive = marginBetweenButtonAndText.toAdaptivePadding() + val textLinkTo = if (state.isReceiptAvailable) buttonReceipt else buttonNewOrder Text( text = state.orderTotalText, style = MaterialTheme.typography.h6, @@ -115,13 +119,29 @@ fun WooPosPaymentSuccessScreen( modifier = Modifier.constrainAs(message) { start.linkTo(parent.start) end.linkTo(parent.end) - bottom.linkTo(button.top, margin = marginBetweenButtonAndTextAdaptive) + bottom.linkTo(textLinkTo.top, margin = marginBetweenButtonAndTextAdaptive) } ) + val marginBetweenButtons = 32.dp.toAdaptivePadding() + if (state.isReceiptAvailable) { + WooPosButton( + modifier = Modifier + .constrainAs(buttonReceipt) { + bottom.linkTo(buttonNewOrder.top, margin = marginBetweenButtons) + start.linkTo(parent.start) + end.linkTo(parent.end) + } + .height(80.dp) + .width(604.dp), + onClick = onReceiptClicked, + text = stringResource(R.string.woopos_receipt_button), + ) + } + WooPosButton( modifier = Modifier - .constrainAs(button) { + .constrainAs(buttonNewOrder) { bottom.linkTo(parent.bottom) start.linkTo(parent.start) end.linkTo(parent.end) @@ -189,6 +209,24 @@ fun WooPosPaymentSuccessScreenPreview() { ), bottomAnimationStarted = true, iconAnimationStarted = true, + onReceiptClicked = {}, + onNewTransactionClicked = {} + ) + } +} + +@WooPosPreview +@Composable +fun WooPosPaymentSuccessWithoutReceiptScreenPreview() { + WooPosTheme { + WooPosPaymentSuccessScreen( + state = WooPosTotalsViewState.PaymentSuccess( + orderTotalText = "A payment of 13.18 was successfully made", + isReceiptAvailable = false, + ), + bottomAnimationStarted = true, + iconAnimationStarted = true, + onReceiptClicked = {}, onNewTransactionClicked = {} ) } diff --git a/WooCommerce/src/main/res/values/strings.xml b/WooCommerce/src/main/res/values/strings.xml index c951fb10530..345eb311d40 100644 --- a/WooCommerce/src/main/res/values/strings.xml +++ b/WooCommerce/src/main/res/values/strings.xml @@ -4277,6 +4277,7 @@ Payment successful Payment successful checkmark icon New order + Receipt Subtotal Taxes Total From 74863fe1c775413e8396f54942e3f110cd0f3977 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 27 Nov 2024 12:39:00 +0100 Subject: [PATCH 08/14] Smaller margin between buttons --- .../totals/payment/success/WooPosTotalsPaymentSuccessScreen.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/success/WooPosTotalsPaymentSuccessScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/success/WooPosTotalsPaymentSuccessScreen.kt index debc7aafe3b..8ce194016ff 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/success/WooPosTotalsPaymentSuccessScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/success/WooPosTotalsPaymentSuccessScreen.kt @@ -123,7 +123,7 @@ fun WooPosPaymentSuccessScreen( } ) - val marginBetweenButtons = 32.dp.toAdaptivePadding() + val marginBetweenButtons = 16.dp.toAdaptivePadding() if (state.isReceiptAvailable) { WooPosButton( modifier = Modifier From 89d39777307ccf98c21ff3d3ed94353de5e4c480 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 27 Nov 2024 12:57:03 +0100 Subject: [PATCH 09/14] Mock UI for sending receipts --- .../home/totals/WooPosTotalsViewModel.kt | 2 +- .../WooPosIsReceiptSendingAvailable.kt | 2 +- .../WooPosTotalsPaymentReceiptScreen.kt | 73 +++++++++++++++++++ .../home/totals/WooPosTotalsViewModelTest.kt | 2 +- 4 files changed, 76 insertions(+), 3 deletions(-) rename WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/{ => payment}/receipt/WooPosIsReceiptSendingAvailable.kt (94%) create mode 100644 WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosTotalsPaymentReceiptScreen.kt 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 68d73fa1793..d2443a0e30d 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 @@ -12,8 +12,8 @@ import com.woocommerce.android.ui.woopos.home.ChildToParentEvent import com.woocommerce.android.ui.woopos.home.ParentToChildrenEvent import com.woocommerce.android.ui.woopos.home.WooPosChildrenToParentEventSender import com.woocommerce.android.ui.woopos.home.WooPosParentToChildrenEventReceiver -import com.woocommerce.android.ui.woopos.home.totals.receipt.WooPosIsReceiptSendingAvailable import com.woocommerce.android.ui.woopos.home.items.WooPosItemsViewModel +import com.woocommerce.android.ui.woopos.home.totals.payment.receipt.WooPosIsReceiptSendingAvailable import com.woocommerce.android.ui.woopos.util.WooPosNetworkStatus import com.woocommerce.android.ui.woopos.util.analytics.WooPosAnalyticsEvent import com.woocommerce.android.ui.woopos.util.analytics.WooPosAnalyticsTracker diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/receipt/WooPosIsReceiptSendingAvailable.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosIsReceiptSendingAvailable.kt similarity index 94% rename from WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/receipt/WooPosIsReceiptSendingAvailable.kt rename to WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosIsReceiptSendingAvailable.kt index 1dc717803ae..6d0c709416c 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/receipt/WooPosIsReceiptSendingAvailable.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosIsReceiptSendingAvailable.kt @@ -1,4 +1,4 @@ -package com.woocommerce.android.ui.woopos.home.totals.receipt +package com.woocommerce.android.ui.woopos.home.totals.payment.receipt import com.woocommerce.android.extensions.semverCompareTo import com.woocommerce.android.ui.woopos.featureflags.WooPosIsReceiptsEnabled diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosTotalsPaymentReceiptScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosTotalsPaymentReceiptScreen.kt new file mode 100644 index 00000000000..5f9dd7e99f8 --- /dev/null +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosTotalsPaymentReceiptScreen.kt @@ -0,0 +1,73 @@ +package com.woocommerce.android.ui.woopos.home.totals.payment.receipt + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.width +import androidx.compose.material.MaterialTheme +import androidx.compose.material.Text +import androidx.compose.material.TextField +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.constraintlayout.compose.ConstraintLayout +import com.woocommerce.android.ui.woopos.common.composeui.WooPosPreview +import com.woocommerce.android.ui.woopos.common.composeui.component.WooPosButton + +@Composable +fun WooPosTotalsPaymentReceiptScreen( + onEmailAddressChanged: (String) -> Unit, + onSendReceiptClicked: () -> Unit, +) { + Box( + modifier = Modifier + .fillMaxSize(), + contentAlignment = Alignment.Center + ) { + ConstraintLayout( + modifier = Modifier + .width(540.dp), + ) { + val (title, email, button) = createRefs() + + Text( + text = "Receipt", + style = MaterialTheme.typography.h2, + modifier = Modifier.constrainAs(title) { + top.linkTo(parent.top) + start.linkTo(parent.start) + } + ) + + TextField( + value = "", + onValueChange = onEmailAddressChanged, + label = { "email" }, + modifier = Modifier.constrainAs(email) { + top.linkTo(title.bottom, margin = 16.dp) + start.linkTo(parent.start) + end.linkTo(parent.end) + } + ) + + WooPosButton( + text = "Send", + onClick = onSendReceiptClicked, + modifier = Modifier.constrainAs(button) { + top.linkTo(email.bottom, margin = 16.dp) + start.linkTo(parent.start) + end.linkTo(parent.end) + }, + ) + } + } +} + +@WooPosPreview +@Composable +fun PreviewWooPosTotalsPaymentReceiptScreen() { + WooPosTotalsPaymentReceiptScreen( + onEmailAddressChanged = {}, + onSendReceiptClicked = {}, + ) +} 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 9f6b36cd632..9b5aca1a5bc 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 @@ -9,7 +9,7 @@ import com.woocommerce.android.ui.woopos.home.ChildToParentEvent import com.woocommerce.android.ui.woopos.home.ParentToChildrenEvent import com.woocommerce.android.ui.woopos.home.WooPosChildrenToParentEventSender import com.woocommerce.android.ui.woopos.home.WooPosParentToChildrenEventReceiver -import com.woocommerce.android.ui.woopos.home.totals.receipt.WooPosIsReceiptSendingAvailable +import com.woocommerce.android.ui.woopos.home.totals.payment.receipt.WooPosIsReceiptSendingAvailable import com.woocommerce.android.ui.woopos.home.items.WooPosItemsViewModel import com.woocommerce.android.ui.woopos.util.WooPosCoroutineTestRule import com.woocommerce.android.ui.woopos.util.WooPosNetworkStatus From 28e50fca47e7722f32abb4364db3140d95b95e8f Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 27 Nov 2024 13:05:18 +0100 Subject: [PATCH 10/14] State to show receipt screen --- .../ui/woopos/home/totals/WooPosTotalsScreen.kt | 13 ++++++++++++- .../ui/woopos/home/totals/WooPosTotalsUIEvent.kt | 2 ++ .../ui/woopos/home/totals/WooPosTotalsViewState.kt | 4 ++++ .../receipt/WooPosTotalsPaymentReceiptScreen.kt | 4 +++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsScreen.kt index 81c2c55ce4a..6dd302722b5 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsScreen.kt @@ -46,6 +46,7 @@ import com.woocommerce.android.ui.woopos.common.composeui.component.WooPosButton import com.woocommerce.android.ui.woopos.common.composeui.component.WooPosErrorScreen import com.woocommerce.android.ui.woopos.common.composeui.component.WooPosShimmerBox import com.woocommerce.android.ui.woopos.common.composeui.toAdaptivePadding +import com.woocommerce.android.ui.woopos.home.totals.payment.receipt.WooPosTotalsPaymentReceiptScreen import com.woocommerce.android.ui.woopos.home.totals.payment.success.WooPosPaymentSuccessScreen import kotlinx.coroutines.delay @@ -73,7 +74,7 @@ private fun WooPosTotalsScreen( if (state is WooPosTotalsViewState.PaymentSuccess) { WooPosPaymentSuccessScreen( state, - onReceiptClicked = {}, + onReceiptClicked = { onUIEvent(WooPosTotalsUIEvent.OnStartReceiptFlowClicked) }, onNewTransactionClicked = { onUIEvent(WooPosTotalsUIEvent.OnNewTransactionClicked) } ) } @@ -85,6 +86,16 @@ private fun WooPosTotalsScreen( } } + StateChangeAnimated(visible = state is WooPosTotalsViewState.ReceiptSending) { + if (state is WooPosTotalsViewState.ReceiptSending) { + WooPosTotalsPaymentReceiptScreen( + state, + onEmailAddressChanged = {}, + onSendReceiptClicked = { onUIEvent(WooPosTotalsUIEvent.OnSendReceiptClicked) } + ) + } + } + StateChangeAnimated(visible = state is WooPosTotalsViewState.Error) { if (state is WooPosTotalsViewState.Error) { TotalsErrorScreen( diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsUIEvent.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsUIEvent.kt index 7719dec6dd7..26143344294 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsUIEvent.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsUIEvent.kt @@ -4,4 +4,6 @@ sealed class WooPosTotalsUIEvent { data object CollectPaymentClicked : WooPosTotalsUIEvent() data object OnNewTransactionClicked : WooPosTotalsUIEvent() data object RetryOrderCreationClicked : WooPosTotalsUIEvent() + data object OnStartReceiptFlowClicked : WooPosTotalsUIEvent() + data object OnSendReceiptClicked : WooPosTotalsUIEvent() } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewState.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewState.kt index a1424b4d76b..c5b44f4b746 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewState.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewState.kt @@ -18,5 +18,9 @@ sealed class WooPosTotalsViewState : Parcelable { val isReceiptAvailable: Boolean, ) : WooPosTotalsViewState() + data class ReceiptSending( + val email: String, + ) : WooPosTotalsViewState() + data class Error(val message: String) : WooPosTotalsViewState() } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosTotalsPaymentReceiptScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosTotalsPaymentReceiptScreen.kt index 5f9dd7e99f8..e578ca033d7 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosTotalsPaymentReceiptScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosTotalsPaymentReceiptScreen.kt @@ -13,9 +13,11 @@ import androidx.compose.ui.unit.dp import androidx.constraintlayout.compose.ConstraintLayout import com.woocommerce.android.ui.woopos.common.composeui.WooPosPreview import com.woocommerce.android.ui.woopos.common.composeui.component.WooPosButton +import com.woocommerce.android.ui.woopos.home.totals.WooPosTotalsViewState @Composable fun WooPosTotalsPaymentReceiptScreen( + state: WooPosTotalsViewState.ReceiptSending, onEmailAddressChanged: (String) -> Unit, onSendReceiptClicked: () -> Unit, ) { @@ -40,7 +42,7 @@ fun WooPosTotalsPaymentReceiptScreen( ) TextField( - value = "", + value = state.email, onValueChange = onEmailAddressChanged, label = { "email" }, modifier = Modifier.constrainAs(email) { From 97c42ace112d57ca3ae3a59b3e14722cd9bca1d2 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 27 Nov 2024 13:17:06 +0100 Subject: [PATCH 11/14] Set receipt sending state when button is clicked --- .../android/ui/woopos/home/totals/WooPosTotalsViewModel.kt | 4 ++++ .../payment/receipt/WooPosTotalsPaymentReceiptScreen.kt | 1 + 2 files changed, 5 insertions(+) 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 d2443a0e30d..ee93330f333 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 @@ -81,6 +81,10 @@ class WooPosTotalsViewModel @Inject constructor( is WooPosTotalsUIEvent.RetryOrderCreationClicked -> { createOrderDraft(dataState.value.itemClickedDataList) } + WooPosTotalsUIEvent.OnSendReceiptClicked -> TODO() + WooPosTotalsUIEvent.OnStartReceiptFlowClicked -> { + uiState.value = WooPosTotalsViewState.ReceiptSending(email = "") + } } } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosTotalsPaymentReceiptScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosTotalsPaymentReceiptScreen.kt index e578ca033d7..7ef9b9e9d50 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosTotalsPaymentReceiptScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosTotalsPaymentReceiptScreen.kt @@ -69,6 +69,7 @@ fun WooPosTotalsPaymentReceiptScreen( @Composable fun PreviewWooPosTotalsPaymentReceiptScreen() { WooPosTotalsPaymentReceiptScreen( + state = WooPosTotalsViewState.ReceiptSending("email hint"), onEmailAddressChanged = {}, onSendReceiptClicked = {}, ) From 39d4c485c63aa85758611a5702011bffbeccf54d Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 27 Nov 2024 13:20:21 +0100 Subject: [PATCH 12/14] Fixed formatting --- .../android/ui/woopos/home/totals/WooPosTotalsViewModelTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9b5aca1a5bc..0e0ca69b379 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 @@ -9,8 +9,8 @@ import com.woocommerce.android.ui.woopos.home.ChildToParentEvent import com.woocommerce.android.ui.woopos.home.ParentToChildrenEvent import com.woocommerce.android.ui.woopos.home.WooPosChildrenToParentEventSender import com.woocommerce.android.ui.woopos.home.WooPosParentToChildrenEventReceiver -import com.woocommerce.android.ui.woopos.home.totals.payment.receipt.WooPosIsReceiptSendingAvailable import com.woocommerce.android.ui.woopos.home.items.WooPosItemsViewModel +import com.woocommerce.android.ui.woopos.home.totals.payment.receipt.WooPosIsReceiptSendingAvailable 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 From e9deffb0df1fede143e248b3ac66fbe8647b2dc6 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 27 Nov 2024 18:19:15 +0100 Subject: [PATCH 13/14] WooPosIsReceiptSendingAvailableTest --- .../WooPosIsReceiptSendingAvailableTest.kt | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosIsReceiptSendingAvailableTest.kt diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosIsReceiptSendingAvailableTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosIsReceiptSendingAvailableTest.kt new file mode 100644 index 00000000000..9679aa4c4cd --- /dev/null +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/totals/payment/receipt/WooPosIsReceiptSendingAvailableTest.kt @@ -0,0 +1,83 @@ +package com.woocommerce.android.ui.woopos.home.totals.payment.receipt + +import com.woocommerce.android.ui.woopos.featureflags.WooPosIsReceiptsEnabled +import com.woocommerce.android.util.GetWooCorePluginCachedVersion +import kotlinx.coroutines.test.runTest +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test +import org.mockito.kotlin.mock +import org.mockito.kotlin.whenever + +class WooPosIsReceiptSendingAvailableTest { + private val isReceiptsEnabled: WooPosIsReceiptsEnabled = mock() + private val getWooCoreVersion: GetWooCorePluginCachedVersion = mock() + + private val receiptSendingAvailable = WooPosIsReceiptSendingAvailable( + isReceiptsEnabled = isReceiptsEnabled, + getWooCoreVersion = getWooCoreVersion + ) + + @Test + fun `given receipts disabled, when invoked, then return false`() = runTest { + // GIVEN + whenever(isReceiptsEnabled()).thenReturn(false) + + // WHEN + val result = receiptSendingAvailable() + + // THEN + assertThat(result).isFalse + } + + @Test + fun `given receipts enabled and wooCoreVersion null, when invoked, then return false`() = runTest { + // GIVEN + whenever(isReceiptsEnabled()).thenReturn(true) + whenever(getWooCoreVersion()).thenReturn(null) + + // WHEN + val result = receiptSendingAvailable() + + // THEN + assertThat(result).isFalse + } + + @Test + fun `given receipts enabled and wooCoreVersion less than required, when invoked, then return false`() = runTest { + // GIVEN + whenever(isReceiptsEnabled()).thenReturn(true) + whenever(getWooCoreVersion()).thenReturn("9.4.0") + + // WHEN + val result = receiptSendingAvailable() + + // THEN + assertThat(result).isFalse + } + + @Test + fun `given receipts enabled and wooCoreVersion equal to required, when invoked, then return true`() = runTest { + // GIVEN + whenever(isReceiptsEnabled()).thenReturn(true) + whenever(getWooCoreVersion()).thenReturn("9.5.0") + + // WHEN + val result = receiptSendingAvailable() + + // THEN + assertThat(result).isTrue + } + + @Test + fun `given receipts enabled and wooCoreVersion greater than required, when invoked, then return true`() = runTest { + // GIVEN + whenever(isReceiptsEnabled()).thenReturn(true) + whenever(getWooCoreVersion()).thenReturn("9.6.0") + + // WHEN + val result = receiptSendingAvailable() + + // THEN + assertThat(result).isTrue + } +} From 0ca85b528e9d94ba22a0d7a9f5950067e4a7d979 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 27 Nov 2024 18:27:47 +0100 Subject: [PATCH 14/14] Add and fixed Totals VM tests --- .../home/totals/WooPosTotalsViewModelTest.kt | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 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 0e0ca69b379..37ddcd86d60 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 @@ -2,6 +2,7 @@ package com.woocommerce.android.ui.woopos.home.totals import androidx.arch.core.executor.testing.InstantTaskExecutorRule import androidx.lifecycle.SavedStateHandle +import com.woocommerce.android.R import com.woocommerce.android.model.Order import com.woocommerce.android.ui.woopos.cardreader.WooPosCardReaderFacade import com.woocommerce.android.ui.woopos.cardreader.WooPosCardReaderPaymentStatus @@ -61,7 +62,9 @@ class WooPosTotalsViewModelTest { on { paymentStatus }.thenReturn(MutableStateFlow(WooPosCardReaderPaymentStatus.Unknown)) } private val analyticsTracker: WooPosAnalyticsTracker = mock() - private val isReceiptSendingAvailable: WooPosIsReceiptSendingAvailable = mock() + private val isReceiptSendingAvailable: WooPosIsReceiptSendingAvailable = mock { + onBlocking { invoke() }.thenReturn(false) + } private companion object { private const val EMPTY_ORDER_ID = -1L @@ -537,7 +540,14 @@ class WooPosTotalsViewModelTest { val paymentStatusFlow = MutableStateFlow(WooPosCardReaderPaymentStatus.Unknown) whenever(cardReaderFacade.paymentStatus).thenReturn(paymentStatusFlow) + val resourceProvider: ResourceProvider = mock { + on { getString(R.string.woopos_success_screen_total, "$3.00") }.thenReturn( + "A payment of $3.00 was successfully made" + ) + } + val viewModel = createViewModel( + resourceProvider = resourceProvider, savedState = savedState, parentToChildrenEventReceiver = parentToChildrenEventReceiver, totalsRepository = totalsRepository, @@ -553,7 +563,7 @@ class WooPosTotalsViewModelTest { val state = viewModel.state.value assertThat(state).isEqualTo( WooPosTotalsViewState.PaymentSuccess( - orderTotalText = "$3.00", + orderTotalText = "A payment of $3.00 was successfully made", isReceiptAvailable = false, ) ) @@ -670,6 +680,25 @@ class WooPosTotalsViewModelTest { verify(cardReaderFacade, never()).collectPayment(any()) } + @Test + fun `when OnStartReceiptFlowClicked is triggered, then update state to ReceiptSending with empty email`() = runTest { + // GIVEN + val parentToChildrenEventReceiver: WooPosParentToChildrenEventReceiver = mock { + on { events }.thenReturn(mock()) + } + val savedState = createMockSavedStateHandle() + val viewModel = createViewModel( + savedState = savedState, + parentToChildrenEventReceiver = parentToChildrenEventReceiver, + ) + + // WHEN + viewModel.onUIEvent(WooPosTotalsUIEvent.OnStartReceiptFlowClicked) + + // THEN + assertThat(viewModel.state.value).isEqualTo(WooPosTotalsViewState.ReceiptSending(email = "")) + } + private fun createViewModel( resourceProvider: ResourceProvider = mock(), parentToChildrenEventReceiver: WooPosParentToChildrenEventReceiver = mock(),