Skip to content

Commit

Permalink
refactor(capture-sdk): Fix tests related to help screens
Browse files Browse the repository at this point in the history
BSDK-258
  • Loading branch information
a-szotyori committed Jan 12, 2024
1 parent 21f7c42 commit fc301cc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,4 @@ class CameraActivityTest {
}
}

@Test
fun `triggers Help event when help was started`() {
// Given
val eventTracker = spy<EventTracker>()
GiniCapture.Builder().setEventTracker(eventTracker).build()

ActivityScenario.launch(CameraActivity::class.java).use { scenario ->
scenario.moveToState(Lifecycle.State.STARTED)

// When
scenario.onActivity { activity ->
val menuItem = mock<MenuItem>()
whenever(menuItem.itemId).thenReturn(R.id.gc_action_show_onboarding)
activity.onOptionsItemSelected(menuItem)

// Then
verify(eventTracker).onCameraScreenEvent(Event(CameraScreenEvent.HELP))
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package net.gini.android.capture.camera

import android.app.Activity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.google.common.truth.Truth
import com.nhaarman.mockitokotlin2.*
import jersey.repackaged.jsr166e.CompletableFuture
import net.gini.android.capture.Amount
import net.gini.android.capture.GiniCapture
import net.gini.android.capture.GiniCaptureError
import net.gini.android.capture.GiniCaptureHelper
import net.gini.android.capture.internal.camera.api.CameraInterface
import net.gini.android.capture.internal.ui.FragmentImplCallback
import net.gini.android.capture.tracking.CameraScreenEvent
import net.gini.android.capture.tracking.Event
import net.gini.android.capture.tracking.EventTracker
import org.junit.After
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito
Expand Down Expand Up @@ -70,4 +71,49 @@ class CameraFragmentImplTest {
Truth.assertThat(args.firstValue.errorCode)
.isEqualTo(GiniCaptureError.ErrorCode.MISSING_GINI_CAPTURE_INSTANCE)
}

@Test
fun `triggers Help event when help was started`() {
// Given
val eventTracker = spy<EventTracker>()
GiniCapture.Builder().setEventTracker(eventTracker).build()

// Stub the fragment transaction related calls
val fragmentCallbackStub = mock<FragmentImplCallback>()
whenever(fragmentCallbackStub.childFragmentManager).thenReturn(object: FragmentManager() {
override fun beginTransaction(): FragmentTransaction {
return object: FragmentTransaction() {
override fun add(containerViewId: Int, fragment: Fragment, tag: String?): FragmentTransaction {
return this;
}

override fun addToBackStack(name: String?): FragmentTransaction {
return this
}

override fun commit(): Int {
return 0
}

override fun commitAllowingStateLoss(): Int {
return 0
}

override fun commitNow() {
}

override fun commitNowAllowingStateLoss() {
}
}
}
})

val fragmentImpl = CameraFragmentImpl(fragmentCallbackStub)

// When
fragmentImpl.startHelpActivity()

// Then
verify(eventTracker).onCameraScreenEvent(Event(CameraScreenEvent.HELP))
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package net.gini.android.capture.help

import android.content.Intent
import androidx.fragment.app.testing.launchFragment
import androidx.fragment.app.testing.launchFragmentInContainer
import androidx.test.core.app.launchActivity
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
Expand Down Expand Up @@ -44,7 +46,7 @@ class HelpActivityTest {
.build()

// When
launchActivity<HelpActivity>().use {
launchFragmentInContainer<HelpFragment>(themeResId = R.style.GiniCaptureTheme).use {
// Then
onView(ViewMatchers.withText(customTitle)).check(matches(isDisplayed()))
}
Expand Down Expand Up @@ -73,7 +75,7 @@ class HelpActivityTest {
// When
Intents.init()

launchActivity<HelpActivity>().use {
launchFragmentInContainer<HelpFragment>(themeResId = R.style.GiniCaptureTheme).use {
// Then
onView(ViewMatchers.withText(customTitle)).perform(click())

Expand Down

0 comments on commit fc301cc

Please sign in to comment.