Skip to content

Commit

Permalink
[MIT-1925] Fix app crash from progress view (#278)
Browse files Browse the repository at this point in the history
* fix: remove hide progress view

* test: add UI tests
  • Loading branch information
nuxzero authored Oct 9, 2023
1 parent 702174a commit 6700bfe
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.app.Activity
import android.app.Instrumentation
import android.content.Intent
import android.net.Uri
import androidx.arch.core.executor.testing.CountingTaskExecutorRule
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
Expand Down Expand Up @@ -44,6 +46,8 @@ import co.omise.android.utils.interceptActivityLifecycle
import co.omise.android.utils.loadHtml
import co.omise.android.utils.loadUrl
import co.omise.android.utils.withUrl
import com.netcetera.threeds.sdk.api.transaction.Transaction
import com.netcetera.threeds.sdk.api.ui.ProgressView
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.containsString
import org.junit.Assert.assertEquals
Expand All @@ -52,9 +56,13 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.any
import org.mockito.Mockito.mock
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import org.mockito.kotlin.doNothing
import org.mockito.kotlin.whenever
import java.util.concurrent.TimeUnit


@LargeTest
Expand All @@ -63,6 +71,9 @@ class AuthorizingPaymentActivityTest {
@get:Rule
val intentRule = IntentsRule()

@get:Rule
val countingTaskExecutorRule = CountingTaskExecutorRule()

private val authorizeUrl = "https://www.omise.co/pay"
private val returnUrl = "http://www.example.com"
private val deepLinkAuthorizeUrl = "bankapp://omise.co/authorize?return_uri=sampleapp://omise.co/authorize_return?result=success"
Expand All @@ -72,6 +83,8 @@ class AuthorizingPaymentActivityTest {
putExtra(EXTRA_EXPECTED_RETURN_URLSTRING_PATTERNS, arrayOf(returnUrl))
}

private val transaction: Transaction = mock()
private val progressView: ProgressView = mock()
private val mockViewModel: AuthorizingPaymentViewModel = mock()
private val viewModelFactory = object : ViewModelProvider.Factory {
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
Expand All @@ -92,6 +105,8 @@ class AuthorizingPaymentActivityTest {
whenever(mockViewModel.isLoading).thenReturn(isLoading)
whenever(mockViewModel.error).thenReturn(error)
whenever(mockViewModel.transactionStatus).thenReturn(transactionStatus)
whenever(mockViewModel.getTransaction()).thenReturn(transaction)
whenever(transaction.getProgressView(any())).thenReturn(progressView)
doNothing().whenever(mockViewModel).cleanup()

interceptActivityLifecycle { activity, _ ->
Expand Down Expand Up @@ -306,4 +321,26 @@ class AuthorizingPaymentActivityTest {
)
)
}

@Test
fun progressView_whenLoadingIsTrueThenShowProgressView() {
ActivityScenario.launchActivityForResult<AuthorizingPaymentActivity>(intent)

isLoading.postValue(true)
countingTaskExecutorRule.drainTasks(3, TimeUnit.SECONDS)

verify(progressView).showProgress()
}

@Test
fun progressView_whenLoadingIsFalseThenDoNothing() {
ActivityScenario.launchActivityForResult<AuthorizingPaymentActivity>(intent)

isLoading.postValue(false)
countingTaskExecutorRule.drainTasks(3, TimeUnit.SECONDS)

// Closing the transaction will also hide the progress view. So we don't need to call hideProgress() here.
verify(progressView, never()).showProgress()
verify(progressView, never()).hideProgress()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ class AuthorizingPaymentActivity : AppCompatActivity() {
}

viewModel.isLoading.observe(this) {
// Closing transaction will also hide the progress view.
// So, we only show the progress view.
if (it) {
viewModel.getTransaction().getProgressView(this).showProgress()
} else {
viewModel.getTransaction().getProgressView(this).hideProgress()
}
}

Expand Down

0 comments on commit 6700bfe

Please sign in to comment.