Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nikclayton committed Nov 24, 2024
1 parent 6a3e88c commit d80ae49
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -76,14 +79,19 @@ 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)
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)
Expand All @@ -107,6 +115,9 @@ class ComposeActivityTest {
@Inject
lateinit var instanceInfoRepository: InstanceInfoRepository

@Inject
lateinit var db: AppDatabase

private var pachliAccountId by Delegates.notNull<Long>()

val account = Account(
Expand All @@ -125,6 +136,8 @@ class ComposeActivityTest {
fun setup() = runTest {
hilt.inject()

db.clearAllTables()

getInstanceCallback = null
reset(mastodonApi)
mastodonApi.stub {
Expand Down Expand Up @@ -178,6 +191,9 @@ class ComposeActivityTest {
.get()!!.id
}

@After
fun closeDb() = db.close()

/**
* When tests do something like this (lines marked "->")
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d80ae49

Please sign in to comment.