Skip to content

Commit

Permalink
Merge branch 'feature/MIT-1760-poc-netcetera-3ds-sdk' into feature/MI…
Browse files Browse the repository at this point in the history
…T-1759-ui-cutomization-configuration
  • Loading branch information
nuxzero committed Oct 10, 2023
2 parents 7fd0702 + 6700bfe commit 27ec921
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
Expand Down Expand Up @@ -44,6 +45,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,8 +55,12 @@ 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.whenever
import java.util.concurrent.TimeUnit


@LargeTest
Expand All @@ -62,6 +69,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 @@ -71,6 +81,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 @@ -91,6 +103,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)

interceptActivityLifecycle { activity, _ ->
(activity as? AuthorizingPaymentActivity)?.setViewModelFactory(viewModelFactory)
Expand Down Expand Up @@ -304,4 +318,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 @@ -82,10 +82,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 27ec921

Please sign in to comment.