generated from nimblehq/git-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#102] Update isNetworkConnected to be StateFlow and add test
- Loading branch information
1 parent
a3f5d4b
commit 4b5bc67
Showing
5 changed files
with
77 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
app/src/test/java/co/nimblehq/compose/crypto/ui/screens/ComposeCryptoAppTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package co.nimblehq.compose.crypto.ui.screens | ||
|
||
import androidx.activity.compose.setContent | ||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.junit4.createAndroidComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import co.nimblehq.compose.crypto.R | ||
import co.nimblehq.compose.crypto.domain.usecase.IsNetworkConnectedUseCase | ||
import co.nimblehq.compose.crypto.rememberCryptoAppState | ||
import co.nimblehq.compose.crypto.ui.navigation.ComposeCryptoApp | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.flowOf | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
@RunWith(RobolectricTestRunner::class) | ||
class ComposeCryptoAppTest : BaseViewModelTest() { | ||
|
||
@get:Rule | ||
val composeAndroidTestRule = createAndroidComposeRule<MainActivity>() | ||
|
||
private val mockIsNetworkConnectedUseCase: IsNetworkConnectedUseCase = mockk() | ||
|
||
private val noInternetMessage: String | ||
get() = composeAndroidTestRule.activity.getString(R.string.no_internet_message) | ||
|
||
@Before | ||
fun setUp() { | ||
composeAndroidTestRule.activity.setContent { | ||
ComposeCryptoApp( | ||
cryptoAppState = rememberCryptoAppState( | ||
isNetworkConnectedUseCase = mockIsNetworkConnectedUseCase, | ||
dispatchersProvider = testDispatcherProvider | ||
) | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun `When there is no internet, it shows dialog`() { | ||
every { mockIsNetworkConnectedUseCase.invoke() } returns flowOf(false) | ||
|
||
with(composeAndroidTestRule) { | ||
onNodeWithText(noInternetMessage).assertIsDisplayed() | ||
} | ||
} | ||
|
||
@Test | ||
fun `When there is internet, it does not show dialog`() { | ||
every { mockIsNetworkConnectedUseCase.invoke() } returns flowOf(true) | ||
|
||
with(composeAndroidTestRule) { | ||
onNodeWithText(noInternetMessage).assertDoesNotExist() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters