-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/#17 home test
- Loading branch information
Showing
689 changed files
with
1,117 additions
and
239 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
139 changes: 139 additions & 0 deletions
139
app/src/androidTest/java/com/najudoryeong/mineme/DoAppStateTest.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,139 @@ | ||
package com.najudoryeong.mineme | ||
|
||
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi | ||
import androidx.compose.material3.windowsizeclass.WindowSizeClass | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.unit.DpSize | ||
import androidx.compose.ui.unit.dp | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.compose.ComposeNavigator | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.createGraph | ||
import androidx.navigation.testing.TestNavHostController | ||
import com.najudoryeong.mineme.core.testing.util.TestNetworkMonitor | ||
import com.najudoryeong.mineme.ui.DoAppState | ||
import com.najudoryeong.mineme.ui.rememberDoAppState | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.test.UnconfinedTestDispatcher | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertTrue | ||
|
||
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class) | ||
class DoAppStateTest { | ||
|
||
// 테스트를 위한 규칙 정의 | ||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
private val networkMonitor = TestNetworkMonitor() | ||
|
||
|
||
// 테스트 대상 | ||
private lateinit var state: DoAppState | ||
|
||
|
||
// AppState currentDestination이 잘 동작하는지 | ||
@Test | ||
fun doAppState_currentDestination() = runTest { | ||
var currentDestination: String? = null | ||
|
||
composeTestRule.setContent { | ||
val navController = rememberTestNavController() | ||
state = remember(navController) { | ||
DoAppState( | ||
navController = navController, | ||
coroutineScope = backgroundScope, | ||
windowSizeClass = getCompactWindowClass(), | ||
networkMonitor = networkMonitor, | ||
) | ||
} | ||
|
||
currentDestination = state.currentDestination?.route | ||
|
||
LaunchedEffect(Unit) { | ||
navController.setCurrentDestination("b") | ||
} | ||
} | ||
|
||
assertEquals("b", currentDestination) | ||
} | ||
|
||
|
||
// toLevelDestination이 올바른 개수,순서인지 | ||
@Test | ||
fun doAppState_destinations() = runTest { | ||
composeTestRule.setContent { | ||
state = rememberDoAppState( | ||
windowSizeClass = getCompactWindowClass(), | ||
networkMonitor = networkMonitor, | ||
) | ||
} | ||
|
||
assertEquals(3, state.topLevelDestinations.size) | ||
assertTrue(state.topLevelDestinations[0].name.contains("home", true)) | ||
assertTrue(state.topLevelDestinations[1].name.contains("story", true)) | ||
assertTrue(state.topLevelDestinations[2].name.contains("settings", true)) | ||
} | ||
|
||
|
||
@Test | ||
fun doAppState_showBottomBar_compact() = runTest { | ||
composeTestRule.setContent { | ||
state = DoAppState( | ||
navController = NavHostController(LocalContext.current), | ||
coroutineScope = backgroundScope, | ||
windowSizeClass = getCompactWindowClass(), | ||
networkMonitor = networkMonitor, | ||
) | ||
} | ||
|
||
assertTrue(state.shouldShowBottomBar) | ||
} | ||
|
||
// offline 설정 잘 되는지 | ||
@Test | ||
fun stateIsOfflineWhenNetworkMonitorIsOffline() = runTest(UnconfinedTestDispatcher()) { | ||
composeTestRule.setContent { | ||
state = DoAppState( | ||
navController = NavHostController(LocalContext.current), | ||
coroutineScope = backgroundScope, | ||
windowSizeClass = WindowSizeClass.calculateFromSize(DpSize(900.dp, 1200.dp)), | ||
networkMonitor = networkMonitor | ||
) | ||
} | ||
|
||
backgroundScope.launch { state.isOffline.collect() } | ||
networkMonitor.setConnected(false) | ||
assertEquals( | ||
true, | ||
state.isOffline.value, | ||
) | ||
} | ||
|
||
private fun getCompactWindowClass() = WindowSizeClass.calculateFromSize(DpSize(500.dp, 300.dp)) | ||
} | ||
|
||
|
||
// TestNavHostController 설정 | ||
@Composable | ||
private fun rememberTestNavController(): TestNavHostController { | ||
val context = LocalContext.current | ||
return remember { | ||
TestNavHostController(context).apply { | ||
navigatorProvider.addNavigator(ComposeNavigator()) | ||
graph = createGraph(startDestination = "a") { | ||
composable("a") { } | ||
composable("b") { } | ||
composable("c") { } | ||
} | ||
} | ||
} | ||
} |
24 changes: 0 additions & 24 deletions
24
app/src/androidTest/java/com/najudoryeong/mineme/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.