From d5c80960a86c1748e6cc43be0d577a1567bbd1fb Mon Sep 17 00:00:00 2001 From: samiuelson Date: Mon, 18 Nov 2024 19:00:42 +0100 Subject: [PATCH] Add PaymentController test: `given collect payment shown, when SWIPE_CARD received, then collect payment hint updated` --- .../CardReaderPaymentControllerTest.kt | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/controller/CardReaderPaymentControllerTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/controller/CardReaderPaymentControllerTest.kt index c2e3fad8585..98ec3c00299 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/controller/CardReaderPaymentControllerTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/payments/cardreader/payment/controller/CardReaderPaymentControllerTest.kt @@ -8,6 +8,8 @@ import com.woocommerce.android.cardreader.connection.event.BluetoothCardReaderMe import com.woocommerce.android.cardreader.connection.event.CardReaderBatteryStatus import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType.INSERT_CARD +import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType.INSERT_OR_SWIPE_CARD +import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType.SWIPE_CARD import com.woocommerce.android.cardreader.payments.CardPaymentStatus.CollectingPayment import com.woocommerce.android.model.Address import com.woocommerce.android.model.Order @@ -182,6 +184,44 @@ class CardReaderPaymentControllerTest : BaseUnitTest() { .isEqualTo(R.string.card_reader_payment_collect_payment_hint) } + @Test + fun `given collect payment shown, when INSERT_OR_SWIPE_CARD received, then collect payment hint updated`() = + testBlocking { + whenever(cardReaderManager.displayBluetoothCardReaderMessages).thenAnswer { + flow { + emit(BluetoothCardReaderMessages.CardReaderDisplayMessage(INSERT_OR_SWIPE_CARD)) + } + } + + whenever(cardReaderManager.collectPayment(any())).thenAnswer { + flow { emit(CollectingPayment) } + } + + controller.start() + + assertThat((controller.paymentState.value as CardReaderPaymentState.CollectingPayment).cardReaderHint) + .isEqualTo(R.string.card_reader_payment_collect_payment_hint) + } + + @Test + fun `given collect payment shown, when SWIPE_CARD received, then collect payment hint updated`() = + testBlocking { + whenever(cardReaderManager.displayBluetoothCardReaderMessages).thenAnswer { + flow { + emit(BluetoothCardReaderMessages.CardReaderDisplayMessage(SWIPE_CARD)) + } + } + + whenever(cardReaderManager.collectPayment(any())).thenAnswer { + flow { emit(CollectingPayment) } + } + + controller.start() + + assertThat((controller.paymentState.value as CardReaderPaymentState.CollectingPayment).cardReaderHint) + .isEqualTo(R.string.card_reader_payment_collect_payment_hint) + } + companion object { private const val ORDER_ID = 1L private val siteModel = SiteModel().apply { name = "testName" }.apply { url = "testUrl.com" }