diff --git a/app/src/test/java/app/pachli/components/compose/ComposeActivityTest.kt b/app/src/test/java/app/pachli/components/compose/ComposeActivityTest.kt index 34034b060..6a0c923a8 100644 --- a/app/src/test/java/app/pachli/components/compose/ComposeActivityTest.kt +++ b/app/src/test/java/app/pachli/components/compose/ComposeActivityTest.kt @@ -26,6 +26,7 @@ import app.pachli.core.data.model.InstanceInfo.Companion.DEFAULT_CHARACTERS_RESE import app.pachli.core.data.model.InstanceInfo.Companion.DEFAULT_CHARACTER_LIMIT import app.pachli.core.data.repository.AccountManager import app.pachli.core.data.repository.InstanceInfoRepository +import app.pachli.core.database.AppDatabase import app.pachli.core.navigation.ComposeActivityIntent import app.pachli.core.navigation.ComposeActivityIntent.ComposeOptions import app.pachli.core.network.model.Account @@ -55,10 +56,12 @@ import kotlin.properties.Delegates import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.runTest +import org.junit.After import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Before +import org.junit.Ignore import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -76,6 +79,11 @@ open class PachliHiltApplication : PachliApplication() @CustomTestApplication(PachliHiltApplication::class) interface HiltTestApplication +// Temporarily ignore these tests. They're flaky because the current +// implementation of ComposeActivity/ViewModel does not make it possible to +// proceed with the test once the ViewModel has finished loading data and +// the UI is set up. +@Ignore("see comment") @HiltAndroidTest @Config(application = HiltTestApplication_Application::class) @RunWith(AndroidJUnit4::class) @@ -83,7 +91,7 @@ class ComposeActivityTest { @get:Rule(order = 0) var hilt = HiltAndroidRule(this) - val dispatcher = StandardTestDispatcher() + private val dispatcher = StandardTestDispatcher() @get:Rule(order = 1) val mainCoroutineRule = MainCoroutineRule(dispatcher) @@ -107,6 +115,9 @@ class ComposeActivityTest { @Inject lateinit var instanceInfoRepository: InstanceInfoRepository + @Inject + lateinit var db: AppDatabase + private var pachliAccountId by Delegates.notNull() val account = Account( @@ -125,6 +136,8 @@ class ComposeActivityTest { fun setup() = runTest { hilt.inject() + db.clearAllTables() + getInstanceCallback = null reset(mastodonApi) mastodonApi.stub { @@ -178,6 +191,9 @@ class ComposeActivityTest { .get()!!.id } + @After + fun closeDb() = db.close() + /** * When tests do something like this (lines marked "->") * diff --git a/core/data/src/test/kotlin/app/pachli/core/data/repository/InstanceInfoRepositoryTest.kt b/core/data/src/test/kotlin/app/pachli/core/data/repository/InstanceInfoRepositoryTest.kt index 2ba69220c..a846a0dd6 100644 --- a/core/data/src/test/kotlin/app/pachli/core/data/repository/InstanceInfoRepositoryTest.kt +++ b/core/data/src/test/kotlin/app/pachli/core/data/repository/InstanceInfoRepositoryTest.kt @@ -125,7 +125,6 @@ class InstanceInfoRepositoryTest { onBlocking { getContentFilters() } doReturn success(emptyList()) onBlocking { getContentFiltersV1() } doReturn success(emptyList()) onBlocking { accountFollowing(any(), anyOrNull(), any()) } doReturn success(emptyList()) - onBlocking { accountFollowing(any(), anyOrNull(), any()) } doReturn success(emptyList()) } reset(nodeInfoApi)