refactor(home): 홈 접근 가드를 공통화한다
This commit is contained in:
+14
-14
@@ -13,7 +13,7 @@ class HomeMainFragmentLoginGuardSourceTest {
|
||||
"app/src/main/java/kr/co/vividnext/sodalive/v2/main/home/HomeMainFragment.kt"
|
||||
).readText()
|
||||
|
||||
assertTrue(source.contains("import kr.co.vividnext.sodalive.v2.main.ensureMainV2NavigationAllowed"))
|
||||
assertTrue(source.contains("import kr.co.vividnext.sodalive.v2.access.ensureV2Access"))
|
||||
assertGuardedStartActivity(source, "private fun openHomeOnAirLive()")
|
||||
assertGuardedStartActivity(source, "private fun openFollowingChat(item: ChatRoomListUiItem)")
|
||||
assertGuardedStartActivity(source, "private fun onBannerClick(item: HomeRecommendationBannerUiModel)")
|
||||
@@ -65,12 +65,12 @@ class HomeMainFragmentLoginGuardSourceTest {
|
||||
assertBefore(
|
||||
clickSource,
|
||||
"val community = item as? HomeFollowingNewsUiItem.Community ?: return",
|
||||
"ensureMainV2NavigationAllowed"
|
||||
"ensureV2Access"
|
||||
)
|
||||
assertBefore(
|
||||
clickSource,
|
||||
"if (postId <= 0L) return",
|
||||
"ensureMainV2NavigationAllowed"
|
||||
"ensureV2Access"
|
||||
)
|
||||
assertTrue(clickSource.contains("CreatorChannelCommunityDetailActivity.newIntent(requireContext(), postId)"))
|
||||
assertFalse(clickSource.contains("CreatorCommunityAllActivity"))
|
||||
@@ -98,15 +98,15 @@ class HomeMainFragmentLoginGuardSourceTest {
|
||||
"app/src/main/java/kr/co/vividnext/sodalive/v2/main/home/HomeMainFragment.kt"
|
||||
).readText()
|
||||
|
||||
assertTrue(source.contains("import kr.co.vividnext.sodalive.common.SharedPreferenceManager"))
|
||||
assertTrue(source.contains("import kr.co.vividnext.sodalive.v2.access.AccessRequirement"))
|
||||
assertTrue(source.contains("private var currentHomeTabIndex = HOME_TAB_RECOMMENDATION"))
|
||||
|
||||
val followingTabSource = source.substringFrom("private fun openFollowingTab()")
|
||||
assertTrue(followingTabSource.contains("if (SharedPreferenceManager.token.isBlank())"))
|
||||
assertTrue(followingTabSource.contains("val allowed = ensureV2Access(AccessRequirement.Login)"))
|
||||
assertBefore(
|
||||
followingTabSource,
|
||||
"binding.textTabBarHome.root.selectTab(currentHomeTabIndex)",
|
||||
"ensureMainV2NavigationAllowed"
|
||||
"val allowed = ensureV2Access(AccessRequirement.Login)",
|
||||
"binding.textTabBarHome.root.selectTab(currentHomeTabIndex)"
|
||||
)
|
||||
assertTrue(followingTabSource.contains("showHomeTab(HOME_TAB_FOLLOWING)"))
|
||||
|
||||
@@ -121,21 +121,21 @@ class HomeMainFragmentLoginGuardSourceTest {
|
||||
).readText()
|
||||
|
||||
val clickSource = source.substringFrom("private fun onLiveClick(item: HomeRecommendationLiveUiModel)")
|
||||
assertTrue(clickSource.contains("ensureMainV2NavigationAllowed"))
|
||||
assertTrue(clickSource.contains("ensureV2Access"))
|
||||
assertTrue(clickSource.contains("liveViewModel.getRoomDetail(item.roomId) { roomDetail ->"))
|
||||
assertBefore(
|
||||
clickSource,
|
||||
"if (!isAdded || view == null) return@getRoomDetail",
|
||||
"requiresAdultContentAccess = roomDetail.isAdult"
|
||||
"AccessRequirement.forAdultContent(roomDetail.isAdult)"
|
||||
)
|
||||
assertBefore(
|
||||
clickSource,
|
||||
"liveViewModel.getRoomDetail(item.roomId) { roomDetail ->",
|
||||
"requiresAdultContentAccess = roomDetail.isAdult"
|
||||
"AccessRequirement.forAdultContent(roomDetail.isAdult)"
|
||||
)
|
||||
assertBefore(
|
||||
clickSource,
|
||||
"requiresAdultContentAccess = roomDetail.isAdult",
|
||||
"AccessRequirement.forAdultContent(roomDetail.isAdult)",
|
||||
"liveCoordinator.enterLiveRoom(item.roomId, roomDetail)"
|
||||
)
|
||||
assertFalse(clickSource.contains("= Unit"))
|
||||
@@ -189,14 +189,14 @@ class HomeMainFragmentLoginGuardSourceTest {
|
||||
private fun assertGuardedStartActivity(source: String, functionSignature: String) {
|
||||
val functionSource = source.substringFrom(functionSignature)
|
||||
assertTrue(
|
||||
"$functionSignature must call ensureMainV2NavigationAllowed before startActivity.",
|
||||
functionSource.indexOf("ensureMainV2NavigationAllowed") in 0 until functionSource.indexOf("startActivity")
|
||||
"$functionSignature must call ensureV2Access before startActivity.",
|
||||
functionSource.indexOf("ensureV2Access") in 0 until functionSource.indexOf("startActivity")
|
||||
)
|
||||
}
|
||||
|
||||
private fun assertBeforeGuard(source: String, expectedReturn: String) {
|
||||
val returnIndex = source.indexOf(expectedReturn)
|
||||
val guardIndex = source.indexOf("ensureMainV2NavigationAllowed", returnIndex)
|
||||
val guardIndex = source.indexOf("ensureV2Access", returnIndex)
|
||||
|
||||
assertTrue("Missing source: $expectedReturn", returnIndex >= 0)
|
||||
assertTrue("$expectedReturn must stay before guard.", guardIndex > returnIndex)
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ class HomeMainTitleBarActionSourceTest {
|
||||
assertTrue(source.contains("viewHomeTitleBar.ivTitleBarCash.setOnClickListener"))
|
||||
assertTrue(source.contains("viewHomeTitleBar.ivTitleBarSearch.setOnClickListener"))
|
||||
assertTrue(source.contains("viewHomeTitleBar.ivTitleBarBell.setOnClickListener"))
|
||||
assertTrue(source.contains("ensureMainV2NavigationAllowed"))
|
||||
assertTrue(source.contains("ensureV2Access"))
|
||||
assertTrue(source.contains("CanChargeActivity::class.java"))
|
||||
assertTrue(source.contains("SearchActivity::class.java"))
|
||||
assertTrue(source.contains("PushNotificationListActivity::class.java"))
|
||||
|
||||
Reference in New Issue
Block a user