From 96d03b9f9bbd5368cbb9f0a239ae4b225f24319a Mon Sep 17 00:00:00 2001 From: samiuelson Date: Mon, 18 Nov 2024 19:24:07 +0100 Subject: [PATCH] Add PaymentController test: `given collect payment shown, when TRY_OTHER_READ message received, then collect payment hint updated` --- .../CardReaderPaymentControllerTest.kt | 22 +++++++++++++++++++ 1 file changed, 22 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 856518023ce..5e67c1ae4c6 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 @@ -13,6 +13,7 @@ import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalI import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType.REMOVE_CARD import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType.SWIPE_CARD import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType.TRY_ANOTHER_CARD +import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType.TRY_ANOTHER_READ_METHOD import com.woocommerce.android.cardreader.payments.CardPaymentStatus.CollectingPayment import com.woocommerce.android.model.Address import com.woocommerce.android.model.Order @@ -288,6 +289,27 @@ class CardReaderPaymentControllerTest : BaseUnitTest() { .isEqualTo(R.string.card_reader_payment_card_removed_too_early) } + @Test + fun `given collect payment shown, when TRY_OTHER_READ message received, then collect payment hint updated`() = + testBlocking { + whenever(cardReaderManager.displayBluetoothCardReaderMessages).thenAnswer { + flow { + delay(1) // make sure it's run after collecting payment starts + emit(BluetoothCardReaderMessages.CardReaderDisplayMessage(TRY_ANOTHER_READ_METHOD)) + } + } + + whenever(cardReaderManager.collectPayment(any())).thenAnswer { + flow { emit(CollectingPayment) } + } + + controller.start() + advanceUntilIdle() + + assertThat((controller.paymentState.value as CardReaderPaymentState.CollectingPayment).cardReaderHint) + .isEqualTo(R.string.card_reader_payment_try_another_read_method_prompt) + } + companion object { private const val ORDER_ID = 1L private val siteModel = SiteModel().apply { name = "testName" }.apply { url = "testUrl.com" }