Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POS] Custom payment UI — Part 5 | Unit tests clean up #12943

Merged
merged 92 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 152 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
8676fe1
Add PaymentController test:
samiuelson Nov 18, 2024
662b0f2
Add PaymentController test:
samiuelson Nov 18, 2024
d5c8096
Add PaymentController test:
samiuelson Nov 18, 2024
e78c02e
Add PaymentController test:
samiuelson Nov 18, 2024
9086eba
Add PaymentController test:
samiuelson Nov 18, 2024
4a52038
Add PaymentController test:
samiuelson Nov 18, 2024
96d03b9
Add PaymentController test:
samiuelson Nov 18, 2024
647f459
Add PaymentController test:
samiuelson Nov 18, 2024
4aa8c79
Add PaymentController test:
samiuelson Nov 18, 2024
063f851
Add PaymentController test:
samiuelson Nov 18, 2024
178902e
Add PaymentController test:
samiuelson Nov 18, 2024
d919366
Move test from VM to PaymentController :
samiuelson Nov 18, 2024
6ad2c55
Add test PaymentController:
samiuelson Nov 18, 2024
7cfd275
Add test PaymentController:
samiuelson Nov 18, 2024
f623f5a
Move test from VM PaymentController:
samiuelson Nov 18, 2024
9e3791f
Move test from VM PaymentController:
samiuelson Nov 18, 2024
7ab0235
Add test to PaymentController:
samiuelson Nov 18, 2024
96daeae
Add test to PaymentController:
samiuelson Nov 18, 2024
24ad94d
Add test to PaymentController:
samiuelson Nov 18, 2024
faad942
Add test to PaymentController:
samiuelson Nov 18, 2024
c7094f0
Add test to PaymentController:
samiuelson Nov 18, 2024
27e2524
Move test from VM to PaymentController:
samiuelson Nov 18, 2024
f01dde9
Move test from VM to PaymentController:
samiuelson Nov 19, 2024
541f79a
Move test from VM to PaymentController:
samiuelson Nov 19, 2024
6381858
Move test from VM to PaymentController:
samiuelson Nov 19, 2024
c6f76bb
Move test from VM to PaymentController:
samiuelson Nov 19, 2024
bd7ad11
Move test from VM to PaymentController:
samiuelson Nov 19, 2024
78d8ec2
Add PaymentController test:
samiuelson Nov 19, 2024
e382e68
Add PaymentController test:
samiuelson Nov 19, 2024
46ae7cf
Add PaymentController test:
samiuelson Nov 19, 2024
5410953
Add PaymentController test:
samiuelson Nov 19, 2024
4c66bea
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
11a2aa4
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
b1c344b
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
c110229
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
204c773
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
36e6a17
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
93abe09
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
6733360
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
c2b00f9
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
7e19d9d
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
4a27284
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
a846931
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
c2df5dd
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
8c2c756
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
ca8c3b5
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
9936c7a
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
8f25805
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
ccc26d6
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
0f220ed
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
d8350a0
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
b7fc22b
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
dcbcfcd
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
7dcc66f
Rename vars
samiuelson Nov 20, 2024
6cb9005
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
de32048
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
bf56f5c
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
04b8b51
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
47328f6
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
c216f03
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
06fcf18
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
d1bc07b
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
22de1eb
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
eaad07b
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
c8af83c
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
8f49f5d
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
0d046e6
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
bcea393
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
3d10156
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
ff0ddaf
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
40b7495
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
fffefeb
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
615d2ae
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
adcd228
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
2e98afe
Move test from VM to `CardReaderPaymentController`:
samiuelson Nov 20, 2024
0529c00
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
43c1f96
Add `CardReaderPaymentController` test:
samiuelson Nov 20, 2024
7888538
Move tests to `CardReaderPaymentController`:
samiuelson Nov 25, 2024
88ceac1
Merge branch `trunk` into `custom-payment-ui-5`
samiuelson Nov 25, 2024
ff89241
Merge branch 'custom-payment-ui-4' into custom-payment-ui-5
samiuelson Nov 25, 2024
84687a5
Clean up code after merge
samiuelson Nov 25, 2024
4722dbd
Move tests from `CardReaderPaymentViewModelTest` to `CardReaderPaymen…
samiuelson Nov 25, 2024
2a6d9d3
Move tests from `CardReaderPaymentViewModelTest` to `CardReaderPaymen…
samiuelson Nov 25, 2024
21611e3
Move tests from `CardReaderPaymentViewModelTest` to `CardReaderPaymen…
samiuelson Nov 25, 2024
20568e8
Move tests from `CardReaderPaymentViewModelTest` to `CardReaderPaymen…
samiuelson Nov 25, 2024
455bd7e
Add `CardReaderPaymentController` test:
samiuelson Nov 25, 2024
08dd973
Move Interac flow tests to `CardReaderPaymentController`
samiuelson Nov 25, 2024
3cce3d1
Move tests to `CardReaderPaymentController`
samiuelson Nov 25, 2024
8648d46
Move tests to `CardReaderPaymentController`
samiuelson Nov 25, 2024
93c337e
Satisfy detekt's complaints
samiuelson Nov 25, 2024
00701ea
Merge branch 'feature/custom-payment-ui' into custom-payment-ui-5
samiuelson Nov 25, 2024
e9cd84d
Improve formatting
samiuelson Nov 27, 2024
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
@@ -0,0 +1,223 @@
package com.woocommerce.android.ui.payments.cardreader.payment

