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 6894b2e1bac..856518023ce 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 @@ -7,6 +7,7 @@ import com.woocommerce.android.cardreader.connection.CardReaderStatus import com.woocommerce.android.cardreader.connection.event.BluetoothCardReaderMessages import com.woocommerce.android.cardreader.connection.event.CardReaderBatteryStatus import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType +import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType.CARD_REMOVED_TOO_EARLY 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.REMOVE_CARD @@ -266,6 +267,27 @@ class CardReaderPaymentControllerTest : BaseUnitTest() { .isEqualTo(R.string.card_reader_payment_try_another_card_prompt) } + @Test + fun `given collect payment shown, when CARD_REMOVED_TOO_EARLY message received, then collect payment hint updated`() = + testBlocking { + whenever(cardReaderManager.displayBluetoothCardReaderMessages).thenAnswer { + flow { + delay(1) // make sure it runs after collecting payment starts + emit(BluetoothCardReaderMessages.CardReaderDisplayMessage(CARD_REMOVED_TOO_EARLY)) + } + } + + 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_card_removed_too_early) + } + companion object { private const val ORDER_ID = 1L private val siteModel = SiteModel().apply { name = "testName" }.apply { url = "testUrl.com" }