Skip to content

Commit f48cc81

Browse files
committed
Add tests on IntentResolver about external permalink.
1 parent 50b77a3 commit f48cc81

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

appnav/src/test/kotlin/io/element/android/appnav/intent/IntentResolverTest.kt

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import io.element.android.features.login.impl.oidc.OidcUrlParser
2727
import io.element.android.libraries.deeplink.DeepLinkCreator
2828
import io.element.android.libraries.deeplink.DeeplinkData
2929
import io.element.android.libraries.deeplink.DeeplinkParser
30+
import io.element.android.libraries.matrix.api.core.UserId
3031
import io.element.android.libraries.matrix.api.permalink.PermalinkData
3132
import io.element.android.libraries.matrix.test.A_ROOM_ID
3233
import io.element.android.libraries.matrix.test.A_SESSION_ID
@@ -165,9 +166,60 @@ class IntentResolverTest {
165166
}
166167
}
167168

169+
@Test
170+
fun `test resolve external permalink`() {
171+
val permalinkData = PermalinkData.UserLink(
172+
userId = UserId("@alice:matrix.org")
173+
)
174+
val sut = createIntentResolver(
175+
permalinkParserResult = { permalinkData }
176+
)
177+
val intent = Intent(RuntimeEnvironment.getApplication(), Activity::class.java).apply {
178+
action = Intent.ACTION_VIEW
179+
data = "https://matrix.to/#/@alice:matrix.org".toUri()
180+
}
181+
val result = sut.resolve(intent)
182+
assertThat(result).isEqualTo(
183+
ResolvedIntent.Permalink(
184+
permalinkData = permalinkData
185+
)
186+
)
187+
}
188+
189+
@Test
190+
fun `test resolve external permalink, FallbackLink should be ignored`() {
191+
val sut = createIntentResolver(
192+
permalinkParserResult = { PermalinkData.FallbackLink(Uri.parse("https://matrix.org")) }
193+
)
194+
val intent = Intent(RuntimeEnvironment.getApplication(), Activity::class.java).apply {
195+
action = Intent.ACTION_VIEW
196+
data = "https://matrix.to/#/@alice:matrix.org".toUri()
197+
}
198+
val result = sut.resolve(intent)
199+
assertThat(result).isNull()
200+
}
201+
202+
@Test
203+
fun `test resolve external permalink, invalid action`() {
204+
val permalinkData = PermalinkData.UserLink(
205+
userId = UserId("@alice:matrix.org")
206+
)
207+
val sut = createIntentResolver(
208+
permalinkParserResult = { permalinkData }
209+
)
210+
val intent = Intent(RuntimeEnvironment.getApplication(), Activity::class.java).apply {
211+
action = Intent.ACTION_SEND
212+
data = "https://matrix.to/invalid".toUri()
213+
}
214+
val result = sut.resolve(intent)
215+
assertThat(result).isNull()
216+
}
217+
168218
@Test
169219
fun `test resolve invalid`() {
170-
val sut = createIntentResolver()
220+
val sut = createIntentResolver(
221+
permalinkParserResult = { PermalinkData.FallbackLink(Uri.parse("https://matrix.org")) }
222+
)
171223
val intent = Intent(RuntimeEnvironment.getApplication(), Activity::class.java).apply {
172224
action = Intent.ACTION_VIEW
173225
data = "io.element:/invalid".toUri()
@@ -176,14 +228,16 @@ class IntentResolverTest {
176228
assertThat(result).isNull()
177229
}
178230

179-
private fun createIntentResolver(): IntentResolver {
231+
private fun createIntentResolver(
232+
permalinkParserResult: () -> PermalinkData = { throw NotImplementedError() }
233+
): IntentResolver {
180234
return IntentResolver(
181235
deeplinkParser = DeeplinkParser(),
182236
oidcIntentResolver = DefaultOidcIntentResolver(
183237
oidcUrlParser = OidcUrlParser()
184238
),
185239
permalinkParser = FakePermalinkParser(
186-
result = { PermalinkData.FallbackLink(Uri.parse("https://matrix.org")) }
240+
result = permalinkParserResult
187241
),
188242
)
189243
}

0 commit comments

Comments
 (0)