communicate: add tests for DeepLinks slice 5/6 pass 2
- Commit
88db4ade468c6d045ffbf3cd22d26dbf9ff5d289- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 06:42 UTC (29 days ago)
- Parents
65ab24e
Second pass over the root-package A-L slice (DeepLinks.kt only; MainActivity.kt is slice 6/6). Re-measured on current main first: the first pass reported 409/621 on DeepLinks because Robolectric exec data was missing from the merged report. That infra gap is fixed on main, and the same tests now measure 608/621. The new pass-2 tests close the remaining branches, taking the slice to 100%: - DeepLinks 608/621 -> 621/621 instructions - DeepLink.Conversation 92/92, DeepLink.UnsupportedGroupInvite 9/9 - Slice total 722/722 = 100% (target >=85%) DeepLinksPass2Slice5Test (19 tests) covers: conversation extras with a missing address (orEmpty branch), negative vs zero subscription ids, lower-case line names rejected by valueOf, GoogleVoice extras; opaque whatsapp: URIs whose query accessor throws (the runCatching in fromUri), sgnl:// signal links, signal.group invites, action-less intents, decoded wa.me text; and resolve branches for null WhatsApp paths, upper-case invite hosts, TEL case/trimming, query-only sms opaque parts, signal fragment trimming, and mixed letter/digit number normalisation. Bugs fixed: none. Untestable remainder: none in this slice. Verified: gslot ./gradlew :communicate:testDevUnitTest (1018 tests, 0 failures) and :communicate:createMergedCoverageReport. (cherry picked from commit 0473020425042cbb04fb13be25cfc8c426d32017)
Diff
communicate/src/test/java/com/vayunmathur/communicate/DeepLinksPass2Slice5Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/DeepLinksPass2Slice5Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/DeepLinksPass2Slice5Test.ktnew file mode 100644index 0000000000..5710606aff--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/DeepLinksPass2Slice5Test.kt@@ -0,0 +1,222 @@+package com.vayunmathur.communicate++import android.content.Intent+import android.net.Uri+import com.vayunmathur.communicate.data.CommunicateLine+import com.vayunmathur.communicate.notifications.ConversationSpace+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), second pass: the branches the first pass left in [DeepLinks].+ *+ * The Robolectric exec data now reaches the merged report, so `parse` / `fromUri` /+ * `fromConversationExtras` are covered here directly: a missing address extra, a negative+ * subscription id, a lower-case line name, and an opaque `whatsapp:` URI whose query accessor+ * throws (the `runCatching` in `fromUri`'s query lambda). The rest drive [DeepLinks.resolve]+ * over plain components for the null-path and case branches.+ */+@RunWith(RobolectricTestRunner::class)+class DeepLinksPass2Slice5Test {++ 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,+ )++ // ---- fromConversationExtras branches (via parse) ----++ @Test+ fun extrasWithoutAddressDefaultToEmptyAddress() {+ val tap = Intent(Intent.ACTION_VIEW)+ .putExtra(ConversationSpace.EXTRA_LINE, CommunicateLine.Rcs.name)+ val result = DeepLinks.parse(tap) as DeepLink.Conversation+ assertEquals("", result.address)+ assertEquals(CommunicateLine.Rcs, result.line)+ assertNull(result.remoteId)+ assertNull(result.subscriptionId)+ }++ @Test+ fun extrasWithNegativeSubIdLeaveItNullButZeroIsKept() {+ val negative = Intent(Intent.ACTION_VIEW)+ .putExtra(ConversationSpace.EXTRA_LINE, CommunicateLine.Sim.name)+ .putExtra(ConversationSpace.EXTRA_ADDRESS, "+15551234567")+ .putExtra(ConversationSpace.EXTRA_SUB_ID, -5)+ assertNull((DeepLinks.parse(negative) as DeepLink.Conversation).subscriptionId)++ val zero = Intent(Intent.ACTION_VIEW)+ .putExtra(ConversationSpace.EXTRA_LINE, CommunicateLine.Sim.name)+ .putExtra(ConversationSpace.EXTRA_ADDRESS, "+15551234567")+ .putExtra(ConversationSpace.EXTRA_SUB_ID, 0)+ assertEquals(0, (DeepLinks.parse(zero) as DeepLink.Conversation).subscriptionId)+ }++ @Test+ fun extrasWithLowerCaseLineNameAreRejected() {+ // valueOf is case-sensitive: a lower-case line extra is not a conversation extra,+ // so parsing falls through to the (absent) data URI and returns null.+ val tap = Intent(Intent.ACTION_VIEW)+ .putExtra(ConversationSpace.EXTRA_LINE, "sim")+ .putExtra(ConversationSpace.EXTRA_ADDRESS, "+15551234567")+ assertNull(DeepLinks.parse(tap))+ }++ @Test+ fun extrasForGoogleVoiceLineParse() {+ val tap = Intent(Intent.ACTION_VIEW)+ .putExtra(ConversationSpace.EXTRA_LINE, CommunicateLine.GoogleVoice.name)+ .putExtra(ConversationSpace.EXTRA_ADDRESS, "+15551234567")+ .putExtra(ConversationSpace.EXTRA_THREAD_ID, 7L)+ .putExtra(ConversationSpace.EXTRA_IS_GROUP, true)+ .putExtra(ConversationSpace.EXTRA_TITLE, "Team")+ val result = DeepLinks.parse(tap) as DeepLink.Conversation+ assertEquals(CommunicateLine.GoogleVoice, result.line)+ assertEquals(7L, result.threadId)+ assertTrue(result.isGroup)+ assertEquals("Team", result.groupTitle)+ }++ // ---- parse / fromUri over real Uris ----++ @Test+ fun opaqueWhatsAppUriReturnsNullInsteadOfThrowing() {+ // An opaque URI has no query accessor: getQueryParameter throws, fromUri's+ // runCatching turns that into a null phone, and there is no path to fall back to.+ assertNull(DeepLinks.fromUri(Uri.parse("whatsapp:send?phone=15551234567")))+ }++ @Test+ fun sgnlSchemeSignalLinkParsesFragmentNumber() {+ val result = DeepLinks.fromUri(Uri.parse("sgnl://signal.me/#p/15551234567"))+ as DeepLink.Conversation+ assertEquals("+15551234567", result.address)+ assertEquals(CommunicateLine.Signal, result.line)+ }++ @Test+ fun signalGroupHostReturnsUnsupportedInvite() {+ val result = DeepLinks.parse(+ Intent(Intent.ACTION_VIEW, Uri.parse("https://signal.group/#CjQK"))+ )+ assertEquals(DeepLink.UnsupportedGroupInvite(CommunicateLine.Signal), result)+ }++ @Test+ fun intentWithoutActionIgnoresItsData() {+ val intent = Intent().apply { data = Uri.parse("smsto:+15551234567") }+ assertNull(DeepLinks.parse(intent))+ }++ @Test+ fun waMeTextQueryIsDecodedAndBeatsExtraText() {+ val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://wa.me/15551234567?text=hello%20there"))+ .putExtra(Intent.EXTRA_TEXT, "from-share")+ val result = DeepLinks.parse(intent) as DeepLink.Conversation+ assertEquals("hello there", result.body)+ }++ @Test+ fun smsUriWithQueryBodyKeepsOnlyTheNumber() {+ val result = DeepLinks.fromUri(Uri.parse("sms:+15551234567?body=hi"))+ as DeepLink.Conversation+ assertEquals("+15551234567", result.address)+ assertNull(result.body)+ }++ // ---- resolve: null-path, case and trimming branches ----++ @Test+ fun whatsAppWithNullPathAndNoPhoneIsIgnored() {+ assertNull(link(host = "wa.me", path = null))+ assertNull(link(host = "api.whatsapp.com", path = null, params = mapOf("phone" to " ")))+ }++ @Test+ fun whatsAppWithNullPathUsesPhoneParam() {+ val result = link(+ host = "api.whatsapp.com", path = null,+ params = mapOf("phone" to "+1 (555) 123-4567"),+ ) as DeepLink.Conversation+ assertEquals("+15551234567", result.address)+ }++ @Test+ fun groupInviteHostsAreCaseInsensitive() {+ assertEquals(+ DeepLink.UnsupportedGroupInvite(CommunicateLine.WhatsApp),+ link(host = "CHAT.WHATSAPP.COM", path = "/ABC"),+ )+ assertEquals(+ DeepLink.UnsupportedGroupInvite(CommunicateLine.Signal),+ link(host = "SIGNAL.GROUP"),+ )+ }++ @Test+ fun telSchemeIsCaseInsensitiveAndTrimsAddress() {+ val result = link(scheme = "TEL", opaque = " +15551234567 ") as DeepLink.Conversation+ assertEquals("+15551234567", result.address)+ assertEquals(CommunicateLine.Sim, result.line)+ }++ @Test+ fun smsWithOnlyAQueryInTheOpaquePartIsIgnored() {+ assertNull(link(scheme = "sms", opaque = "?body=hi"))+ assertNull(link(scheme = "sms", opaque = ""))+ }++ @Test+ fun signalFragmentIsTrimmedAroundThePrefix() {+ val result = link(host = "signal.me", fragment = " p/+1 (555) 123-4567 ")+ as DeepLink.Conversation+ assertEquals("+15551234567", result.address)+ assertNull(link(host = "signal.me", fragment = "p/"))+ assertNull(link(host = "signal.me", fragment = " "))+ }++ @Test+ fun whatsAppPathMixingLettersAndDigitsIsNormalised() {+ val result = link(host = "wa.me", path = "/call-15551234567/") as DeepLink.Conversation+ assertEquals("+15551234567", result.address)+ }++ @Test+ fun resolveWithEverythingNullIsIgnored() {+ assertNull(+ DeepLinks.resolve(+ scheme = null, host = null, path = null,+ fragment = null, opaque = null, query = { null },+ )+ )+ }++ @Test+ fun conversationCopyAndInviteEquality() {+ val convo = DeepLink.Conversation("+1555", CommunicateLine.Sim, body = "hi")+ assertEquals(convo, convo.copy())+ assertEquals("+1555", convo.copy(address = "+1555").address)+ assertTrue(convo.toString().contains("+1555"))+ assertEquals(+ DeepLink.UnsupportedGroupInvite(CommunicateLine.WhatsApp),+ DeepLink.UnsupportedGroupInvite(CommunicateLine.WhatsApp).copy(),+ )+ }+}