Skip to content

Commit

Permalink
Fix paging test IDE errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdgr8 committed Nov 1, 2023
1 parent ec8fbeb commit c676af4
Showing 1 changed file with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Based on https://github.com/cashapp/sqldelight/blob/master/extensions/androidx-paging3/src/commonTest/kotlin/app/cash/sqldelight/paging3/OffsetQueryPagingSourceTest.kt
*/

@file:Suppress("CAST_NEVER_SUCCEEDS", "TYPE_MISMATCH", "UNRESOLVED_REFERENCE")
@file:Suppress("CAST_NEVER_SUCCEEDS")

package kotbase.paging

Expand Down Expand Up @@ -54,7 +54,7 @@ class OffsetQueryPagingSourceTest : BaseDbTest() {
)
pagingSource.refresh()

Pager(CONFIG, pagingSourceFactory = { pagingSource })
Pager(CONFIG, null) { pagingSource }
.flow
.first()
.withPagingDataDiffer(this, testItemDiffCallback) {
Expand Down Expand Up @@ -415,7 +415,7 @@ class OffsetQueryPagingSourceTest : BaseDbTest() {
val result = pagingSource.refresh() as PagingSourceLoadResultPage<Int, TestItem>
// 15 items loaded, assuming anchorPosition = 14 as the last item loaded
var refreshKey = pagingSource.getRefreshKey(
PagingState<Int, TestItem>(
PagingState(
pages = listOf(result),
anchorPosition = 14,
config = CONFIG,
Expand All @@ -433,7 +433,7 @@ class OffsetQueryPagingSourceTest : BaseDbTest() {

assertContentEquals(ITEMS_LIST.subList(15, 20), result2.data)
refreshKey = pagingSource.getRefreshKey(
PagingState<Int, TestItem>(
PagingState(
pages = listOf(result, result2),
// 20 items loaded, assume anchorPosition = 19 as the last item loaded
anchorPosition = 19,
Expand Down Expand Up @@ -475,7 +475,7 @@ class OffsetQueryPagingSourceTest : BaseDbTest() {

// database should only have 40 items left. Refresh key is invalid at this point
// (greater than item count after deletion)
Pager(CONFIG, pagingSourceFactory = { pagingSource2 })
Pager(CONFIG, null) { pagingSource2 }
.flow
.first()
.withPagingDataDiffer(this, testItemDiffCallback) {
Expand Down Expand Up @@ -516,7 +516,7 @@ class OffsetQueryPagingSourceTest : BaseDbTest() {
insertItems()
pagingSource.refresh()

Pager(CONFIG, pagingSourceFactory = { pagingSource })
Pager(CONFIG, null) { pagingSource }
.flow
.first()
.withPagingDataDiffer(this, testItemDiffCallback) {
Expand All @@ -540,7 +540,7 @@ class OffsetQueryPagingSourceTest : BaseDbTest() {
as PagingSourceLoadResultPage<Int, TestItem>

// database should only have 70 items left
Pager(CONFIG, pagingSourceFactory = { pagingSource2 })
Pager(CONFIG, null) { pagingSource2 }
.flow
.first()
.withPagingDataDiffer(this, testItemDiffCallback) {
Expand Down Expand Up @@ -569,7 +569,7 @@ class OffsetQueryPagingSourceTest : BaseDbTest() {
insertItems()
pagingSource.refresh(key = 30)

Pager(CONFIG, pagingSourceFactory = { pagingSource })
Pager(CONFIG, null) { pagingSource }
.flow
.first()
.withPagingDataDiffer(this, testItemDiffCallback) {
Expand All @@ -592,7 +592,7 @@ class OffsetQueryPagingSourceTest : BaseDbTest() {
as PagingSourceLoadResultPage<Int, TestItem>

// database should only have 5 items left
Pager(CONFIG, pagingSourceFactory = { pagingSource2 })
Pager(CONFIG, null) { pagingSource2 }
.flow
.first()
.withPagingDataDiffer(this, testItemDiffCallback) {
Expand Down Expand Up @@ -652,8 +652,11 @@ class OffsetQueryPagingSourceTest : BaseDbTest() {

private val CONFIG = PagingConfig(
pageSize = 5,
prefetchDistance = 5,
enablePlaceholders = true,
initialLoadSize = 15,
maxSize = MAX_SIZE_UNBOUNDED,
jumpThreshold = COUNT_UNDEFINED
)

private val ITEMS_LIST = List(100) { TestItem(id = it.toLong()) }
Expand All @@ -672,19 +675,19 @@ private fun createLoadParam(loadType: LoadType, key: Int?): PagingSourceLoadPara
key = key,
loadSize = CONFIG.initialLoadSize,
placeholdersEnabled = CONFIG.enablePlaceholders,
)
) as PagingSourceLoadParams<Int>

LoadType.APPEND -> PagingSourceLoadParamsAppend(
key = key ?: -1,
loadSize = CONFIG.pageSize,
placeholdersEnabled = CONFIG.enablePlaceholders,
)
) as PagingSourceLoadParams<Int>

LoadType.PREPEND -> PagingSourceLoadParamsPrepend(
key = key ?: -1,
loadSize = CONFIG.pageSize,
placeholdersEnabled = CONFIG.enablePlaceholders,
)
) as PagingSourceLoadParams<Int>

else -> error("Unknown PagingSourceLoadParams ${loadType::class}")
}
Expand Down

0 comments on commit c676af4

Please sign in to comment.