-
-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modifier.sentryTag uses Modifier.Node (#4029)
* Modifier.sentryTag uses Modifier.Node * Update Changelog * Add UI test for SentryModifier * Make sentrymodifier a robolectric test * Remove redundant dep --------- Co-authored-by: Markus Hintersteiner <markus.hintersteiner@sentry.io> Co-authored-by: Roman Zavarnitsyn <rom4ek93@gmail.com>
- Loading branch information
1 parent
63342b7
commit 47a3903
Showing
5 changed files
with
107 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
sentry-compose/src/androidUnitTest/kotlin/io/sentry/compose/SentryModifierComposeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package io.sentry.compose | ||
|
||
import android.app.Application | ||
import android.content.ComponentName | ||
import androidx.activity.ComponentActivity | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.test.SemanticsMatcher | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import io.sentry.compose.SentryModifier.sentryTag | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TestWatcher | ||
import org.junit.runner.Description | ||
import org.junit.runner.RunWith | ||
import org.robolectric.Shadows | ||
import org.robolectric.annotation.Config | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@Config(sdk = [30]) | ||
class SentryModifierComposeTest { | ||
|
||
companion object { | ||
private const val TAG_VALUE = "ExampleTagValue" | ||
} | ||
|
||
// workaround for robolectric tests with composeRule | ||
// from https://github.com/robolectric/robolectric/pull/4736#issuecomment-1831034882 | ||
@get:Rule(order = 1) | ||
val addActivityToRobolectricRule = object : TestWatcher() { | ||
override fun starting(description: Description?) { | ||
super.starting(description) | ||
val appContext: Application = ApplicationProvider.getApplicationContext() | ||
Shadows.shadowOf(appContext.packageManager).addActivityIfNotPresent( | ||
ComponentName( | ||
appContext.packageName, | ||
ComponentActivity::class.java.name | ||
) | ||
) | ||
} | ||
} | ||
|
||
@get:Rule(order = 2) | ||
val rule = createComposeRule() | ||
|
||
@Test | ||
fun sentryModifierAppliesTag() { | ||
rule.setContent { | ||
Box(modifier = Modifier.sentryTag(TAG_VALUE)) | ||
} | ||
rule.onNode( | ||
SemanticsMatcher(TAG_VALUE) { | ||
it.config.find { (key, _) -> key.name == SentryModifier.TAG }?.value == TAG_VALUE | ||
} | ||
).assertExists() | ||
} | ||
} |