fix(main): 대화 탭 로그인 가드를 적용한다
This commit is contained in:
@@ -46,6 +46,48 @@ class MainV2ActivitySourceTest {
|
||||
assertTrue(dmRouteIndex < firstFallbackIndex)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `MainV2Activity 대화 탭 이동은 로그인 가드를 통과한 뒤 탭을 전환한다`() {
|
||||
val source = projectFile("app/src/main/java/kr/co/vividnext/sodalive/v2/main/MainV2Activity.kt").readText()
|
||||
|
||||
assertTrue(source.contains("private fun selectChatTabWithLoginGuard(): Boolean"))
|
||||
|
||||
val guardSource = source.substringFrom("private fun selectChatTabWithLoginGuard(): Boolean")
|
||||
assertBefore(guardSource, "if (!isLoggedIn())", "viewModel.clickTab(MainV2Tab.CHAT)")
|
||||
assertBefore(guardSource, "showLoginActivity()", "return false")
|
||||
assertTrue(guardSource.contains("return true"))
|
||||
|
||||
val setupViewSource = source.substringFrom("override fun setupView()")
|
||||
assertTrue(setupViewSource.contains("selectChatTabWithLoginGuard()"))
|
||||
assertFalse(setupViewSource.contains("viewModel.clickTab(MainV2Tab.CHAT)"))
|
||||
|
||||
val openChatTabSource = source.substringFrom("fun openChatTab()")
|
||||
assertTrue(openChatTabSource.contains("selectChatTabWithLoginGuard()"))
|
||||
assertFalse(openChatTabSource.contains("viewModel.clickTab(MainV2Tab.CHAT)"))
|
||||
|
||||
val openChatFilterSource = source.substringFrom("private fun openChatWithInitialFilter()")
|
||||
assertTrue(openChatFilterSource.contains("selectChatTabWithLoginGuard()"))
|
||||
assertFalse(openChatFilterSource.contains("viewModel.clickTab(MainV2Tab.CHAT)"))
|
||||
|
||||
val navigationSource = source.substringFrom("private fun setupBottomNavigation()")
|
||||
assertTrue(navigationSource.contains("R.id.menu_main_v2_chat -> selectChatTabWithLoginGuard()"))
|
||||
}
|
||||
|
||||
private fun assertBefore(source: String, expectedBefore: String, expectedAfter: String) {
|
||||
val beforeIndex = source.indexOf(expectedBefore)
|
||||
val afterIndex = source.indexOf(expectedAfter, beforeIndex)
|
||||
|
||||
assertTrue("Missing source: $expectedBefore", beforeIndex >= 0)
|
||||
assertTrue("Missing source after $expectedBefore: $expectedAfter", afterIndex > beforeIndex)
|
||||
}
|
||||
|
||||
private fun String.substringFrom(marker: String): String {
|
||||
val startIndex = indexOf(marker)
|
||||
assertTrue("Missing function: $marker", startIndex >= 0)
|
||||
val nextFunctionIndex = indexOf("\n private fun ", startIndex + marker.length).takeIf { it >= 0 } ?: length
|
||||
return substring(startIndex, nextFunctionIndex)
|
||||
}
|
||||
|
||||
private fun projectFile(relativePath: String): File {
|
||||
val candidates = listOf(File(relativePath), File("../$relativePath"))
|
||||
return candidates.firstOrNull { it.exists() }
|
||||
|
||||
Reference in New Issue
Block a user