import com.woocommerce.android.R
import com.woocommerce.android.model.UiString
import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderType
import com.woocommerce.android.ui.payments.cardreader.payment.controller.CardReaderPaymentOrRefundState
import com.woocommerce.android.ui.payments.cardreader.payment.controller.CardReaderPaymentOrRefundState.CardReaderInteracRefundState
import com.woocommerce.android.ui.payments.cardreader.payment.controller.CardReaderPaymentOrRefundState.CardReaderPaymentState.CollectingPayment
import com.woocommerce.android.ui.payments.cardreader.payment.controller.CardReaderPaymentOrRefundState.CardReaderPaymentState.LoadingData
import com.woocommerce.android.ui.payments.cardreader.payment.controller.CardReaderPaymentOrRefundState.CardReaderPaymentState.PaymentCapturing
import com.woocommerce.android.ui.payments.cardreader.payment.controller.CardReaderPaymentOrRefundState.CardReaderPaymentState.PaymentFailed
import com.woocommerce.android.ui.payments.cardreader.payment.controller.CardReaderPaymentOrRefundState.CardReaderPaymentState.PaymentSuccessful
import com.woocommerce.android.ui.payments.cardreader.payment.controller.CardReaderPaymentOrRefundState.CardReaderPaymentState.PrintingReceipt
import com.woocommerce.android.ui.payments.cardreader.payment.controller.CardReaderPaymentOrRefundState.CardReaderPaymentState.ProcessingPayment
import com.woocommerce.android.ui.payments.cardreader.payment.controller.CardReaderPaymentOrRefundState.CardReaderPaymentState.ReFetchingOrder
import com.woocommerce.android.ui.payments.cardreader.payment.controller.CardReaderPaymentOrRefundState.CardReaderPaymentState.SharingReceipt
import javax.inject.Inject

