11package io.embrace.android.embracesdk.testcases
22
33import androidx.test.ext.junit.runners.AndroidJUnit4
4- import io.embrace.android.embracesdk.assertions.findSpanOfType
5- import io.embrace.android.embracesdk.assertions.findSpanSnapshotOfType
64import io.embrace.android.embracesdk.assertions.findSpansByName
5+ import io.embrace.android.embracesdk.assertions.findSpansOfType
76import io.embrace.android.embracesdk.fakes.config.FakeInstrumentedConfig
87import io.embrace.android.embracesdk.fakes.config.FakeProjectConfig
98import io.embrace.android.embracesdk.internal.EmbraceInternalApi
109import io.embrace.android.embracesdk.internal.arch.schema.EmbType
1110import io.embrace.android.embracesdk.internal.arch.schema.toSessionPropertyAttributeName
1211import io.embrace.android.embracesdk.internal.clock.nanosToMillis
1312import io.embrace.android.embracesdk.internal.payload.AppFramework
13+ import io.embrace.android.embracesdk.internal.spans.findAttributeValue
1414import io.embrace.android.embracesdk.testframework.SdkIntegrationTestRule
1515import io.embrace.android.embracesdk.testframework.assertions.assertMatches
1616import org.junit.Assert.assertEquals
17+ import org.junit.Assert.assertNotNull
1718import org.junit.Assert.assertNull
1819import org.junit.Rule
1920import org.junit.Test
@@ -25,10 +26,12 @@ import org.junit.runner.RunWith
2526@RunWith(AndroidJUnit4 ::class )
2627internal class ReactNativeInternalInterfaceTest {
2728
28- private val instrumentedConfig = FakeInstrumentedConfig (project = FakeProjectConfig (
29- appId = " abcde" ,
30- appFramework = " react_native"
31- ))
29+ private val instrumentedConfig = FakeInstrumentedConfig (
30+ project = FakeProjectConfig (
31+ appId = " abcde" ,
32+ appFramework = " react_native"
33+ )
34+ )
3235
3336 @Rule
3437 @JvmField
@@ -152,21 +155,19 @@ internal class ReactNativeInternalInterfaceTest {
152155 assertEquals(1000L , span.startTimeNanos?.nanosToMillis())
153156 assertEquals(5000L , span.endTimeNanos?.nanosToMillis())
154157
155- span.attributes?.assertMatches(mapOf (
156- " emb.type" to " sys.rn_action" ,
157- " name" to " MyAction" ,
158- " outcome" to " SUCCESS" ,
159- " payload_size" to " 100" ,
160- " key" .toSessionPropertyAttributeName() to " value" ,
161- ))
158+ span.attributes?.assertMatches(
159+ mapOf (
160+ " emb.type" to " sys.rn_action" ,
161+ " name" to " MyAction" ,
162+ " outcome" to " SUCCESS" ,
163+ " payload_size" to " 100" ,
164+ " key" .toSessionPropertyAttributeName() to " value" ,
165+ )
166+ )
162167 }
163168 )
164169 }
165170
166- /*
167- * The first view is logged and stored as a span, because we know that it ends when logRnView is called again.
168- * The second view is logged as a span snapshot, because we know that it ends when the session ends.
169- * */
170171 @Test
171172 fun `react native log RN view` () {
172173 testRule.runTest(
@@ -179,21 +180,9 @@ internal class ReactNativeInternalInterfaceTest {
179180 }
180181 },
181182 assertAction = {
182- val message = getSingleSessionEnvelope()
183- val firstSpan = message.findSpanOfType(EmbType .Ux .View )
184- val secondSpan = message.findSpanSnapshotOfType(EmbType .Ux .View )
185-
186- assertEquals(" emb-screen-view" , firstSpan.name)
187- firstSpan.attributes?.assertMatches(mapOf (
188- " emb.type" to " ux.view" ,
189- " view.name" to " HomeScreen" ,
190- ))
191-
192- assertEquals(" emb-screen-view" , secondSpan.name)
193- secondSpan.attributes?.assertMatches(mapOf (
194- " emb.type" to " ux.view" ,
195- " view.name" to " DetailsScreen" ,
196- ))
183+ val viewSpans = getSingleSessionEnvelope().findSpansOfType(EmbType .Ux .View )
184+ assertNotNull(viewSpans.single { it.attributes?.findAttributeValue(" view.name" ) == " HomeScreen" })
185+ assertNotNull(viewSpans.single { it.attributes?.findAttributeValue(" view.name" ) == " DetailsScreen" })
197186 }
198187 )
199188 }
@@ -214,20 +203,8 @@ internal class ReactNativeInternalInterfaceTest {
214203 }
215204 },
216205 assertAction = {
217- val message = getSingleSessionEnvelope()
218- val firstSpan = message.findSpanOfType(EmbType .Ux .View )
219- assertEquals(" emb-screen-view" , firstSpan.name)
220- firstSpan.attributes?.assertMatches(mapOf (
221- " emb.type" to " ux.view" ,
222- " view.name" to " HomeScreen" ,
223- ))
224-
225- val secondSpan = message.findSpanSnapshotOfType(EmbType .Ux .View )
226- assertEquals(" emb-screen-view" , secondSpan.name)
227- secondSpan.attributes?.assertMatches(mapOf (
228- " emb.type" to " ux.view" ,
229- " view.name" to " HomeScreen" ,
230- ))
206+ val viewSpans = getSingleSessionEnvelope().findSpansOfType(EmbType .Ux .View )
207+ assertEquals(2 , viewSpans.filter { it.attributes?.findAttributeValue(" view.name" ) == " HomeScreen" }.size)
231208 }
232209 )
233210 }
0 commit comments