Add updateToPendingOrLoading helper method (#390)

This commit is contained in:
David Perez
2024-06-20 17:08:07 +01:00
committed by Álison Fernandes
parent 5932ebb5c6
commit 36e913b680
3 changed files with 35 additions and 10 deletions
@@ -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)
}
}