class CardReaderPaymentStateToViewStateMapper @Inject constructor(
private val cardReaderPaymentReaderTypeStateProvider: CardReaderPaymentReaderTypeStateProvider,
) {
@Suppress("LongMethod", "CyclomaticComplexMethod")
operator fun invoke(): (CardReaderPaymentOrRefundState) -> ViewState = { paymentState ->
when (paymentState) {
is CardReaderInteracRefundState.CollectingInteracRefund -> {
ViewState.CollectRefundState(
amountWithCurrencyLabel = paymentState.amountWithCurrencyLabel,
onSecondaryActionClicked = paymentState.onCancel,
hintLabel = paymentState.cardReaderHint
?: R.string.card_reader_interac_refund_refund_payment_hint,
)
}
is CardReaderInteracRefundState.InteracRefundFailure -> {
if (paymentState.onRetry == null) {
if (paymentState.cta != null) {
ViewState.FailedRefundState(
errorType = paymentState.errorType,
amountWithCurrencyLabel = paymentState.amountWithCurrencyLabel,
primaryLabel = paymentState.cta.label,
onPrimaryActionClicked = paymentState.cta.onCallToActionTapped,
secondaryLabel = R.string.cancel,
onSecondaryActionClicked = paymentState.onCancel,
)
} else {
ViewState.FailedRefundState(
errorType = paymentState.errorType,
amountWithCurrencyLabel = paymentState.amountWithCurrencyLabel,
primaryLabel = R.string.card_reader_interac_refund_refund_failed_ok,
onPrimaryActionClicked = paymentState.onCancel!!,
)
}
} else {
ViewState.FailedRefundState(
errorType = paymentState.errorType,
amountWithCurrencyLabel = paymentState.amountWithCurrencyLabel,
primaryLabel = R.string.try_again,
onPrimaryActionClicked = paymentState.onRetry,
secondaryLabel = R.string.cancel,
onSecondaryActionClicked = paymentState.onCancel,
)
}
}

is CardReaderInteracRefundState.InteracRefundSuccessful -> {
ViewState.RefundSuccessfulState(paymentState.amountWithCurrencyLabel)
}
is CardReaderInteracRefundState.LoadingData -> {
ViewState.RefundLoadingDataState(paymentState.onCancel)
}
is CardReaderInteracRefundState.ProcessingInteracRefund -> {
ViewState.ProcessingRefundState(paymentState.amountWithCurrencyLabel)
}
is CollectingPayment.BuiltInReaderCollectPaymentState -> {
ViewState.BuiltInReaderCollectPaymentState(
amountWithCurrencyLabel = paymentState.amountWithCurrencyLabel,
hintLabel = paymentState.cardReaderHint
?: R.string.card_reader_payment_collect_payment_built_in_hint
)
}

is CollectingPayment.ExternalReaderCollectPaymentState -> {
ViewState.ExternalReaderCollectPaymentState(
amountWithCurrencyLabel = paymentState.amountWithCurrencyLabel,
hintLabel = paymentState.cardReaderHint
?: R.string.card_reader_payment_collect_payment_hint,
onSecondaryActionClicked = paymentState.onCancel
)
}
is LoadingData -> ViewState.LoadingDataState(paymentState.onCancel)
is PaymentCapturing.BuiltInReaderPaymentCapturing -> {
ViewState.BuiltInReaderCapturingPaymentState(
amountWithCurrencyLabel = paymentState.amountWithCurrencyLabel,
)
}
is PaymentCapturing.ExternalReaderPaymentCapturing -> {
ViewState.ExternalReaderCapturingPaymentState(
amountWithCurrencyLabel = paymentState.amountWithCurrencyLabel,
)
}
is PaymentFailed.BuiltInReaderFailedPayment -> {
if (paymentState.cta != null) {
cardReaderPaymentReaderTypeStateProvider.provideFailedPaymentState(
cardReaderType = CardReaderType.BUILT_IN,
errorType = paymentState.errorType,
amountLabel = paymentState.amountWithCurrencyLabel,
primaryLabel = paymentState.cta.label,
onPrimaryActionClicked = paymentState.cta.onCallToActionTapped,
secondaryLabel = R.string.cancel,
onSecondaryActionClicked = paymentState.onCancel,
)
} else {
if (paymentState.onRetry != null) {
cardReaderPaymentReaderTypeStateProvider.provideFailedPaymentState(
cardReaderType = CardReaderType.BUILT_IN,
errorType = paymentState.errorType,
amountLabel = paymentState.amountWithCurrencyLabel,
primaryLabel = R.string.try_again,
onPrimaryActionClicked = paymentState.onRetry,
onSecondaryActionClicked = paymentState.onCancel,
secondaryLabel = R.string.cancel,
)
} else {
cardReaderPaymentReaderTypeStateProvider.provideFailedPaymentState(
cardReaderType = CardReaderType.BUILT_IN,
errorType = paymentState.errorType,
amountLabel = paymentState.amountWithCurrencyLabel,
primaryLabel = R.string.card_reader_payment_payment_failed_ok,
onPrimaryActionClicked = paymentState.onCancel!!,
)
}
}
}
is PaymentFailed.ExternalReaderFailedPayment -> {
if (paymentState.cta != null) {
cardReaderPaymentReaderTypeStateProvider.provideFailedPaymentState(
cardReaderType = CardReaderType.EXTERNAL,
errorType = paymentState.errorType,
amountLabel = paymentState.amountWithCurrencyLabel,
primaryLabel = paymentState.cta.label,
onPrimaryActionClicked = paymentState.cta.onCallToActionTapped,
secondaryLabel = R.string.cancel,
onSecondaryActionClicked = paymentState.onCancel,
)
} else {
if (paymentState.onRetry != null) {
cardReaderPaymentReaderTypeStateProvider.provideFailedPaymentState(
cardReaderType = CardReaderType.EXTERNAL,
errorType = paymentState.errorType,
amountLabel = paymentState.amountWithCurrencyLabel,
primaryLabel = R.string.try_again,
onPrimaryActionClicked = paymentState.onRetry,
secondaryLabel = R.string.cancel,
onSecondaryActionClicked = paymentState.onCancel,
)
} else {
cardReaderPaymentReaderTypeStateProvider.provideFailedPaymentState(
cardReaderType = CardReaderType.EXTERNAL,
errorType = paymentState.errorType,
amountLabel = paymentState.amountWithCurrencyLabel,
primaryLabel = R.string.card_reader_payment_payment_failed_ok,
onPrimaryActionClicked = paymentState.onCancel!!,
)
}
}
}
is PaymentSuccessful.BuiltInReaderPaymentSuccessful -> {
ViewState.BuiltInReaderPaymentSuccessfulState(
amountWithCurrencyLabel = paymentState.amountWithCurrencyLabel,
onPrimaryActionClicked = paymentState.onPrintReceiptClicked,
onSecondaryActionClicked = paymentState.onSendReceiptClicked,
onTertiaryActionClicked = paymentState.onSaveUserClicked,
)
}
is PaymentSuccessful.BuiltInReaderPaymentSuccessfulReceiptSentAutomatically -> {
val receiptSentHint = UiString.UiStringRes(
R.string.card_reader_payment_reader_receipt_sent,
listOf(UiString.UiStringText(paymentState.recipientEmail)),
true
)
ViewState.BuiltInReaderPaymentSuccessfulReceiptSentAutomaticallyState(
amountWithCurrencyLabel = paymentState.amountWithCurrencyLabel,
receiptSentAutomaticallyHint = receiptSentHint,
onPrimaryActionClicked = paymentState.onPrintReceiptClicked,
onTertiaryActionClicked = paymentState.onSaveUserClicked,
)
}
is PaymentSuccessful.ExternalReaderPaymentSuccessful -> {
ViewState.ExternalReaderPaymentSuccessfulState(
amountWithCurrencyLabel = paymentState.amountWithCurrencyLabel,
onPrimaryActionClicked = paymentState.onPrintReceiptClicked,
onSecondaryActionClicked = paymentState.onSendReceiptClicked,
onTertiaryActionClicked = paymentState.onSaveUserClicked,
)
}
is PaymentSuccessful.ExternalReaderPaymentSuccessfulReceiptSentAutomatically -> {
val receiptSentHint = UiString.UiStringRes(
R.string.card_reader_payment_reader_receipt_sent,
listOf(UiString.UiStringText(paymentState.recipientEmail)),
true
)
cardReaderPaymentReaderTypeStateProvider.providePaymentSuccessfulReceiptSentAutomaticallyState(
cardReaderType = CardReaderType.EXTERNAL,
amountLabel = paymentState.amountWithCurrencyLabel,
receiptSentHint = receiptSentHint,
onSaveUserClicked = paymentState.onSaveUserClicked,
onPrintReceiptClicked = paymentState.onPrintReceiptClicked,
)
}
is PrintingReceipt -> ViewState.PrintingReceiptState(paymentState.amountWithCurrencyLabel)
is ProcessingPayment.BuiltInReaderProcessingPayment -> {
ViewState.BuiltInReaderProcessingPaymentState(paymentState.amountWithCurrencyLabel)
}
is ProcessingPayment.ExternalReaderProcessingPayment -> {
ViewState.ExternalReaderProcessingPaymentState(
amountWithCurrencyLabel = paymentState.amountWithCurrencyLabel,
onSecondaryActionClicked = paymentState.onCancel
)
}
ReFetchingOrder -> ViewState.ReFetchingOrderState
SharingReceipt -> ViewState.SharingReceiptState
}
}
}
Loading
Loading