adding test for cancelling previous page job

- fixes wrong page key being used to cancel previous
This commit is contained in:
Adam Brown 2022-11-03 12:40:27 +00:00
parent 6492afe063
commit b1c5481d1e
2 changed files with 9 additions and 1 deletions

View File

@ -57,7 +57,7 @@ fun imageGalleryReducer(
},
sideEffect(PageStateChange.ChangePage::class) { action, _ ->
jobBag.cancel(action.previous::class)
jobBag.cancel(action.previous.state::class)
},
)
}

View File

@ -90,6 +90,14 @@ class ImageGalleryReducerTest {
)
}
@Test
fun `when ChangePage, then cancels previous page jobs`() = runReducerTest {
fakeJobBag.instance.expect { it.cancel(ImageGalleryPage.Folders::class) }
reduce(PageStateChange.ChangePage(previous = AN_INITIAL_FOLDERS_PAGE, newPage = AN_INITIAL_FILES_PAGE))
assertOnlyStateChange(pageState(AN_INITIAL_FILES_PAGE))
}
}
private fun <P> pageState(page: SpiderPage<out P>) = Combined2(PageContainer(page), Unit)