add tests for paged loading components

This commit is contained in:
2025-03-02 23:06:42 +06:00
parent 3b7dde3cb1
commit e70d34d91a
4 changed files with 169 additions and 28 deletions

View File

@@ -0,0 +1,47 @@
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.runComposeUiTest
import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.pagination.compose.InfinityPagedComponent
import dev.inmo.micro_utils.pagination.compose.PagedComponent
import org.jetbrains.annotations.TestOnly
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
class InfinityPagedComponentTests {
@OptIn(ExperimentalTestApi::class)
@Test
@TestOnly
fun testSimpleLoad() = runComposeUiTest {
var expectedList = listOf<Int>()
setContent {
InfinityPagedComponent<Int>(
size = 1,
loader = {
PaginationResult(
page = it.page,
size = it.size,
results = (it.firstIndex .. it.lastIndex).toList(),
objectsNumber = 3
).also {
expectedList += it.results
}
}
) {
assertEquals(expectedList, it)
LaunchedEffect(it ?.size) {
loadNext()
}
}
}
waitForIdle()
assertContentEquals(
listOf(0, 1, 2),
expectedList
)
}
}