Add updateToPendingOrLoading helper method (#390)

This commit is contained in:
David Perez
2023-12-13 18:35:33 -06:00
committed by GitHub
parent e702a2105f
commit 4df89cc01a
3 changed files with 35 additions and 10 deletions

View File

@@ -23,4 +23,22 @@ class DataStateExtensionsTest {
awaitComplete()
}
}
@Test
fun `updateToPendingOrLoading should change the DataState to Pending when data is present`() {
val mutableStateFlow = MutableStateFlow<DataState<Unit>>(DataState.Loaded(Unit))
mutableStateFlow.updateToPendingOrLoading()
assertEquals(DataState.Pending(Unit), mutableStateFlow.value)
}
@Test
fun `updateToPendingOrLoading should change the DataState to Loading when data is absent`() {
val mutableStateFlow = MutableStateFlow<DataState<Unit>>(DataState.Error(Throwable("Fail")))
mutableStateFlow.updateToPendingOrLoading()
assertEquals(DataState.Loading, mutableStateFlow.value)
}
}