Updated on 2026-08-14
This commit is contained in:
parent
12e53a3aa3
commit
315d7c9d6c
25 changed files with 482 additions and 321 deletions
|
|
@ -1,66 +1,77 @@
|
|||
package com.tangem.common
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||
import androidx.datastore.dataStoreFile
|
||||
import androidx.test.espresso.intent.Intents
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.rule.GrantPermissionRule
|
||||
import com.atiurin.ultron.core.compose.config.UltronComposeConfig
|
||||
import com.atiurin.ultron.core.compose.createUltronComposeRule
|
||||
import com.atiurin.ultron.core.compose.listeners.ComposDebugListener
|
||||
import com.atiurin.ultron.core.config.UltronCommonConfig
|
||||
import com.atiurin.ultron.core.config.UltronConfig
|
||||
import com.atiurin.ultron.core.test.UltronTest
|
||||
import com.kaspersky.components.composesupport.config.withComposeSupport
|
||||
import com.kaspersky.kaspresso.kaspresso.Kaspresso
|
||||
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
|
||||
import com.tangem.datasource.local.preferences.AppPreferencesStore
|
||||
import com.tangem.sdk.api.TangemSdkManager
|
||||
import com.tangem.tap.MainActivity
|
||||
import dagger.hilt.android.testing.HiltAndroidRule
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.Rule
|
||||
import org.junit.rules.RuleChain
|
||||
import org.junit.rules.TestRule
|
||||
import org.junit.runner.RunWith
|
||||
import javax.inject.Inject
|
||||
|
||||
abstract class BaseTestCase : UltronTest() {
|
||||
abstract class BaseTestCase : TestCase(
|
||||
kaspressoBuilder = Kaspresso.Builder.withComposeSupport()
|
||||
) {
|
||||
|
||||
@Inject
|
||||
lateinit var tangemSdkManager: TangemSdkManager
|
||||
|
||||
@Inject
|
||||
lateinit var appPreferencesStore: AppPreferencesStore
|
||||
|
||||
@get:Rule(order = 0)
|
||||
val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(
|
||||
private val hiltRule = HiltAndroidRule(this)
|
||||
private val permissionRule = GrantPermissionRule.grant(
|
||||
Manifest.permission.POST_NOTIFICATIONS,
|
||||
Manifest.permission.CAMERA
|
||||
Manifest.permission.CAMERA,
|
||||
)
|
||||
@get:Rule(order = 1)
|
||||
val hiltRule = HiltAndroidRule(this)
|
||||
val composeTestRule = createAndroidComposeRule<MainActivity>()
|
||||
|
||||
@get:Rule (order = 2)
|
||||
val injectionRule = ApplicationInjectionExecutionRule()
|
||||
@Rule
|
||||
@JvmField
|
||||
val ruleChain: TestRule = RuleChain
|
||||
.outerRule(hiltRule)
|
||||
.around(ApplicationInjectionExecutionRule())
|
||||
.around(permissionRule)
|
||||
.around(composeTestRule)
|
||||
|
||||
@get:Rule(order = 3)
|
||||
val composeRule = createUltronComposeRule<MainActivity>()
|
||||
|
||||
override val beforeTest: () -> Unit = {
|
||||
protected fun setupHooks(
|
||||
additionalBeforeSection: () -> Unit = {},
|
||||
additionalAfterSection: () -> Unit = {},
|
||||
) = before {
|
||||
hiltRule.inject()
|
||||
Intents.init()
|
||||
additionalBeforeSection()
|
||||
|
||||
runBlocking {
|
||||
delay(INIT_DELAY)
|
||||
}
|
||||
}
|
||||
|
||||
override val afterTest: () -> Unit = {
|
||||
}.after {
|
||||
runBlocking {
|
||||
appPreferencesStore.editData { prefs -> prefs.clear() }
|
||||
}
|
||||
|
||||
additionalAfterSection()
|
||||
Intents.release()
|
||||
}
|
||||
|
||||
companion object {
|
||||
@BeforeClass
|
||||
@JvmStatic
|
||||
fun config() {
|
||||
UltronConfig.applyRecommended()
|
||||
UltronComposeConfig.applyRecommended()
|
||||
UltronCommonConfig.addListener(ComposDebugListener())
|
||||
}
|
||||
|
||||
private const val INIT_DELAY = 2000L
|
||||
private const val INIT_DELAY = 1000L
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue