Add online state test, Update offline state tests

pull/1461/head
TM 5 months ago
parent 1d5f10a76b
commit caf28b19ef

@ -56,7 +56,7 @@ class NiaAppStateTest {
// Create the test dependencies. // Create the test dependencies.
private val networkMonitor = TestNetworkMonitor() private val networkMonitor = TestNetworkMonitor()
private val errorMonitor = TestErrorMonitor() private val errorMonitor = TestErrorMonitor(networkMonitor)
private val timeZoneMonitor = TestTimeZoneMonitor() private val timeZoneMonitor = TestTimeZoneMonitor()
@ -122,7 +122,7 @@ class NiaAppStateTest {
) )
} }
backgroundScope.launch { state.isOffline.collect() } backgroundScope.launch { state.isOfflineState.collect() }
networkMonitor.setConnected(false) networkMonitor.setConnected(false)
assertEquals( assertEquals(
true, true,
@ -130,6 +130,26 @@ class NiaAppStateTest {
) )
} }
@Test
fun niaAppState_whenNetworkMonitorIsOnline_StateIsOnline() = runTest(UnconfinedTestDispatcher()) {
composeTestRule.setContent {
state = NiaAppState(
navController = NavHostController(LocalContext.current),
coroutineScope = backgroundScope,
errorMonitor = errorMonitor,
userNewsResourceRepository = userNewsResourceRepository,
timeZoneMonitor = timeZoneMonitor,
)
}
backgroundScope.launch { state.isOfflineState.collect() }
networkMonitor.setConnected(true)
assertEquals(
false,
state.isOfflineState.value,
)
}
@Test @Test
fun niaAppState_differentTZ_withTimeZoneMonitorChange() = runTest(UnconfinedTestDispatcher()) { fun niaAppState_differentTZ_withTimeZoneMonitorChange() = runTest(UnconfinedTestDispatcher()) {
composeTestRule.setContent { composeTestRule.setContent {

@ -20,11 +20,11 @@ import com.google.samples.apps.nowinandroid.core.data.util.ErrorMessage
import com.google.samples.apps.nowinandroid.core.data.util.ErrorMonitor import com.google.samples.apps.nowinandroid.core.data.util.ErrorMonitor
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
class TestErrorMonitor : ErrorMonitor { class TestErrorMonitor(networkMonitor: TestNetworkMonitor) : ErrorMonitor {
override var offlineMessage: String? = "offline" override var offlineMessage: String? = "offline"
override val isOffline: Flow<Boolean> override val isOffline: Flow<Boolean> = networkMonitor.isOnline.map { !it }
get() = flowOf(false)
override fun addShortErrorMessage( override fun addShortErrorMessage(
error: String, error: String,
label: String?, label: String?,

Loading…
Cancel
Save