Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zwarm committed Feb 1, 2024
1 parent cd99536 commit 175ab13
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import org.wordpress.android.fluxc.store.qrcodeauth.QRCodeAuthStore
import org.wordpress.android.fluxc.store.qrcodeauth.QRCodeAuthStore.QRCodeAuthAuthenticateResult
import org.wordpress.android.fluxc.store.qrcodeauth.QRCodeAuthStore.QRCodeAuthResult
import org.wordpress.android.fluxc.store.qrcodeauth.QRCodeAuthStore.QRCodeAuthValidateResult
import org.wordpress.android.ui.barcodescanner.BarcodeScanningTracker
import org.wordpress.android.ui.barcodescanner.CodeScannerStatus
import org.wordpress.android.ui.barcodescanner.CodeScanningErrorType
import org.wordpress.android.ui.barcodescanner.ScanningSource
import org.wordpress.android.ui.posts.BasicDialogViewModel.DialogInteraction
import org.wordpress.android.ui.qrcodeauth.QRCodeAuthUiState.Content.Done
import org.wordpress.android.ui.qrcodeauth.QRCodeAuthUiState.Content.Validated
Expand Down Expand Up @@ -80,6 +84,9 @@ class QRCodeAuthViewModelTest : BaseUnitTest() {
@Mock
lateinit var analyticsTrackerWrapper: AnalyticsTrackerWrapper

@Mock
lateinit var barcodeScanningTracker: BarcodeScanningTracker

private val uiStateMapper = QRCodeAuthUiStateMapper()

private val validQueryParams = mapOf(DATA_KEY to DATA, TOKEN_KEY to TOKEN)
Expand All @@ -89,14 +96,17 @@ class QRCodeAuthViewModelTest : BaseUnitTest() {
private val errorTrackingMapAuthFailed = mutableMapOf("error" to "authentication_failed", "origin" to "menu")
private val errorTrackingMapExpiredToken = mutableMapOf("error" to "expired_token", "origin" to "menu")

private val failureStatus = CodeScannerStatus.Failure("Failure", CodeScanningErrorType.Unknown)

@Before
fun setUp() {
viewModel = QRCodeAuthViewModel(
store,
uiStateMapper,
networkUtilsWrapper,
validator,
analyticsTrackerWrapper
analyticsTrackerWrapper,
barcodeScanningTracker
)

whenever(networkUtilsWrapper.isNetworkAvailable()).thenReturn(true)
Expand Down Expand Up @@ -198,6 +208,8 @@ class QRCodeAuthViewModelTest : BaseUnitTest() {
viewModel.start()
viewModel.onScanSuccess(SCANNED_VALUE)

verify(barcodeScanningTracker).trackSuccess(ScanningSource.QRCODE_LOGIN)

verify(analyticsTrackerWrapper).track(eq(QRLOGIN_VERIFY_FAILED), eq(errorTrackingMapInvalidData))
}
}
Expand Down Expand Up @@ -510,12 +522,22 @@ class QRCodeAuthViewModelTest : BaseUnitTest() {
fun `when scan fails, then finish activity event is raised`() {
val actionEvents = mutableListOf<QRCodeAuthActionEvent>()
testWithData(actionEvents = actionEvents) {
viewModel.onScanFailure()
viewModel.onScanFailure(failureStatus)

assertThat(actionEvents.last()).isInstanceOf(QRCodeAuthActionEvent.FinishActivity::class.java)
}
}

@Test
fun `when scan fails, then scan failed is tracked`() {
val actionEvents = mutableListOf<QRCodeAuthActionEvent>()
testWithData(actionEvents = actionEvents) {
viewModel.onScanFailure(failureStatus)

verify(barcodeScanningTracker).trackScanFailure(ScanningSource.QRCODE_LOGIN, failureStatus.type)
}
}

@Test
fun `given valid scan, when no network connection, then no internet error is shown`() {
val uiStates = mutableListOf<QRCodeAuthUiState>()
Expand Down

0 comments on commit 175ab13

Please sign in to comment.