Modern Apps git

← Modern-Apps.git

communicate: add tests for DeepLinks slice 5/6 (root package A-L)

Commit
4cf0d1a8e559fa565522b4d5fb192983adb009e7
Author
Vayun Mathur <[email protected]>
When
2026-11-06 16:56 UTC (29 days ago)
Parents
ee04653
DeepLinks instruction coverage 61.5% -> 65.9% (merged report).
New: DeepLinksResolveSlice5Test (22 JVM tests: case-insensitive
scheme/host, mms variants, sms path fallback, blank-address guards,
WhatsApp phone/text precedence, signal fragment edge cases, data-class
equality/defaults) and DeepLinksParseSlice5Test (19 Robolectric tests:
parse() over real Intent/Uri incl. conversation-extras round-trip via
ConversationSpace.putExtras, extras-beat-URI precedence, bad/missing
line fallback, fromUri overload).
Note: Robolectric execution data is not captured in the merged .exec
(verified by dumping it: Robolectric-only classes absent), so the
Parse tests verify behavior but add 0% until the shared infra gap is
fixed (messaged to lead). Remainder: parse/fromConversationExtras/
fromUri need Intent/Uri (Robolectric or instrumented).

(cherry picked from commit 6d688796ea63a2dfd6ac10af5859270d7a19bc29)

Diff

