diff --git a/appnav/src/test/kotlin/io/element/android/appnav/intent/IntentResolverTest.kt b/appnav/src/test/kotlin/io/element/android/appnav/intent/IntentResolverTest.kt index fa588410dc..074009cacc 100644 --- a/appnav/src/test/kotlin/io/element/android/appnav/intent/IntentResolverTest.kt +++ b/appnav/src/test/kotlin/io/element/android/appnav/intent/IntentResolverTest.kt @@ -27,6 +27,7 @@ import io.element.android.features.login.impl.oidc.OidcUrlParser import io.element.android.libraries.deeplink.DeepLinkCreator import io.element.android.libraries.deeplink.DeeplinkData import io.element.android.libraries.deeplink.DeeplinkParser +import io.element.android.libraries.matrix.api.core.UserId import io.element.android.libraries.matrix.api.permalink.PermalinkData import io.element.android.libraries.matrix.test.A_ROOM_ID import io.element.android.libraries.matrix.test.A_SESSION_ID @@ -165,9 +166,60 @@ class IntentResolverTest { } } + @Test + fun `test resolve external permalink`() { + val permalinkData = PermalinkData.UserLink( + userId = UserId("@alice:matrix.org") + ) + val sut = createIntentResolver( + permalinkParserResult = { permalinkData } + ) + val intent = Intent(RuntimeEnvironment.getApplication(), Activity::class.java).apply { + action = Intent.ACTION_VIEW + data = "https://matrix.to/#/@alice:matrix.org".toUri() + } + val result = sut.resolve(intent) + assertThat(result).isEqualTo( + ResolvedIntent.Permalink( + permalinkData = permalinkData + ) + ) + } + + @Test + fun `test resolve external permalink, FallbackLink should be ignored`() { + val sut = createIntentResolver( + permalinkParserResult = { PermalinkData.FallbackLink(Uri.parse("https://matrix.org")) } + ) + val intent = Intent(RuntimeEnvironment.getApplication(), Activity::class.java).apply { + action = Intent.ACTION_VIEW + data = "https://matrix.to/#/@alice:matrix.org".toUri() + } + val result = sut.resolve(intent) + assertThat(result).isNull() + } + + @Test + fun `test resolve external permalink, invalid action`() { + val permalinkData = PermalinkData.UserLink( + userId = UserId("@alice:matrix.org") + ) + val sut = createIntentResolver( + permalinkParserResult = { permalinkData } + ) + val intent = Intent(RuntimeEnvironment.getApplication(), Activity::class.java).apply { + action = Intent.ACTION_SEND + data = "https://matrix.to/invalid".toUri() + } + val result = sut.resolve(intent) + assertThat(result).isNull() + } + @Test fun `test resolve invalid`() { - val sut = createIntentResolver() + val sut = createIntentResolver( + permalinkParserResult = { PermalinkData.FallbackLink(Uri.parse("https://matrix.org")) } + ) val intent = Intent(RuntimeEnvironment.getApplication(), Activity::class.java).apply { action = Intent.ACTION_VIEW data = "io.element:/invalid".toUri() @@ -176,14 +228,16 @@ class IntentResolverTest { assertThat(result).isNull() } - private fun createIntentResolver(): IntentResolver { + private fun createIntentResolver( + permalinkParserResult: () -> PermalinkData = { throw NotImplementedError() } + ): IntentResolver { return IntentResolver( deeplinkParser = DeeplinkParser(), oidcIntentResolver = DefaultOidcIntentResolver( oidcUrlParser = OidcUrlParser() ), permalinkParser = FakePermalinkParser( - result = { PermalinkData.FallbackLink(Uri.parse("https://matrix.org")) } + result = permalinkParserResult ), ) }