@@ -15,6 +15,7 @@ import io.sentry.SentryTracer
1515import io.sentry.TransactionContext
1616import io.sentry.TransactionOptions
1717import io.sentry.TypeCheckHint
18+ import io.sentry.protocol.App
1819import io.sentry.protocol.TransactionNameSource
1920import kotlin.test.Test
2021import kotlin.test.assertNull
@@ -230,6 +231,7 @@ class BackStackObserverTest {
230231
231232 assertThat(fixture.scope.screen).isNull()
232233 assertThat(fixture.scope.contexts.app?.viewNames).isNull()
234+ assertThat(fixture.startedTransactions.single().contexts.app?.viewNames).isNull()
233235 }
234236
235237 @Test
@@ -372,6 +374,31 @@ class BackStackObserverTest {
372374 assertThat(argumentCalls).doesNotContainKey(home)
373375 }
374376
377+ @Test
378+ fun `onBackStackChanged resolves top entry arguments once per update` () {
379+ val fixture = Fixture ()
380+ val home = HomeRoute ()
381+ val profile = ProfileRoute (" 123" )
382+ val argumentCalls = mutableMapOf<Any , Int >()
383+ val sut =
384+ fixture.getSut(
385+ argumentsExtractor =
386+ RouteArgumentsExtractor { entry ->
387+ argumentCalls[entry] = (argumentCalls[entry] ? : 0 ) + 1
388+ when (entry) {
389+ is HomeRoute -> mapOf (" tab" to entry.id)
390+ is ProfileRoute -> mapOf (" userId" to entry.userId)
391+ else -> emptyMap()
392+ }
393+ }
394+ )
395+
396+ sut.onBackStackChanged(listOf (home, profile))
397+
398+ assertThat(argumentCalls[profile]).isEqualTo(1 )
399+ assertThat(argumentCalls[home]).isEqualTo(1 )
400+ }
401+
375402 @Test
376403 fun `onBackStackChanged creates a nav transaction when enabled and no ambient transaction is active` () {
377404 val fixture = Fixture ()
@@ -408,28 +435,24 @@ class BackStackObserverTest {
408435 }
409436
410437 @Test
411- fun `onBackStackChanged resolves top entry arguments once per update ` () {
438+ fun `onBackStackChanged preserves scope app fields on the nav transaction ` () {
412439 val fixture = Fixture ()
413- val home = HomeRoute ()
414- val profile = ProfileRoute (" 123" )
415- val argumentCalls = mutableMapOf<Any , Int >()
416- val sut =
417- fixture.getSut(
418- argumentsExtractor =
419- RouteArgumentsExtractor { entry ->
420- argumentCalls[entry] = (argumentCalls[entry] ? : 0 ) + 1
421- when (entry) {
422- is HomeRoute -> mapOf (" tab" to entry.id)
423- is ProfileRoute -> mapOf (" userId" to entry.userId)
424- else -> emptyMap()
425- }
426- }
427- )
440+ val scopeApp =
441+ App ().apply {
442+ appName = " Demo App"
443+ appIdentifier = " io.sentry.demo"
444+ }
445+ fixture.scope.contexts.setApp(scopeApp)
446+ val sut = fixture.getSut(config = ObserverConfig (enableScreenTracking = true ))
428447
429- sut.onBackStackChanged(listOf (home, profile ))
448+ sut.onBackStackChanged(listOf (HomeRoute (), ProfileRoute ( " 123 " ) ))
430449
431- assertThat(argumentCalls[profile]).isEqualTo(1 )
432- assertThat(argumentCalls[home]).isEqualTo(1 )
450+ val transactionApp = fixture.startedTransactions.single().contexts.app
451+ assertThat(transactionApp).isNotNull()
452+ assertThat(transactionApp).isNotSameInstanceAs(scopeApp)
453+ assertThat(transactionApp?.appName).isEqualTo(" Demo App" )
454+ assertThat(transactionApp?.appIdentifier).isEqualTo(" io.sentry.demo" )
455+ assertThat(transactionApp?.viewNames).isEqualTo(listOf (" /ProfileRoute" ))
433456 }
434457
435458 @Test
0 commit comments