communicate/src/test/java/com/vayunmathur/communicate/DeepLinksParseSlice5Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/DeepLinksParseSlice5Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/DeepLinksParseSlice5Test.ktnew file mode 100644index 0000000000..8925a85b8f--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/DeepLinksParseSlice5Test.kt@@ -0,0 +1,199 @@+package com.vayunmathur.communicate++import android.content.Intent+import android.net.Uri+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.communicate.data.CommunicateLine+import com.vayunmathur.communicate.notifications.ConversationSpace+import com.vayunmathur.communicate.notifications.ConversationTarget+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNull+import kotlin.test.assertTrue+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/**+ * Slice 5/6 (root package A-L): [DeepLinks.parse] over real [Intent]/[Uri] under Robolectric.+ *+ * `android.net.Uri` is a stub on the JVM, so these paths (`parse`, `fromUri`, `fromConversationExtras`)+ * have zero coverage from the JVM suite. Uses real `Uri.parse` strings plus the real+ * [ConversationSpace.putExtras] writer so the extras contract is verified end to end.+ */+@RunWith(RobolectricTestRunner::class)+class DeepLinksParseSlice5Test {++    private val context get() = ApplicationProvider.getApplicationContext<android.content.Context>()++    private fun intent(action: String, data: String, text: String? = null): Intent =+        Intent(action, Uri.parse(data)).apply {+            if (text != null) putExtra(Intent.EXTRA_TEXT, text)+        }++    @Test+    fun nullIntentReturnsNull() {+        assertNull(DeepLinks.parse(null))+    }++    @Test+    fun intentWithoutDataReturnsNull() {+        assertNull(DeepLinks.parse(Intent(Intent.ACTION_VIEW)))+    }++    @Test+    fun unsupportedActionIsIgnored() {+        assertNull(DeepLinks.parse(intent(Intent.ACTION_SEND, "smsto:+15551234567")))+    }++    @Test+    fun smsViewIntentParsesToSimLine() {+        val result = DeepLinks.parse(intent(Intent.ACTION_VIEW, "smsto:+15551234567"))+            as DeepLink.Conversation+        assertEquals("+15551234567", result.address)+        assertEquals(CommunicateLine.Sim, result.line)+    }++    @Test+    fun smsSendToIntentCarriesTheSharedText() {+        val result = DeepLinks.parse(intent(Intent.ACTION_SENDTO, "sms:+15551234567", text = "hi"))+            as DeepLink.Conversation+        assertEquals("hi", result.body)+    }++    @Test+    fun dialIntentMapsToSimLine() {+        val result = DeepLinks.parse(intent(Intent.ACTION_DIAL, "tel:+15551234567"))+            as DeepLink.Conversation+        assertEquals(CommunicateLine.Sim, result.line)+        assertEquals("+15551234567", result.address)+    }++    @Test+    fun callIntentMapsToSimLine() {+        val result = DeepLinks.parse(intent(Intent.ACTION_CALL, "tel:+15551234567"))+            as DeepLink.Conversation+        assertEquals(CommunicateLine.Sim, result.line)+    }++    @Test+    fun waMeViewIntentParsesToWhatsAppLine() {+        val result = DeepLinks.parse(intent(Intent.ACTION_VIEW, "https://wa.me/15551234567"))+            as DeepLink.Conversation+        assertEquals("+15551234567", result.address)+        assertEquals(CommunicateLine.WhatsApp, result.line)+    }++    @Test+    fun apiWhatsAppLinkCarriesPhoneAndTextQueryParams() {+        val result = DeepLinks.parse(+            intent(Intent.ACTION_VIEW, "https://api.whatsapp.com/send?phone=15551234567&text=hello"),+        ) as DeepLink.Conversation+        assertEquals("+15551234567", result.address)+        assertEquals("hello", result.body)+    }++    @Test+    fun signalMeLinkParsesFragmentNumber() {+        val result = DeepLinks.parse(intent(Intent.ACTION_VIEW, "https://signal.me/#p/+15551234567"))+            as DeepLink.Conversation+        assertEquals("+15551234567", result.address)+        assertEquals(CommunicateLine.Signal, result.line)+    }++    @Test+    fun whatsAppGroupInviteReturnsUnsupported() {+        assertTrue(+            DeepLinks.parse(intent(Intent.ACTION_VIEW, "https://chat.whatsapp.com/ABC123"))+                is DeepLink.UnsupportedGroupInvite,+        )+    }++    @Test+    fun unknownLinkReturnsNull() {+        assertNull(DeepLinks.parse(intent(Intent.ACTION_VIEW, "https://example.com/15551234567")))+    }++    @Test+    fun conversationExtrasRoundTripThroughPutExtras() {+        val target = ConversationTarget(+            line = CommunicateLine.WhatsApp,+            address = "+15551234567",+            remoteId = "remote-1",+            threadId = 42L,+            isGroup = true,+            title = "Group",+            personName = "Alice",+            subscriptionId = 3,+        )+        val tap = ConversationSpace.putExtras(+            Intent(context, MainActivity::class.java).setAction(Intent.ACTION_VIEW),+            target,+        )+        val result = DeepLinks.parse(tap) as DeepLink.Conversation+        assertEquals("+15551234567", result.address)+        assertEquals(CommunicateLine.WhatsApp, result.line)+        assertEquals("remote-1", result.remoteId)+        assertEquals(42L, result.threadId)+        assertEquals(true, result.isGroup)+        assertEquals("Group", result.groupTitle)+        assertEquals(3, result.subscriptionId)+    }++    @Test+    fun conversationExtrasWinOverDataUri() {+        val tap = ConversationSpace.putExtras(+            Intent(Intent.ACTION_VIEW, Uri.parse("https://wa.me/19998887777")),+            ConversationTarget(+                line = CommunicateLine.Sim,+                address = "+15551234567",+                personName = "Bob",+            ),+        )+        val result = DeepLinks.parse(tap) as DeepLink.Conversation+        assertEquals(CommunicateLine.Sim, result.line)+        assertEquals("+15551234567", result.address)+    }++    @Test+    fun conversationExtrasWithMissingLineFallsBackToUri() {+        val tap = Intent(Intent.ACTION_VIEW, Uri.parse("https://wa.me/15551234567"))+            .putExtra(ConversationSpace.EXTRA_ADDRESS, "+10000000000")+        val result = DeepLinks.parse(tap) as DeepLink.Conversation+        assertEquals(CommunicateLine.WhatsApp, result.line)+        assertEquals("+15551234567", result.address)+    }++    @Test+    fun conversationExtrasWithBadLineNameFallsBackToUri() {+        val tap = Intent(Intent.ACTION_VIEW, Uri.parse("smsto:+15551234567"))+            .putExtra(ConversationSpace.EXTRA_LINE, "NotALine")+        val result = DeepLinks.parse(tap) as DeepLink.Conversation+        assertEquals(CommunicateLine.Sim, result.line)+    }++    @Test+    fun conversationExtrasWithoutSubIdLeaveItNull() {+        val tap = Intent(Intent.ACTION_VIEW)+            .putExtra(ConversationSpace.EXTRA_LINE, CommunicateLine.Signal.name)+            .putExtra(ConversationSpace.EXTRA_ADDRESS, "+15551234567")+        val result = DeepLinks.parse(tap) as DeepLink.Conversation+        assertEquals(CommunicateLine.Signal, result.line)+        assertEquals("+15551234567", result.address)+        assertEquals(null, result.subscriptionId)+        assertEquals(-1L, result.threadId)+        assertEquals(false, result.isGroup)+        assertEquals(null, result.groupTitle)+        assertEquals(null, result.remoteId)+    }++    @Test+    fun fromUriDefaultOverloadWorks() {+        val result = DeepLinks.fromUri(Uri.parse("smsto:+15551234567")) as DeepLink.Conversation+        assertEquals("+15551234567", result.address)+    }++    @Test+    fun fromUriWithUnknownSchemeReturnsNull() {+        assertNull(DeepLinks.fromUri(Uri.parse("https://example.com/x")))+    }+}
communicate/src/test/java/com/vayunmathur/communicate/DeepLinksResolveSlice5Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/DeepLinksResolveSlice5Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/DeepLinksResolveSlice5Test.ktnew file mode 100644index 0000000000..1a5f21d410--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/DeepLinksResolveSlice5Test.kt@@ -0,0 +1,196 @@+package com.vayunmathur.communicate++import com.vayunmathur.communicate.data.CommunicateLine+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNull+import kotlin.test.assertTrue++/**+ * Slice 5/6 (root package A-L): edge branches of [DeepLinks.resolve] not covered by [DeepLinksTest].+ *+ * Drives the component-based parser directly, since `android.net.Uri` is a stub on the JVM.+ */+class DeepLinksResolveSlice5Test {+    @Test+    fun parseOfNullIntentReturnsNull() {+        // The only `parse` branch reachable without Android framework classes.+        assertNull(DeepLinks.parse(null))+    }++    private fun link(+        scheme: String? = "https",+        host: String? = null,+        path: String? = null,+        fragment: String? = null,+        opaque: String? = null,+        params: Map<String, String> = emptyMap(),+        body: String? = null,+    ) = DeepLinks.resolve(+        scheme = scheme,+        host = host,+        path = path,+        fragment = fragment,+        opaque = opaque,+        query = { params[it] },+        body = body,+    )++    @Test+    fun schemeMatchingIsCaseInsensitive() {+        val result = link(scheme = "SMSTO", opaque = "+15551234567") as DeepLink.Conversation+        assertEquals(CommunicateLine.Sim, result.line)+        assertEquals("+15551234567", result.address)+    }++    @Test+    fun hostMatchingIsCaseInsensitive() {+        val result = link(host = "WA.ME", path = "/15551234567") as DeepLink.Conversation+        assertEquals(CommunicateLine.WhatsApp, result.line)+        assertEquals("+15551234567", result.address)+    }++    @Test+    fun mmsSchemesMapToTheSimLine() {+        for (scheme in listOf("mms", "mmsto", "sms")) {+            val result = link(scheme = scheme, opaque = "+15551234567") as DeepLink.Conversation+            assertEquals(CommunicateLine.Sim, result.line, "scheme $scheme")+        }+    }++    @Test+    fun smsFallsBackToPathWhenOpaqueIsNull() {+        // The path fallback keeps the leading slash as-is (opaque is the normal carrier for sms: URIs).+        val result = link(scheme = "sms", opaque = null, path = "/+15551234567") as DeepLink.Conversation+        assertEquals("/+15551234567", result.address)+    }++    @Test+    fun smsWithNeitherOpaqueNorPathIsIgnored() {+        assertNull(link(scheme = "sms", opaque = null, path = null))+    }++    @Test+    fun smsWithBlankAddressIsIgnored() {+        assertNull(link(scheme = "sms", opaque = "   "))+    }++    @Test+    fun smsBodyExtraIsCarriedAsTheDraft() {+        val result = link(scheme = "sms", opaque = "+15551234567", body = "hello") as DeepLink.Conversation+        assertEquals("hello", result.body)+    }++    @Test+    fun whatsAppBlankPhoneParamFallsBackToPath() {+        val result = link(+            host = "api.whatsapp.com",+            path = "/15551234567",+            params = mapOf("phone" to "   "),+        ) as DeepLink.Conversation+        assertEquals("+15551234567", result.address)+    }++    @Test+    fun whatsAppWithNoNumberAnywhereIsIgnored() {+        assertNull(link(host = "wa.me", path = "/send"))+        assertNull(link(host = "api.whatsapp.com", path = "/send"))+    }++    @Test+    fun whatsAppQueryTextBeatsTheShareBody() {+        val result = link(+            host = "wa.me",+            path = "/15551234567",+            params = mapOf("text" to "from-link"),+            body = "from-share",+        ) as DeepLink.Conversation+        assertEquals("from-link", result.body)+    }++    @Test+    fun whatsAppFallsBackToShareBodyWithoutQueryText() {+        val result = link(+            host = "wa.me",+            path = "/15551234567",+            body = "from-share",+        ) as DeepLink.Conversation+        assertEquals("from-share", result.body)+    }++    @Test+    fun whatsAppPhoneWithNoDigitsNormalisesToEmpty() {+        val result = link(+            host = "api.whatsapp.com",+            path = "/send",+            params = mapOf("phone" to "!!!"),+        ) as DeepLink.Conversation+        assertEquals("", result.address)+    }++    @Test+    fun signalWithNoDigitsInFragmentIsIgnored() {+        assertNull(link(host = "signal.me", fragment = "p/abc"))+    }++    @Test+    fun signalWithNullFragmentIsIgnored() {+        assertNull(link(host = "signal.me", fragment = null))+    }++    @Test+    fun signalFragmentWithoutPrefixStillParses() {+        val result = link(host = "signal.me", fragment = "+15551234567") as DeepLink.Conversation+        assertEquals("+15551234567", result.address)+        assertEquals(CommunicateLine.Signal, result.line)+    }++    @Test+    fun signalCarriesTheShareBody() {+        val result = link(+            host = "signal.me",+            fragment = "p/+15551234567",+            body = "hi",+        ) as DeepLink.Conversation+        assertEquals("hi", result.body)+    }++    @Test+    fun nullSchemeWithUnknownHostIsIgnored() {+        assertNull(link(scheme = null, host = "example.com", path = "/x"))+        assertNull(link(scheme = "ftp", host = "example.com", path = "/x"))+    }++    @Test+    fun unsupportedGroupInvitesCarryTheRightLine() {+        val wa = link(host = "chat.whatsapp.com", path = "/ABC") as DeepLink.UnsupportedGroupInvite+        assertEquals(CommunicateLine.WhatsApp, wa.line)+        val signal = link(host = "signal.group") as DeepLink.UnsupportedGroupInvite+        assertEquals(CommunicateLine.Signal, signal.line)+    }++    @Test+    fun telWithEmptyOpaqueIsIgnored() {+        assertNull(link(scheme = "tel", opaque = ""))+    }++    @Test+    fun conversationDefaultsAreSane() {+        val convo = DeepLink.Conversation(address = "x", line = CommunicateLine.Sim)+        assertEquals(null, convo.body)+        assertEquals(null, convo.remoteId)+        assertEquals(-1L, convo.threadId)+        assertEquals(false, convo.isGroup)+        assertEquals(null, convo.groupTitle)+        assertEquals(null, convo.subscriptionId)+    }++    @Test+    fun conversationAndInviteAreDistinctDeepLinks() {+        val convo: DeepLink = DeepLink.Conversation(address = "x", line = CommunicateLine.Sim)+        val invite: DeepLink = DeepLink.UnsupportedGroupInvite(CommunicateLine.Signal)+        assertTrue(convo is DeepLink.Conversation)+        assertTrue(invite is DeepLink.UnsupportedGroupInvite)+        assertEquals(convo, DeepLink.Conversation(address = "x", line = CommunicateLine.Sim))+    }+}