Add tests on IntentResolver about external permalink.
This commit is contained in:
parent
50b77a3cbe
commit
f48cc81434
1 changed files with 57 additions and 3 deletions
|
|
@ -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
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue