From c0aa1124f743e8313b9a933e025102eb3b178a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=BC=ED=98=81?= Date: Fri, 23 Oct 2026 04:13:59 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat(app):=20=EC=95=8C=EB=A6=BC=20=EC=A7=84?= =?UTF-8?q?=EC=9E=85=20=ED=81=90=EB=A5=BC=20Nav3=20=EC=95=B1=20=EC=85=B8?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=86=8C=EB=B9=84=ED=95=B4=20=EB=AA=A9?= =?UTF-8?q?=EC=A0=81=EC=A7=80=20=ED=83=AD=EC=9C=BC=EB=A1=9C=20=EC=98=AE?= =?UTF-8?q?=EA=B8=B4=EB=8B=A4=20(#1795)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NotificationNavigationAndroidTest.kt | 20 +++++---- .../afternote_fe/navigation/AppNavigation.kt | 1 + .../navigation/NotificationEntryEffect.kt | 42 +++++++++++++++++++ 3 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/com/afternote/afternote_fe/navigation/NotificationEntryEffect.kt diff --git a/app/src/androidTest/java/com/afternote/afternote_fe/NotificationNavigationAndroidTest.kt b/app/src/androidTest/java/com/afternote/afternote_fe/NotificationNavigationAndroidTest.kt index b24735a475..9bcd568c43 100644 --- a/app/src/androidTest/java/com/afternote/afternote_fe/NotificationNavigationAndroidTest.kt +++ b/app/src/androidTest/java/com/afternote/afternote_fe/NotificationNavigationAndroidTest.kt @@ -109,9 +109,9 @@ class NotificationNavigationAndroidTest { composeRule .onNodeWithText(context.getString(OnboardingR.string.onboarding_welcome_start)) .assertIsDisplayed() - deliverWarmNotification(NotificationEntrySource.FCM, "logged-out-1", NotificationDestination.HOME) + deliverWarmNotification(NotificationEntrySource.FCM, "logged-out-1", NotificationDestination.TIME_LETTER) - awaitNotificationIntent(NotificationEntrySource.FCM, "logged-out-1", NotificationDestination.HOME) + awaitNotificationIntent(NotificationEntrySource.FCM, "logged-out-1", NotificationDestination.TIME_LETTER) assertSame(activityUnderTest, resumedMainActivity()) composeRule .onNodeWithText(context.getString(OnboardingR.string.onboarding_welcome_start)) @@ -119,10 +119,8 @@ class NotificationNavigationAndroidTest { fakeAuth.loggedIn = true - val greeting = context.getString(HomeR.string.home_tab_greeting, "테스트 사용자") - composeRule.waitUntilAtLeastOneExists(hasText(greeting), timeoutMillis = 10_000) - composeRule.onNodeWithText(greeting).assertIsDisplayed() - composeRule.onNode(selectedBottomBarMatcher(CoreUiR.string.core_ui_nav_item_home)).assertIsSelected() + // 로그인이 확정되면 큐에 남아 있던 알림이 그제서야 목적지로 이어진다. + awaitSelectedBottomBarTab(CoreUiR.string.core_ui_nav_item_timeletter) } @Test @@ -136,7 +134,12 @@ class NotificationNavigationAndroidTest { awaitNotificationIntent(NotificationEntrySource.FCM, "logged-in-1", NotificationDestination.HOME) assertSame(activityUnderTest, resumedMainActivity()) - // 목적지 이동 결선은 #1795 가 Nav3 루트에 붙인다 — 지금은 보던 탭에 머문다. + awaitSelectedBottomBarTab(CoreUiR.string.core_ui_nav_item_home) + + // 같은 알림을 다시 받아도 두 번 처리하지 않는다 — 탭을 옮겨 둔 뒤 재전달해도 그대로다. + openTimeLetterTab() + deliverWarmNotification(NotificationEntrySource.FCM, "logged-in-1", NotificationDestination.HOME) + composeRule.waitForIdle() awaitSelectedBottomBarTab(CoreUiR.string.core_ui_nav_item_timeletter) } @@ -162,8 +165,7 @@ class NotificationNavigationAndroidTest { NotificationDestination.AFTERNOTE, ) assertSame(activityUnderTest, resumedMainActivity()) - // 목적지 이동 결선은 #1795 가 붙인다 — 지금은 보던 홈 탭에 머문다. - awaitSelectedBottomBarTab(CoreUiR.string.core_ui_nav_item_home) + awaitSelectedBottomBarTab(CoreUiR.string.core_ui_nav_item_note) } @Test diff --git a/app/src/main/java/com/afternote/afternote_fe/navigation/AppNavigation.kt b/app/src/main/java/com/afternote/afternote_fe/navigation/AppNavigation.kt index e53275e3a2..5ea1d58e40 100644 --- a/app/src/main/java/com/afternote/afternote_fe/navigation/AppNavigation.kt +++ b/app/src/main/java/com/afternote/afternote_fe/navigation/AppNavigation.kt @@ -155,6 +155,7 @@ fun AppNavigation( } NotificationPermissionEffect(snackbarHostState = snackbarHostState) + NotificationEntryEffect(appState = appState, mainViewModel = mainViewModel) Scaffold( modifier = modifier, diff --git a/app/src/main/java/com/afternote/afternote_fe/navigation/NotificationEntryEffect.kt b/app/src/main/java/com/afternote/afternote_fe/navigation/NotificationEntryEffect.kt new file mode 100644 index 0000000000..ab2f1b336d --- /dev/null +++ b/app/src/main/java/com/afternote/afternote_fe/navigation/NotificationEntryEffect.kt @@ -0,0 +1,42 @@ +package com.afternote.afternote_fe.navigation + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.afternote.afternote_fe.MainViewModel +import com.afternote.core.common.notification.NotificationDestination +import com.afternote.core.ui.Route + +/** + * Activity 가 큐에 넣은 알림 진입을 앱 셸이 소비해 목적지 탭으로 옮긴다. + * + * 로그인이 확정되고 앱 셸이 바텀바 스택 위에 있을 때만 소비한다. 로그아웃(온보딩 FLOW 스택)이면 + * 큐에 남겨 두어 알림이 인증 관문을 건너뛰는 통로가 되지 않게 하고, 로그인이 끝나 스택이 + * 바뀌는 순간 효과가 다시 돌아 그 목적지로 이어진다. 이동은 바텀바 탭을 누른 것과 같은 + * [AppState.navigateToBottomBarRoute] 를 재사용해 백스택 규약을 한 벌로 유지한다. + */ +@Composable +internal fun NotificationEntryEffect( + appState: AppState, + mainViewModel: MainViewModel, +) { + val pendingEntry by mainViewModel.pendingNotificationEntry.collectAsStateWithLifecycle() + val authenticatedStartRoute by mainViewModel.startRoute.collectAsStateWithLifecycle() + val isReadyForDestination = + authenticatedStartRoute == Route.Home && appState.activeStack != AppStack.FLOW + val entry = pendingEntry + LaunchedEffect(entry?.identityKey, isReadyForDestination) { + if (entry == null || !isReadyForDestination) return@LaunchedEffect + appState.navigateToBottomBarRoute(entry.destination.toBottomBarRoute()) + mainViewModel.consumeNotificationEntry(entry.identityKey) + } +} + +internal fun NotificationDestination.toBottomBarRoute(): Route = + when (this) { + NotificationDestination.HOME -> Route.Home + NotificationDestination.MIND_RECORD -> Route.MindRecord + NotificationDestination.TIME_LETTER -> Route.TimeLetter + NotificationDestination.AFTERNOTE -> Route.Afternote + } From c702e811106784ed483e04d2235ea877b7341a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=BC=ED=98=81?= Date: Fri, 23 Oct 2026 04:33:48 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix(app):=20=ED=83=AD=20NavHost=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A1=A4=EB=9F=AC=EB=A5=BC=20Nav3=20=EC=97=94?= =?UTF-8?q?=ED=8A=B8=EB=A6=AC=20=EC=88=98=EB=AA=85=EC=97=90=20=EB=A7=9E?= =?UTF-8?q?=EC=B6=B0=20=EC=9E=AC=EC=A7=84=EC=9E=85=20=ED=81=AC=EB=9E=98?= =?UTF-8?q?=EC=8B=9C=EB=A5=BC=20=EB=A7=89=EB=8A=94=EB=8B=A4=20(#1795)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../afternote_fe/navigation/AppNavigation.kt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/afternote/afternote_fe/navigation/AppNavigation.kt b/app/src/main/java/com/afternote/afternote_fe/navigation/AppNavigation.kt index 5ea1d58e40..f2b8dcd1b4 100644 --- a/app/src/main/java/com/afternote/afternote_fe/navigation/AppNavigation.kt +++ b/app/src/main/java/com/afternote/afternote_fe/navigation/AppNavigation.kt @@ -14,9 +14,12 @@ import androidx.compose.material3.Scaffold import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.SideEffect import androidx.compose.runtime.getValue +import androidx.compose.runtime.key +import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope @@ -69,8 +72,14 @@ fun AppNavigation( ) { val context = LocalContext.current val activity = remember(context) { context.findActivity() } - val rememberedMindRecordController = rememberNavController() - val rememberedTimeLetterController = rememberNavController() + // 탭 NavHost 의 컨트롤러는 셸이 들고 있지만, NavHost 가 붙는 Nav3 엔트리는 탭 스택을 바꿀 때마다 + // 내려가며 자기 ViewModelStore·Lifecycle 을 버린다. 다시 들어온 엔트리에 옛 컨트롤러를 붙이면 + // "ViewModelStore should be set before setGraph call" 로 죽으므로, 엔트리 컴포지션이 내려갈 때 + // 세대를 올려 컨트롤러도 엔트리와 같은 수명으로 새로 만든다. + var mindRecordHostGeneration by remember { mutableIntStateOf(0) } + var timeLetterHostGeneration by remember { mutableIntStateOf(0) } + val rememberedMindRecordController = key(mindRecordHostGeneration) { rememberNavController() } + val rememberedTimeLetterController = key(timeLetterHostGeneration) { rememberNavController() } val mindRecordController = mindRecordNavController ?: appState.legacyMindRecordController ?: rememberedMindRecordController val timeLetterController = timeLetterNavController ?: rememberedTimeLetterController val mindRecordEntry by mindRecordController.currentBackStackEntryAsState() @@ -204,12 +213,14 @@ fun AppNavigation( HomeTabScreen(uiState = uiState, actions = actions) } entry { + DisposableEffect(Unit) { onDispose { mindRecordHostGeneration++ } } MindRecordRootHost( navController = mindRecordController, actions = mindRecordNavActions, ) } entry { + DisposableEffect(Unit) { onDispose { timeLetterHostGeneration++ } } NavHost(navController = timeLetterController, startDestination = Route.TimeLetter::class) { timeLetterNavGraph(navController = timeLetterController, actions = timeLetterNavActions) } From 7ed501636de6d3c08a08907a1cae35dabb40c86e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=BC=ED=98=81?= Date: Sun, 25 Oct 2026 15:20:34 +0900 Subject: [PATCH 3/4] =?UTF-8?q?test(app):=20=EC=95=8C=EB=A6=BC=20cold=20?= =?UTF-8?q?=EC=A7=84=EC=9E=85=EC=9D=98=20=EB=AA=A9=EC=A0=81=EC=A7=80=20?= =?UTF-8?q?=EB=8F=84=EB=8B=AC=EC=9D=84=20=EA=B2=80=EC=A6=9D=ED=95=9C?= =?UTF-8?q?=EB=8B=A4=20(#1795)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NotificationColdStartAndroidTest.kt | 76 ++++++++++++++----- .../NotificationNavigationAndroidTest.kt | 2 +- .../navigation/NotificationEntryEffect.kt | 2 +- 3 files changed, 58 insertions(+), 22 deletions(-) diff --git a/app/src/androidTest/java/com/afternote/afternote_fe/NotificationColdStartAndroidTest.kt b/app/src/androidTest/java/com/afternote/afternote_fe/NotificationColdStartAndroidTest.kt index 648401a442..cc10ce05c2 100644 --- a/app/src/androidTest/java/com/afternote/afternote_fe/NotificationColdStartAndroidTest.kt +++ b/app/src/androidTest/java/com/afternote/afternote_fe/NotificationColdStartAndroidTest.kt @@ -1,6 +1,12 @@ package com.afternote.afternote_fe import android.app.Instrumentation +import androidx.compose.ui.test.ExperimentalTestApi +import androidx.compose.ui.test.assertIsSelected +import androidx.compose.ui.test.hasClickAction +import androidx.compose.ui.test.hasText +import androidx.compose.ui.test.junit4.createEmptyComposeRule +import androidx.compose.ui.test.waitUntilAtLeastOneExists import androidx.lifecycle.ViewModelProvider import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 @@ -10,6 +16,8 @@ import com.afternote.afternote_fe.notification.NotificationEntrySource import com.afternote.afternote_fe.test.backgroundActivityStartOptions import com.afternote.core.common.notification.NotificationDestination import com.afternote.core.common.notification.NotificationPendingIntentFactory +import com.afternote.core.domain.repository.auth.AuthRepository +import com.afternote.core.domain.testing.FakeAuthRepository import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest import org.junit.After @@ -19,13 +27,22 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import javax.inject.Inject +import com.afternote.core.ui.R as CoreUiR @HiltAndroidTest @RunWith(AndroidJUnit4::class) +@OptIn(ExperimentalTestApi::class) class NotificationColdStartAndroidTest { - @get:Rule + @Inject + lateinit var authRepository: AuthRepository + + @get:Rule(order = 0) val hiltRule = HiltAndroidRule(this) + @get:Rule(order = 1) + val composeRule = createEmptyComposeRule() + private val instrumentation: Instrumentation get() = InstrumentationRegistry.getInstrumentation() @@ -48,29 +65,11 @@ class NotificationColdStartAndroidTest { @Test fun coldPendingIntentLaunch_enqueuesInitialNotificationEntry() { - val context = ApplicationProvider.getApplicationContext() val source = NotificationEntrySource.FCM val occurrenceId = "cold-start-1" // 폴백(HOME)이 아닌 목적지를 실어 cold start 경로에서 extra 가 살아남는지 본다. val destination = NotificationDestination.TIME_LETTER - activityMonitor = instrumentation.addMonitor(MainActivity::class.java.name, null, false) - - val pendingIntent = - NotificationPendingIntentFactory.create( - context = context, - source = source.contractValue, - occurrenceId = occurrenceId, - destination = destination, - ) - - assertNotNull(pendingIntent) - pendingIntent?.send(context, 0, null, null, null, null, backgroundActivityStartOptions()) - launchedActivity = - activityMonitor?.let { monitor -> - instrumentation.waitForMonitorWithTimeout(monitor, ACTIVITY_START_TIMEOUT_MILLIS) - } as? MainActivity - assertNotNull(launchedActivity) - instrumentation.waitForIdleSync() + launchNotification(source, occurrenceId, destination) var pendingEntry: NotificationEntryRequest? = null instrumentation.runOnMainSync { @@ -91,6 +90,43 @@ class NotificationColdStartAndroidTest { ) } + @Test + fun coldPendingIntentLaunchWhileLoggedIn_opensDestination() { + (authRepository as FakeAuthRepository).loggedIn = true + launchNotification(NotificationEntrySource.FCM, "cold-start-signed-in", NotificationDestination.TIME_LETTER) + + val context = ApplicationProvider.getApplicationContext() + val destinationTab = hasText(context.getString(CoreUiR.string.core_ui_nav_item_timeletter)) and hasClickAction() + composeRule.waitUntilAtLeastOneExists(destinationTab, timeoutMillis = ACTIVITY_START_TIMEOUT_MILLIS) + composeRule.onNode(destinationTab).assertIsSelected() + } + + private fun launchNotification( + source: NotificationEntrySource, + occurrenceId: String, + destination: NotificationDestination, + ) { + val context = ApplicationProvider.getApplicationContext() + activityMonitor = instrumentation.addMonitor(MainActivity::class.java.name, null, false) + + val pendingIntent = + NotificationPendingIntentFactory.create( + context = context, + source = source.contractValue, + occurrenceId = occurrenceId, + destination = destination, + ) + + assertNotNull(pendingIntent) + pendingIntent?.send(context, 0, null, null, null, null, backgroundActivityStartOptions()) + launchedActivity = + activityMonitor?.let { monitor -> + instrumentation.waitForMonitorWithTimeout(monitor, ACTIVITY_START_TIMEOUT_MILLIS) + } as? MainActivity + assertNotNull(launchedActivity) + instrumentation.waitForIdleSync() + } + private companion object { const val ACTIVITY_START_TIMEOUT_MILLIS = 10_000L } diff --git a/app/src/androidTest/java/com/afternote/afternote_fe/NotificationNavigationAndroidTest.kt b/app/src/androidTest/java/com/afternote/afternote_fe/NotificationNavigationAndroidTest.kt index 9bcd568c43..a6350bdac1 100644 --- a/app/src/androidTest/java/com/afternote/afternote_fe/NotificationNavigationAndroidTest.kt +++ b/app/src/androidTest/java/com/afternote/afternote_fe/NotificationNavigationAndroidTest.kt @@ -144,7 +144,7 @@ class NotificationNavigationAndroidTest { } @Test - fun backgroundNotification_resumesSameActivityAndKeepsCurrentScreen() { + fun backgroundNotification_resumesSameActivityAndNavigatesToDestination() { fakeAuth.loggedIn = true val greeting = context.getString(HomeR.string.home_tab_greeting, "테스트 사용자") diff --git a/app/src/main/java/com/afternote/afternote_fe/navigation/NotificationEntryEffect.kt b/app/src/main/java/com/afternote/afternote_fe/navigation/NotificationEntryEffect.kt index ab2f1b336d..4bdfdf8697 100644 --- a/app/src/main/java/com/afternote/afternote_fe/navigation/NotificationEntryEffect.kt +++ b/app/src/main/java/com/afternote/afternote_fe/navigation/NotificationEntryEffect.kt @@ -33,7 +33,7 @@ internal fun NotificationEntryEffect( } } -internal fun NotificationDestination.toBottomBarRoute(): Route = +private fun NotificationDestination.toBottomBarRoute(): Route = when (this) { NotificationDestination.HOME -> Route.Home NotificationDestination.MIND_RECORD -> Route.MindRecord From 7f5fff18504543bd7f775c54636b41731317bbd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=BC=ED=98=81?= Date: Sun, 25 Oct 2026 15:29:04 +0900 Subject: [PATCH 4/4] =?UTF-8?q?test(app):=20cold=20=EC=95=8C=EB=A6=BC?= =?UTF-8?q?=EC=9D=98=20=ED=83=AD=20=EC=84=A0=ED=83=9D=20=EC=99=84=EB=A3=8C?= =?UTF-8?q?=EB=A5=BC=20=EA=B8=B0=EB=8B=A4=EB=A6=B0=EB=8B=A4=20(#1795)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../afternote_fe/NotificationColdStartAndroidTest.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/androidTest/java/com/afternote/afternote_fe/NotificationColdStartAndroidTest.kt b/app/src/androidTest/java/com/afternote/afternote_fe/NotificationColdStartAndroidTest.kt index cc10ce05c2..950bee0fd6 100644 --- a/app/src/androidTest/java/com/afternote/afternote_fe/NotificationColdStartAndroidTest.kt +++ b/app/src/androidTest/java/com/afternote/afternote_fe/NotificationColdStartAndroidTest.kt @@ -1,9 +1,10 @@ package com.afternote.afternote_fe import android.app.Instrumentation +import androidx.compose.ui.semantics.SemanticsProperties import androidx.compose.ui.test.ExperimentalTestApi +import androidx.compose.ui.test.SemanticsMatcher import androidx.compose.ui.test.assertIsSelected -import androidx.compose.ui.test.hasClickAction import androidx.compose.ui.test.hasText import androidx.compose.ui.test.junit4.createEmptyComposeRule import androidx.compose.ui.test.waitUntilAtLeastOneExists @@ -96,7 +97,9 @@ class NotificationColdStartAndroidTest { launchNotification(NotificationEntrySource.FCM, "cold-start-signed-in", NotificationDestination.TIME_LETTER) val context = ApplicationProvider.getApplicationContext() - val destinationTab = hasText(context.getString(CoreUiR.string.core_ui_nav_item_timeletter)) and hasClickAction() + val destinationTab = + hasText(context.getString(CoreUiR.string.core_ui_nav_item_timeletter)) and + SemanticsMatcher.expectValue(SemanticsProperties.Selected, true) composeRule.waitUntilAtLeastOneExists(destinationTab, timeoutMillis = ACTIVITY_START_TIMEOUT_MILLIS) composeRule.onNode(destinationTab).assertIsSelected() }