fix(main): 오디오 알림 이동과 미니 플레이어를 연결한다

This commit is contained in:
2026-07-06 14:00:23 +09:00
parent 5b9b7eafa7
commit e3d81792bf
3 changed files with 235 additions and 2 deletions

View File

@@ -91,6 +91,34 @@ class MainV2ActivitySourceTest {
assertBefore(openContentSource, "changeFragment(MainV2Tab.CONTENT)", "?.selectAllTab(type, sort)")
}
@Test
fun `MainV2Activity는 기존 오디오 서비스 브로드캐스트로 미니 플레이어를 표시한다`() {
val source = projectFile("app/src/main/java/kr/co/vividnext/sodalive/v2/main/MainV2Activity.kt").readText()
assertTrue(source.contains("import android.content.BroadcastReceiver"))
assertTrue(source.contains("import android.content.IntentFilter"))
assertTrue(source.contains("private val audioContentReceiver = AudioContentReceiver()"))
assertTrue(source.contains("IntentFilter(Constants.ACTION_MAIN_AUDIO_CONTENT_RECEIVER)"))
assertTrue(source.contains("registerReceiver(audioContentReceiver, intentFilter"))
assertTrue(source.contains("unregisterReceiver(audioContentReceiver)"))
assertTrue(source.contains("inner class AudioContentReceiver : BroadcastReceiver()"))
val receiverSource = source.substringFrom("inner class AudioContentReceiver : BroadcastReceiver()")
assertTrue(receiverSource.contains("Constants.EXTRA_AUDIO_CONTENT_SHOWING"))
assertTrue(receiverSource.contains("Constants.EXTRA_AUDIO_CONTENT_ID"))
assertTrue(receiverSource.contains("Constants.EXTRA_AUDIO_CONTENT_TITLE"))
assertTrue(receiverSource.contains("Constants.EXTRA_NICKNAME"))
assertTrue(receiverSource.contains("Constants.EXTRA_AUDIO_CONTENT_COVER_IMAGE_URL"))
assertTrue(receiverSource.contains("Constants.EXTRA_AUDIO_CONTENT_PLAYING"))
assertTrue(receiverSource.contains("binding.clMiniPlayer.visibility = View.VISIBLE"))
assertTrue(receiverSource.contains("AudioContentDetailActivity::class.java"))
assertTrue(receiverSource.contains("putExtra(Constants.EXTRA_AUDIO_CONTENT_ID, contentId)"))
assertTrue(receiverSource.contains("AudioContentPlayService.MusicAction.PAUSE.name"))
assertTrue(receiverSource.contains("AudioContentPlayService.MusicAction.PLAY.name"))
assertTrue(receiverSource.contains("AudioContentPlayService.MusicAction.STOP.name"))
assertTrue(receiverSource.contains("binding.clMiniPlayer.visibility = View.GONE"))
}
private fun assertBefore(source: String, expectedBefore: String, expectedAfter: String) {
val beforeIndex = source.indexOf(expectedBefore)
val afterIndex = source.indexOf(expectedAfter, beforeIndex)

View File

@@ -0,0 +1,67 @@
package kr.co.vividnext.sodalive.v2.main
import org.junit.Assert.assertTrue
import org.junit.Test
import java.io.File
class MainV2AudioNotificationRouteSourceTest {
private val source = projectFile(
"app/src/main/java/kr/co/vividnext/sodalive/v2/main/MainV2Activity.kt"
).readText()
@Test
fun `오디오 알림 route는 플레이어와 상세페이지로 분기한다`() {
assertTrue(source.contains("const val EXTRA_AUDIO_NOTIFICATION_ROUTE"))
assertTrue(source.contains("const val ROUTE_AUDIO_PLAYER"))
assertTrue(source.contains("const val ROUTE_AUDIO_DETAIL"))
assertTrue(source.contains("handleAudioNotificationRoute"))
assertTrue(source.contains("showPlayerFragment()"))
assertTrue(source.contains("AudioContentDetailActivity::class.java"))
assertTrue(source.contains("Constants.EXTRA_AUDIO_CONTENT_ID"))
assertTrue(source.contains("removeExtra(EXTRA_AUDIO_NOTIFICATION_ROUTE)"))
}
@Test
fun `오디오 알림 route는 채팅 필터 이후 딥링크 이전에 처리된다`() {
val onNewIntentSource = source.substringFrom("override fun onNewIntent(intent: Intent)")
assertBefore(onNewIntentSource, "if (intent.hasExtra(EXTRA_CHAT_FILTER))", "handleAudioNotificationRoute(intent)")
assertBefore(onNewIntentSource, "handleAudioNotificationRoute(intent)", "isLoggedIn()")
assertBefore(onNewIntentSource, "handleAudioNotificationRoute(intent)", "executeDeeplink(intent)")
val onCreateSource = source.substringFrom("override fun onCreate(savedInstanceState: Bundle?)")
assertBefore(onCreateSource, "handleAudioNotificationRoute(intent)", "isLoggedIn()")
assertBefore(onCreateSource, "handleAudioNotificationRoute(intent)", "executeDeeplink(intent)")
}
@Test
fun `오디오 상세 route는 유효한 content id만 상세페이지로 이동한다`() {
val routeSource = source.substringFrom("private fun handleAudioNotificationRoute(intent: Intent): Boolean")
assertTrue(routeSource.contains("ROUTE_AUDIO_DETAIL ->"))
assertTrue(routeSource.contains("val contentId = intent.getLongExtra(Constants.EXTRA_AUDIO_CONTENT_ID, 0)"))
assertTrue(routeSource.contains("intent.removeExtra(Constants.EXTRA_AUDIO_CONTENT_ID)"))
assertTrue(routeSource.contains("if (contentId > 0"))
assertBefore(routeSource, "if (contentId > 0", "AudioContentDetailActivity::class.java")
}
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() }
?: error("Project file not found: $relativePath")
}
}