Skip to content

Commit

Permalink
Merge branch 'voucher-error-not-removed-when-changing-input-droid-545'
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Jan 4, 2024
2 parents aa98204 + 57d3634 commit d081fab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class VoucherDialogViewModel(
}

fun onVoucherInputChange(voucherString: String) {
// Remove any errors when the user starts typing again
vmState.update { VoucherDialogState.Default }
if (VoucherRegexHelper.validate(voucherString)) {
val trimmedVoucher = VoucherRegexHelper.trim(voucherString)
voucherInput.value =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,31 @@ class VoucherDialogViewModelTest {
}
}

@Test
fun testResetStateAfterChangingInput() = runTest {
val voucher = DUMMY_INVALID_VOUCHER
val dummyStringResource = DUMMY_STRING_RESOURCE

// Arrange
every { mockServiceConnectionManager.voucherRedeemer() } returns mockVoucherRedeemer
every { mockResources.getString(any()) } returns dummyStringResource
every { mockVoucherSubmission.timeAdded } returns 0
coEvery { mockVoucherRedeemer.submit(voucher) } returns
VoucherSubmissionResult.Error(VoucherSubmissionError.OtherError)

// Act, Assert
viewModel.uiState.test {
assertEquals(viewModel.uiState.value, awaitItem())
serviceConnectionState.value =
ServiceConnectionState.ConnectedReady(mockServiceConnectionContainer)
viewModel.onRedeem(voucher)
assertTrue { awaitItem().voucherViewModelState is VoucherDialogState.Verifying }
assertTrue { awaitItem().voucherViewModelState is VoucherDialogState.Error }
viewModel.onVoucherInputChange(DUMMY_VALID_VOUCHER)
assertTrue { awaitItem().voucherViewModelState is VoucherDialogState.Default }
}
}

companion object {
private const val DUMMY_VALID_VOUCHER = "dummy_valid_voucher"
private const val DUMMY_INVALID_VOUCHER = "dummy_invalid_voucher"
Expand Down

0 comments on commit d081fab

Please sign in to comment.