communicate: add UiPass3 tests for screens, bubbles, picker and RCS
- Commit
da1b5526a7afcfa073333751f03ed1826c60b93a- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 13:57 UTC (28 days ago)
- Parents
169841a
Third coverage pass over the ui/service/notifications/domain slice. Slice INSTRUCTION coverage rises from 28.85% (13088/45365) to 63.52% (29074/45770); module merged coverage rises from 43.88% to 50.93% (119408/234472), measured with gslot ./gradlew :communicate:createMergedCoverageReport. Full unit suite green: 1319 tests, 0 failures. Tests (12 new *UiPass3Test files, 117 cases): shared helpers (initials, group titles, date formatting, permission helpers), LineTag/ThreadAvatar/UnreadBadge/status ticks, PermissionGate and RoleGate states, LineSelector and DialPad interactions; stateless CallLogs/Messages/Voicemail contents with delete-confirm flows and per-type duration labels; message bubbles (revoked/edited/quoted/poll/reactions/sender labels, attachment rows), messages-list states, safety-number and encryption banners; DialerContent T9 filtering and place-call taps; Accounts screen (SIM/GV/Signal/RCS/WhatsApp cards and callbacks) and the first steps of the WhatsApp/Signal registration flows plus backup import; PollComposer create/trim/add/remove rules; ContactIntents blank no-ops and readSharedContact against a fake contacts provider; NewMessagePicker chrome, group mode and number formatting; ConversationTitle/Actions (RCS verify/members callbacks, delete-confirm), ComposeSmsRow send gating and attach menu, RCS encryption banner and peer-typing no-ops via the in-memory RcsDatabase test seam; top-level screens in gated states, the FAB-to-picker compose flow, ConversationScreen composition and send-clears-draft, VoicemailPlayer composition, and CallVideo with no controller / null EGL context. 85% was not reached: the remaining slice misses are classes that cannot run on the JVM - the three Car App Library screens (need a CarContext host), the WebView sign-in/captcha screens, the post-number registration steps (advancing them calls the real WhatsApp/Signal/carrier servers, which tests must never touch), the WebRTC video renderers (need a native EGL context), the role-held bodies of the gated screens (Robolectric 4.17 has no ShadowRoleManager; their stateless contents are covered directly instead), and picker-result lambdas that need a real contact/document picker. (cherry picked from commit 0e535e97c178307e3633da751416d778ee4ee72b)
Diff
communicate/src/test/java/com/vayunmathur/communicate/ui/AccountsUiPass3Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/ui/AccountsUiPass3Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/ui/AccountsUiPass3Test.ktnew file mode 100644index 0000000000..b35ce831c4--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/ui/AccountsUiPass3Test.kt@@ -0,0 +1,150 @@+package com.vayunmathur.communicate.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.assertIsEnabled+import androidx.compose.ui.test.assertIsNotEnabled+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onAllNodesWithText+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.compose.ui.test.performScrollTo+import androidx.compose.ui.test.performTextInput+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.communicate.R+import kotlin.test.Test+import kotlin.test.assertEquals+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/**+ * UiPass3 coverage for account + registration screens: [AccountsScreen]+ * signed-out state, and the first step of the WhatsApp/Signal registration+ * flows (typing a number must never touch the network — buttons are only+ * asserted enabled/disabled, never pressed past the request step).+ */+@RunWith(RobolectricTestRunner::class)+class AccountsUiPass3Test {++ @get:Rule+ val rule = createComposeRule()++ private val context: android.content.Context+ get() = ApplicationProvider.getApplicationContext()++ private fun str(id: Int): String = context.getString(id)++ @Test+ fun `accounts shows sim and signed-out google voice`() {+ var signIns = 0+ rule.setContent {+ AccountsScreen(onBack = {}, onSignIn = { signIns++ })+ }+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.accounts_title)).assertIsDisplayed()+ rule.onAllNodesWithText(str(R.string.account_sim)).fetchSemanticsNodes()+ .let { assertEquals(true, it.isNotEmpty()) }+ rule.onNodeWithText(str(R.string.account_google_voice)).assertIsDisplayed()+ rule.onNodeWithText(str(R.string.gv_not_signed_in)).assertIsDisplayed()+ rule.onNodeWithText(str(R.string.gv_sign_in)).performClick()+ rule.waitForIdle()+ assertEquals(1, signIns)+ }++ @Test+ fun `accounts offers whatsapp registration when signed out`() {+ var registers = 0+ var imports = 0+ rule.setContent {+ AccountsScreen(+ onBack = {},+ onSignIn = {},+ onRegisterWhatsApp = { registers++ },+ onImportBackup = { imports++ },+ )+ }+ rule.waitForIdle()+ rule.onNodeWithText("WhatsApp").assertExists()+ rule.onAllNodesWithText("Not registered").fetchSemanticsNodes()+ .let { assertEquals(true, it.isNotEmpty()) }+ // Signal's Register comes first; WhatsApp's is the second one.+ rule.onAllNodesWithText("Register")[1].performScrollTo().performClick()+ rule.onNodeWithText("Import backup (.crypt15)").performScrollTo().performClick()+ rule.waitForIdle()+ assertEquals(1, registers)+ assertEquals(1, imports)+ }++ @Test+ fun `accounts rcs status and signal register report`() {+ var rcsStatus = 0+ var signalRegisters = 0+ rule.setContent {+ AccountsScreen(+ onBack = {}, onSignIn = {},+ onRegisterSignal = { signalRegisters++ },+ onShowRcsStatus = { rcsStatus++ },+ )+ }+ rule.waitForIdle()+ rule.onNodeWithText("Status").performScrollTo().performClick()+ rule.onAllNodesWithText("Register")[0].performScrollTo().performClick()+ rule.waitForIdle()+ assertEquals(1, rcsStatus)+ assertEquals(1, signalRegisters)+ }++ @Test+ fun `whatsapp registration starts at the number step`() {+ rule.setContent {+ com.vayunmathur.communicate.ui.whatsapp.WhatsAppRegistrationScreen(+ onBack = {}, onRegistered = {},+ )+ }+ rule.waitForIdle()+ rule.onNodeWithText("Register WhatsApp").assertIsDisplayed()+ rule.onNodeWithText("Phone number").assertIsDisplayed()+ rule.onNodeWithText("Request SMS code").assertIsNotEnabled()+ rule.onNodeWithText("Phone number").performTextInput("5550100")+ rule.waitForIdle()+ rule.onNodeWithText("Request SMS code").assertIsEnabled()+ }++ @Test+ fun `whatsapp registration filters non-digits from the number`() {+ rule.setContent {+ com.vayunmathur.communicate.ui.whatsapp.WhatsAppRegistrationScreen(+ onBack = {}, onRegistered = {},+ )+ }+ rule.onNodeWithText("Phone number").performTextInput("55a5")+ rule.waitForIdle()+ rule.onNodeWithText("555").assertIsDisplayed()+ rule.onNodeWithText("55a5").assertDoesNotExist()+ }++ @Test+ fun `signal registration starts at the number step`() {+ rule.setContent {+ com.vayunmathur.communicate.ui.signal.SignalRegistrationScreen(+ onBack = {}, onRegistered = {},+ )+ }+ rule.waitForIdle()+ rule.onNodeWithText("Register Signal").assertIsDisplayed()+ rule.onNodeWithText("Phone number").assertIsDisplayed()+ rule.onNodeWithText("Request SMS code").assertIsNotEnabled()+ rule.onNodeWithText("Phone number").performTextInput("5550100")+ rule.waitForIdle()+ rule.onNodeWithText("Request SMS code").assertIsEnabled()+ }++ @Test+ fun `backup import screen explains and idles without a key`() {+ rule.setContent {+ com.vayunmathur.communicate.ui.whatsapp.WhatsAppBackupImportScreen(onBack = {})+ }+ rule.waitForIdle()+ rule.onNodeWithText("Import WhatsApp backup", substring = true).assertIsDisplayed()+ }+}
communicate/src/test/java/com/vayunmathur/communicate/ui/CallLogsUiPass3Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/ui/CallLogsUiPass3Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/ui/CallLogsUiPass3Test.ktnew file mode 100644index 0000000000..e85fa15de7--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/ui/CallLogsUiPass3Test.kt@@ -0,0 +1,148 @@+package com.vayunmathur.communicate.ui++import androidx.compose.runtime.getValue+import androidx.compose.runtime.setValue+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.hasClickAction+import androidx.compose.ui.test.hasContentDescriptionExactly+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.communicate.R+import com.vayunmathur.communicate.data.CommunicateCallLogEntry+import com.vayunmathur.communicate.data.CommunicateCallType+import com.vayunmathur.communicate.data.CommunicateLine+import kotlin.test.Test+import kotlin.test.assertEquals+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/**+ * UiPass3 coverage for the call-log list (`CallLogsScreen.kt`): stateless+ * [CallLogsContent] rows, duration/type labels and the delete-confirm flow.+ */+@RunWith(RobolectricTestRunner::class)+class CallLogsUiPass3Test {++ @get:Rule+ val rule = createComposeRule()++ private val context: android.content.Context+ get() = ApplicationProvider.getApplicationContext()++ private fun str(id: Int): String = context.getString(id)++ private fun entry(+ id: Long = 1L,+ name: String? = "Pat Lee",+ number: String = "+1555",+ type: CommunicateCallType = CommunicateCallType.Incoming,+ duration: Long = 65L,+ line: CommunicateLine = CommunicateLine.Sim,+ ) = CommunicateCallLogEntry(+ id = id,+ displayName = name,+ phoneNumber = number,+ type = type,+ timestampMillis = System.currentTimeMillis(),+ durationSeconds = duration,+ line = line,+ )++ @Test+ fun `rows show name number and duration and call back on tap`() {+ val called = mutableListOf<CommunicateCallLogEntry>()+ val e = entry()+ rule.setContent {+ CallLogsContent(entries = listOf(e), onCall = { called.add(it) }, onDelete = {})+ }+ rule.onNodeWithText("Pat Lee").assertIsDisplayed()+ rule.onNodeWithText("+1555").assertIsDisplayed()+ rule.onNodeWithText("Pat Lee").performClick()+ rule.waitForIdle()+ assertEquals(listOf(e), called)+ }++ @Test+ fun `unnamed rows fall back to the number as title`() {+ rule.setContent {+ CallLogsContent(entries = listOf(entry(name = null)), onCall = {}, onDelete = {})+ }+ rule.onNodeWithText("+1555").assertIsDisplayed()+ }++ @Test+ fun `every call type renders its label`() {+ // One row, re-composed per type so every label branch renders.+ var type by androidx.compose.runtime.mutableStateOf(CommunicateCallType.Incoming)+ rule.setContent {+ CallLogsContent(entries = listOf(entry(type = type, duration = 0L)), onCall = {}, onDelete = {})+ }+ val labels = mapOf(+ CommunicateCallType.Incoming to R.string.incoming_call,+ CommunicateCallType.Outgoing to R.string.outgoing_call,+ CommunicateCallType.Missed to R.string.missed_call,+ CommunicateCallType.Rejected to R.string.rejected_call,+ CommunicateCallType.Blocked to R.string.blocked_call,+ CommunicateCallType.Voicemail to R.string.voicemail_call,+ CommunicateCallType.Unknown to R.string.unknown_call,+ )+ for ((t, labelRes) in labels) {+ rule.runOnIdle { type = t }+ rule.waitForIdle()+ rule.onNodeWithText(str(labelRes), substring = true).assertExists()+ }+ }++ @Test+ fun `long durations render hours and minutes`() {+ rule.setContent {+ CallLogsContent(+ entries = listOf(entry(duration = 3661L)),+ onCall = {}, onDelete = {},+ )+ }+ // 1 hr 1 min (seconds dropped past the hour).+ rule.onNodeWithText("1 hr", substring = true).assertIsDisplayed()+ }++ @Test+ fun `delete asks first and only then deletes`() {+ val deleted = mutableListOf<CommunicateCallLogEntry>()+ val e = entry()+ rule.setContent {+ CallLogsContent(entries = listOf(e), onCall = {}, onDelete = { deleted.add(it) })+ }+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("More")).performClick()+ rule.onNodeWithText(str(com.vayunmathur.library.ui.R.string.delete)).performClick()+ rule.onNodeWithText(str(R.string.delete_call_log_title)).assertIsDisplayed()+ assertEquals(emptyList(), deleted)+ rule.onNodeWithText(str(com.vayunmathur.library.ui.R.string.delete)).performClick()+ rule.waitForIdle()+ assertEquals(listOf(e), deleted)+ }++ @Test+ fun `delete can be cancelled`() {+ val deleted = mutableListOf<CommunicateCallLogEntry>()+ rule.setContent {+ CallLogsContent(entries = listOf(entry()), onCall = {}, onDelete = { deleted.add(it) })+ }+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("More")).performClick()+ rule.onNodeWithText(str(com.vayunmathur.library.ui.R.string.delete)).performClick()+ rule.onNodeWithText(str(com.vayunmathur.library.ui.R.string.cancel)).performClick()+ rule.waitForIdle()+ assertEquals(emptyList(), deleted)+ rule.onNodeWithText(str(R.string.delete_call_log_title)).assertDoesNotExist()+ }++ @Test+ fun `empty list composes without rows`() {+ rule.setContent {+ CallLogsContent(entries = emptyList(), onCall = {}, onDelete = {})+ }+ rule.onNodeWithText("Pat Lee").assertDoesNotExist()+ }+}
communicate/src/test/java/com/vayunmathur/communicate/ui/CommunicateUiPass3Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/ui/CommunicateUiPass3Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/ui/CommunicateUiPass3Test.ktnew file mode 100644index 0000000000..942eaa0ff1--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/ui/CommunicateUiPass3Test.kt@@ -0,0 +1,261 @@+package com.vayunmathur.communicate.ui++import android.Manifest+import android.app.Application+import androidx.compose.runtime.getValue+import androidx.compose.runtime.setValue+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.assertIsEnabled+import androidx.compose.ui.test.assertIsNotEnabled+import androidx.compose.ui.test.hasClickAction+import androidx.compose.ui.test.hasContentDescriptionExactly+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.communicate.R+import com.vayunmathur.communicate.data.CommunicateLine+import com.vayunmathur.communicate.data.LineChoice+import com.vayunmathur.communicate.data.MessageStatus+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNull+import kotlin.test.assertTrue+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.Shadows++/**+ * UiPass3 coverage for the shared communicate UI helpers (`CommunicateUi.kt`,+ * `DialPad.kt`, thread rows): initials/group titles, status ticks, gates,+ * line selector and the dial pad.+ */+@RunWith(RobolectricTestRunner::class)+class CommunicateUiPass3Test {++ @get:Rule+ val rule = createComposeRule()++ private val context: android.content.Context+ get() = ApplicationProvider.getApplicationContext()++ private fun str(id: Int): String = context.getString(id)++ // -- pure helpers -------------------------------------------------------++ @Test+ fun `initials take the first two words`() {+ assertEquals("PL", initialsFor("Pat Lee"))+ assertEquals("P", initialsFor("Pat"))+ assertEquals("PL", initialsFor("pat lee"))+ assertEquals("?", initialsFor(""))+ assertEquals("?", initialsFor(" "))+ assertEquals("15", initialsFor("+1 555"))+ assertEquals("AB", initialsFor("a-b_c"))+ }++ @Test+ fun `group title lists two names then counts the rest`() {+ assertNull(groupTitleFromParticipants(emptyList()))+ assertEquals("Alice", groupTitleFromParticipants(listOf("Alice")))+ assertEquals("Alice, Bob", groupTitleFromParticipants(listOf("Alice", "Bob")))+ assertEquals("Alice, Bob +2", groupTitleFromParticipants(listOf("Alice", "Bob", "Cid", "Dee")))+ }++ @Test+ fun `formatDateTime renders today and old dates`() {+ val now = System.currentTimeMillis()+ assertTrue(formatDateTime(context, now).isNotBlank())+ assertTrue(formatDateTime(context, now - 3L * 24 * 3600 * 1000).isNotBlank())+ assertTrue(formatDateTime(context, now - 40L * 24 * 3600 * 1000).isNotBlank())+ }++ @Test+ fun `permission helpers reflect grants`() {+ assertEquals(false, context.hasContactsPermission())+ Shadows.shadowOf(context as Application).grantPermissions(Manifest.permission.READ_CONTACTS)+ assertEquals(true, context.hasContactsPermission())+ assertEquals(true, context.hasCommunicatePermission(Manifest.permission.READ_CONTACTS))+ }++ // -- small composables --------------------------------------------------++ @Test+ fun `line tag hides blank and shows text`() {+ var tag by androidx.compose.runtime.mutableStateOf<String?>(null)+ rule.setContent { LineTag(tag) }+ rule.onNodeWithText("SIM 1").assertDoesNotExist()+ rule.runOnIdle { tag = "SIM 1" }+ rule.waitForIdle()+ rule.onNodeWithText("SIM 1").assertIsDisplayed()+ rule.runOnIdle { tag = " " }+ rule.waitForIdle()+ rule.onNodeWithText("SIM 1").assertDoesNotExist()+ }++ @Test+ fun `thread avatar shows initials or group icon`() {+ var group by androidx.compose.runtime.mutableStateOf(false)+ rule.setContent { ThreadAvatar(title = "Pat Lee", isGroup = group) }+ rule.onNodeWithText("PL").assertIsDisplayed()+ rule.runOnIdle { group = true }+ rule.waitForIdle()+ rule.onNodeWithText("PL").assertDoesNotExist()+ }++ @Test+ fun `unread badge shows the count`() {+ rule.setContent { UnreadBadge(3) }+ rule.onNodeWithText("3").assertIsDisplayed()+ }++ @Test+ fun `status ticks render per delivery state`() {+ var status by androidx.compose.runtime.mutableStateOf(MessageStatus.None)+ rule.setContent { MessageStatusTicks(status) }+ rule.onNodeWithText("✓").assertDoesNotExist()+ rule.runOnIdle { status = MessageStatus.Failed }+ rule.waitForIdle()+ rule.onNodeWithText("!").assertIsDisplayed()+ rule.runOnIdle { status = MessageStatus.Sent }+ rule.waitForIdle()+ rule.onNodeWithText("✓").assertIsDisplayed()+ rule.runOnIdle { status = MessageStatus.Delivered }+ rule.waitForIdle()+ rule.onNodeWithText("✓✓").assertIsDisplayed()+ rule.runOnIdle { status = MessageStatus.Read }+ rule.waitForIdle()+ rule.onNodeWithText("✓✓").assertIsDisplayed()+ }++ // -- gates ---------------------------------------------------------------++ @Test+ fun `permission gate shows grant prompt when denied`() {+ var contentShown = false+ rule.setContent {+ PermissionGate(permission = Manifest.permission.READ_SMS, message = "Need SMS") {+ contentShown = true+ }+ }+ rule.onNodeWithText(str(R.string.permission_title)).assertIsDisplayed()+ rule.onNodeWithText("Need SMS").assertIsDisplayed()+ rule.onNodeWithText(str(R.string.grant_permission)).assertIsDisplayed()+ assertEquals(false, contentShown)+ }++ @Test+ fun `permission gate shows content when granted`() {+ Shadows.shadowOf(context as Application).grantPermissions(Manifest.permission.READ_SMS)+ var revisions = -1+ rule.setContent {+ PermissionGate(permission = Manifest.permission.READ_SMS, message = "Need SMS") { rev ->+ revisions = rev+ androidx.compose.material3.Text("secret content")+ }+ }+ rule.onNodeWithText("secret content").assertIsDisplayed()+ assertEquals(0, revisions)+ }++ @Test+ fun `role gate explains when the role is unavailable`() {+ rule.setContent {+ DefaultSmsGate { androidx.compose.material3.Text("sms home") }+ }+ // Robolectric holds no SMS role: the gate must explain, not show content.+ rule.onNodeWithText(str(R.string.default_app_title)).assertIsDisplayed()+ rule.onNodeWithText("sms home").assertDoesNotExist()+ }++ @Test+ fun `line badges label the vendor lines`() {+ rule.setContent {+ androidx.compose.foundation.layout.Column {+ LineBadge(CommunicateLine.WhatsApp)+ LineBadge(CommunicateLine.Signal)+ LineBadge(CommunicateLine.GoogleVoice)+ }+ }+ rule.onNodeWithText("WhatsApp").assertIsDisplayed()+ rule.onNodeWithText("Signal").assertIsDisplayed()+ rule.onNodeWithText("Voice").assertIsDisplayed()+ }++ @Test+ fun `line choices fall back to the placeholder sim when signed out`() {+ var choices: List<LineChoice>? = null+ rule.setContent { choices = rememberLineChoices() }+ rule.waitForIdle()+ // No active SIM and no GV/WhatsApp/Signal sign-in: only the SIM fallback.+ assertEquals(+ listOf<LineChoice>(LineChoice.Sim(-1, str(R.string.account_sim))),+ choices,+ )+ }++ // -- line selector -------------------------------------------------------++ @Test+ fun `line selector opens the menu and reports the pick`() {+ val picks = mutableListOf<LineChoice>()+ val choices = listOf(LineChoice.GoogleVoice, LineChoice.WhatsApp, LineChoice.Signal)+ rule.setContent {+ LineSelector(choices = choices, selected = LineChoice.GoogleVoice, onSelect = { picks.add(it) })+ }+ rule.onNodeWithText("Google Voice").assertIsDisplayed()+ rule.onNodeWithText("Google Voice").performClick()+ rule.onNodeWithText("Signal").performClick()+ rule.waitForIdle()+ assertEquals(listOf<LineChoice>(LineChoice.Signal), picks)+ }++ // -- dial pad ------------------------------------------------------------++ @Test+ fun `dial pad appends digits and fires call clear backspace`() {+ val events = mutableListOf<String>()+ rule.setContent {+ DialPad(+ number = "12",+ onAppend = { events.add("append:$it") },+ onBackspace = { events.add("back") },+ onClear = { events.add("clear") },+ onPaste = { events.add("paste") },+ onCall = { events.add("call") },+ )+ }+ rule.onNodeWithText("12").assertIsDisplayed()+ rule.onNodeWithText("3").performClick()+ rule.onNodeWithText("#").performClick()+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("Call")).performClick()+ rule.waitForIdle()+ assertEquals(listOf("append:3", "append:#", "call"), events)+ }++ @Test+ fun `dial pad disables call and clear on an empty number`() {+ rule.setContent {+ DialPad(+ number = "",+ onAppend = {}, onBackspace = {}, onClear = {}, onPaste = {}, onCall = {},+ )+ }+ rule.onNodeWithText(str(R.string.phone_number)).assertIsDisplayed()+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("Call")).assertIsNotEnabled()+ rule.onNodeWithText("Clear").assertIsNotEnabled()+ }++ @Test+ fun `dial pad enables actions once a number exists`() {+ rule.setContent {+ DialPad(+ number = "5",+ onAppend = {}, onBackspace = {}, onClear = {}, onPaste = {}, onCall = {},+ )+ }+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("Call")).assertIsEnabled()+ rule.onNodeWithText("Clear").assertIsEnabled()+ }+}
communicate/src/test/java/com/vayunmathur/communicate/ui/ConversationBubbleUiPass3Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/ui/ConversationBubbleUiPass3Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/ui/ConversationBubbleUiPass3Test.ktnew file mode 100644index 0000000000..079db80b8d--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/ui/ConversationBubbleUiPass3Test.kt@@ -0,0 +1,243 @@+package com.vayunmathur.communicate.ui++import androidx.compose.foundation.layout.PaddingValues+import androidx.compose.runtime.getValue+import androidx.compose.runtime.setValue+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.compose.ui.unit.dp+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.communicate.R+import com.vayunmathur.communicate.data.CommunicateAttachment+import com.vayunmathur.communicate.data.CommunicateLine+import com.vayunmathur.communicate.data.MessageStatus+import com.vayunmathur.communicate.data.SmsMessage+import com.vayunmathur.communicate.data.whatsapp.WhatsAppServiceData+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNull+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/**+ * UiPass3 coverage for message bubbles and conversation extras+ * (`ConversationMessageBubble.kt`, `ConversationMessagesList.kt`,+ * `ConversationAttachments.kt`): bodies, ticks, quoted/poll/revoked extras,+ * safety-number + encryption banners and attachment rows.+ */+@RunWith(RobolectricTestRunner::class)+class ConversationBubbleUiPass3Test {++ @get:Rule+ val rule = createComposeRule()++ private val context: android.content.Context+ get() = ApplicationProvider.getApplicationContext()++ private fun str(id: Int): String = context.getString(id)++ private fun message(+ id: Long = 1L,+ body: String = "hello there",+ outgoing: Boolean = false,+ line: CommunicateLine = CommunicateLine.Sim,+ serviceData: String? = null,+ status: MessageStatus = MessageStatus.None,+ attachments: List<CommunicateAttachment> = emptyList(),+ senderAddress: String? = null,+ ) = SmsMessage(+ id = id,+ threadId = 7L,+ address = "+1555",+ body = body,+ timestampMillis = System.currentTimeMillis(),+ outgoing = outgoing,+ read = true,+ line = line,+ serviceData = serviceData,+ status = status,+ attachments = attachments,+ senderAddress = senderAddress,+ )++ @Test+ fun `incoming and outgoing bodies render`() {+ var outgoing by androidx.compose.runtime.mutableStateOf(false)+ rule.setContent { MessageBubble(message(body = if (outgoing) "from me" else "from them", outgoing = outgoing)) }+ rule.onNodeWithText("from them").assertIsDisplayed()+ rule.runOnIdle { outgoing = true }+ rule.waitForIdle()+ rule.onNodeWithText("from me").assertIsDisplayed()+ }++ @Test+ fun `outgoing bubble shows delivery ticks`() {+ var status by androidx.compose.runtime.mutableStateOf(MessageStatus.Read)+ rule.setContent { MessageBubble(message(outgoing = true, status = status)) }+ rule.onNodeWithText("✓✓").assertIsDisplayed()+ rule.runOnIdle { status = MessageStatus.Failed }+ rule.waitForIdle()+ rule.onNodeWithText("!").assertIsDisplayed()+ }++ @Test+ fun `revoked whatsapp message hides its body`() {+ val sd = WhatsAppServiceData(isRevoked = true).serialize()+ rule.setContent {+ MessageBubble(message(body = "secret", line = CommunicateLine.WhatsApp, serviceData = sd))+ }+ rule.onNodeWithText("🚫 This message was deleted").assertIsDisplayed()+ rule.onNodeWithText("secret").assertDoesNotExist()+ }++ @Test+ fun `edited whatsapp message is marked edited`() {+ val sd = WhatsAppServiceData(isEdited = true).serialize()+ rule.setContent {+ MessageBubble(message(body = "fixed typo", line = CommunicateLine.WhatsApp, serviceData = sd))+ }+ rule.onNodeWithText("fixed typo").assertIsDisplayed()+ rule.onNodeWithText("edited").assertIsDisplayed()+ }++ @Test+ fun `quoted reply preview shows sender and body`() {+ val sd = WhatsAppServiceData(quotedBody = "original text", quotedSender = "Pat").serialize()+ rule.setContent {+ MessageBubble(message(body = "reply!", line = CommunicateLine.WhatsApp, serviceData = sd))+ }+ rule.onNodeWithText("Pat: original text").assertIsDisplayed()+ rule.onNodeWithText("reply!").assertIsDisplayed()+ }++ @Test+ fun `poll renders question and options with votes`() {+ val sd = WhatsAppServiceData(+ pollQuestion = "Lunch?",+ pollOptions = listOf(+ com.vayunmathur.communicate.data.whatsapp.PollOptionData("Pizza", 3),+ com.vayunmathur.communicate.data.whatsapp.PollOptionData("Sushi", 1),+ ),+ ).serialize()+ rule.setContent {+ MessageBubble(message(body = "pick one", line = CommunicateLine.WhatsApp, serviceData = sd))+ }+ rule.onNodeWithText("📊 Lunch?").assertIsDisplayed()+ rule.onNodeWithText("• Pizza (3)").assertIsDisplayed()+ rule.onNodeWithText("• Sushi (1)").assertIsDisplayed()+ }++ @Test+ fun `group sender name from service data labels the bubble`() {+ val sd = WhatsAppServiceData(senderName = "Group Pat").serialize()+ rule.setContent {+ MessageBubble(message(line = CommunicateLine.WhatsApp, serviceData = sd))+ }+ rule.waitForIdle()+ rule.onNodeWithText("Group Pat").assertIsDisplayed()+ }++ @Test+ fun `document attachment renders a fallback row with its mime type`() {+ val att = CommunicateAttachment("content://doc/1", "application/pdf", "report.pdf")+ rule.setContent { MessageBubble(message(attachments = listOf(att))) }+ rule.onNodeWithText("application/pdf").assertIsDisplayed()+ }++ @Test+ fun `reactions render as chips with counts`() {+ val sd = WhatsAppServiceData(+ reactions = listOf(+ com.vayunmathur.communicate.data.whatsapp.Reaction("👍", 2),+ com.vayunmathur.communicate.data.whatsapp.Reaction("❤️", 1),+ ),+ ).serialize()+ rule.setContent {+ MessageBubble(message(line = CommunicateLine.WhatsApp, serviceData = sd))+ }+ rule.onNodeWithText("👍 2").assertIsDisplayed()+ rule.onNodeWithText("❤️").assertIsDisplayed()+ }++ @Test+ fun `incoming group bubble falls back to the sender address`() {+ rule.setContent {+ MessageBubble(message(senderAddress = "+1666"))+ }+ rule.waitForIdle()+ rule.onNodeWithText("+1666").assertIsDisplayed()+ }++ // -- messages list states -------------------------------------------------++ @Test+ fun `messages content shows empty state for no rows`() {+ rule.setContent { MessagesContent(PaddingValues(0.dp), emptyList()) }+ rule.onNodeWithText(str(R.string.empty_messages)).assertIsDisplayed()+ }++ @Test+ fun `messages content lists bubbles`() {+ rule.setContent {+ MessagesContent(+ PaddingValues(0.dp),+ listOf(message(id = 1L, body = "one"), message(id = 2L, body = "two")),+ )+ }+ rule.onNodeWithText("one").assertIsDisplayed()+ rule.onNodeWithText("two").assertIsDisplayed()+ }++ // -- banners ---------------------------------------------------------------++ @Test+ fun `safety number banner formats the number and accepts`() {+ var accepted = 0+ rule.setContent {+ SafetyNumberBanner(safetyNumber = "1234567890", onAccept = { accepted++ })+ }+ rule.onNodeWithText(str(R.string.signal_safety_number_changed_title)).assertIsDisplayed()+ rule.onNodeWithText(str(R.string.signal_safety_number_accept)).performClick()+ rule.waitForIdle()+ assertEquals(1, accepted)+ }++ @Test+ fun `encrypted banner distinguishes pending from active`() {+ var pending by androidx.compose.runtime.mutableStateOf(false)+ rule.setContent { EncryptedChatBanner(pending = pending) }+ rule.onNodeWithText(str(R.string.rcs_encrypted_banner)).assertIsDisplayed()+ rule.runOnIdle { pending = true }+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.rcs_encrypted_pending)).assertIsDisplayed()+ }++ // -- attachments -------------------------------------------------------------++ @Test+ fun `attachment fallback row reports clicks`() {+ var clicks = 0+ val att = CommunicateAttachment("content://doc/2", "text/plain", "notes.txt")+ rule.setContent {+ AttachmentFallbackRow(+ attachment = att,+ bubbleColor = androidx.compose.ui.graphics.Color.Gray,+ contentColor = androidx.compose.ui.graphics.Color.White,+ shape = androidx.compose.foundation.shape.RoundedCornerShape(8.dp),+ onClick = { clicks++ },+ )+ }+ rule.onNodeWithText("text/plain").assertIsDisplayed()+ rule.onNodeWithText("text/plain").performClick()+ rule.waitForIdle()+ assertEquals(1, clicks)+ }++ @Test+ fun `displayNameOf returns null for an unresolvable uri`() {+ assertNull(displayNameOf(context, android.net.Uri.parse("content://missing/1")))+ }+}
communicate/src/test/java/com/vayunmathur/communicate/ui/ConversationExtrasUiPass3Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/ui/ConversationExtrasUiPass3Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/ui/ConversationExtrasUiPass3Test.ktnew file mode 100644index 0000000000..e7e1a72311--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/ui/ConversationExtrasUiPass3Test.kt@@ -0,0 +1,272 @@+package com.vayunmathur.communicate.ui++import androidx.compose.foundation.layout.PaddingValues+import androidx.compose.runtime.getValue+import androidx.compose.runtime.setValue+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.assertIsEnabled+import androidx.compose.ui.test.assertIsNotEnabled+import androidx.compose.ui.test.hasClickAction+import androidx.compose.ui.test.hasContentDescriptionExactly+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onAllNodesWithText+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.compose.ui.test.performTextInput+import androidx.compose.ui.unit.dp+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.communicate.R+import com.vayunmathur.communicate.data.CommunicateAttachment+import com.vayunmathur.communicate.data.CommunicateLine+import kotlin.test.Test+import kotlin.test.assertEquals+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/**+ * UiPass3 coverage for conversation chrome (`ConversationTopBar.kt`,+ * `ConversationComposeRow.kt`, `ConversationRcsExtras.kt`,+ * `ConversationEncryptionBanner.kt`): titles, typing subtitle, the compose+ * row's send gating and attachment previews, and RCS gate no-ops.+ */+@RunWith(RobolectricTestRunner::class)+class ConversationExtrasUiPass3Test {++ @get:Rule+ val rule = createComposeRule()++ private val context: android.content.Context+ get() = ApplicationProvider.getApplicationContext()++ private fun str(id: Int): String = context.getString(id)++ // -- title -----------------------------------------------------------------++ @Test+ fun `title shows the address under a contact name`() {+ rule.setContent {+ ConversationTitle(+ threadId = 1L, isGroup = false, groupTitle = null,+ title = "Pat Lee", groupSubtitle = null,+ address = "+1555", line = CommunicateLine.Sim,+ )+ }+ rule.onNodeWithText("Pat Lee").assertIsDisplayed()+ rule.onNodeWithText("+1555").assertIsDisplayed()+ }++ @Test+ fun `title hides the address when it is the title`() {+ rule.setContent {+ ConversationTitle(+ threadId = 1L, isGroup = false, groupTitle = null,+ title = "+1555", groupSubtitle = null,+ address = "+1555", line = CommunicateLine.Sim,+ )+ }+ // Only the title node exists (no duplicate subtitle).+ rule.onAllNodesWithText("+1555").fetchSemanticsNodes().let { assertEquals(1, it.size) }+ }++ @Test+ fun `group title prefers the group name and shows the subtitle`() {+ rule.setContent {+ ConversationTitle(+ threadId = 1L, isGroup = true, groupTitle = "Family",+ title = "Pat", groupSubtitle = "3 members",+ address = "g1", line = CommunicateLine.WhatsApp,+ )+ }+ rule.onNodeWithText("Family").assertIsDisplayed()+ rule.onNodeWithText("3 members").assertIsDisplayed()+ }++ @Test+ fun `typing replaces the subtitle for one-to-one rcs`() {+ rule.setContent {+ ConversationTitle(+ threadId = 1L, isGroup = false, groupTitle = null,+ title = "Pat Lee", groupSubtitle = null,+ address = "+1555", line = CommunicateLine.Rcs, isPeerTyping = true,+ )+ }+ rule.onNodeWithText(str(R.string.rcs_typing)).assertIsDisplayed()+ }++ // -- compose row -------------------------------------------------------------++ @Test+ fun `compose row sends only with a draft or an attachment`() {+ var sends = 0+ var draft by androidx.compose.runtime.mutableStateOf("")+ rule.setContent {+ ComposeSmsRow(+ draft = draft, onDraftChange = { draft = it }, attachments = emptyList(),+ onAttachMedia = {}, onAttachFile = {}, onCreatePoll = null,+ onShareContact = null, onRemoveAttachment = {}, onSend = { sends++ },+ )+ }+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("Send")).assertIsNotEnabled()+ rule.runOnIdle { draft = "hi" }+ rule.waitForIdle()+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("Send")).assertIsEnabled()+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("Send")).performClick()+ rule.waitForIdle()+ assertEquals(1, sends)+ }++ @Test+ fun `compose row reports typing`() {+ var draft = ""+ rule.setContent {+ ComposeSmsRow(+ draft = "", onDraftChange = { draft = it }, attachments = emptyList(),+ onAttachMedia = {}, onAttachFile = {}, onCreatePoll = null,+ onShareContact = null, onRemoveAttachment = {}, onSend = {},+ )+ }+ rule.onNodeWithText(str(R.string.message_hint)).performTextInput("hello")+ rule.waitForIdle()+ assertEquals("hello", draft)+ }++ @Test+ fun `compose row previews a document attachment and removes it`() {+ var removed: CommunicateAttachment? = null+ val att = CommunicateAttachment("content://doc/9", "application/pdf", "report.pdf")+ rule.setContent {+ ComposeSmsRow(+ draft = "", onDraftChange = {}, attachments = listOf(att),+ onAttachMedia = {}, onAttachFile = {}, onCreatePoll = null,+ onShareContact = null, onRemoveAttachment = { removed = it }, onSend = {},+ )+ }+ rule.onNodeWithText("application/pdf").assertIsDisplayed()+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("Close")).performClick()+ rule.waitForIdle()+ assertEquals(att, removed)+ }++ // -- actions bar ---------------------------------------------------------------++ @Test+ fun `actions offer delete for a sim thread`() {+ rule.setContent {+ ConversationActions(+ threadId = 1L, address = "+1555", line = CommunicateLine.Sim,+ remoteId = null, isGroup = false, participants = emptyList(),+ groupTitle = null, isUnknownContact = false, onBack = {},+ )+ }+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("More")).performClick()+ rule.onNodeWithText(str(com.vayunmathur.library.ui.R.string.delete)).assertIsDisplayed()+ }++ @Test+ fun `actions offer contact creation for an unknown one-to-one contact`() {+ rule.setContent {+ ConversationActions(+ threadId = 1L, address = "+1555", line = CommunicateLine.Sim,+ remoteId = null, isGroup = false, participants = emptyList(),+ groupTitle = null, isUnknownContact = true, onBack = {},+ )+ }+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("More")).performClick()+ rule.onNodeWithText(str(R.string.contact_create_new)).assertIsDisplayed()+ rule.onNodeWithText(str(R.string.contact_add_to_existing)).assertIsDisplayed()+ }++ @Test+ fun `rcs actions offer verify and report the peer`() {+ var verified: String? = null+ rule.setContent {+ ConversationActions(+ threadId = 1L, address = "+1555", line = CommunicateLine.Rcs,+ remoteId = "peer-1", isGroup = false, participants = emptyList(),+ groupTitle = null, isUnknownContact = false, onBack = {},+ onOpenRcsVerify = { verified = it },+ )+ }+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("More")).performClick()+ rule.onNodeWithText(str(R.string.rcs_verify_title)).performClick()+ rule.waitForIdle()+ assertEquals("peer-1", verified)+ }++ @Test+ fun `rcs group actions offer member management`() {+ var members: String? = null+ rule.setContent {+ ConversationActions(+ threadId = 1L, address = "g1", line = CommunicateLine.Rcs,+ remoteId = "g1", isGroup = true, participants = listOf("+1555"),+ groupTitle = "Family", isUnknownContact = false, onBack = {},+ onOpenRcsGroupMembers = { members = it },+ )+ }+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("More")).performClick()+ rule.onNodeWithText(str(R.string.rcs_group_members_title)).performClick()+ rule.waitForIdle()+ assertEquals("g1", members)+ }++ @Test+ fun `delete confirm can be dismissed without deleting`() {+ var backs = 0+ rule.setContent {+ ConversationActions(+ threadId = 1L, address = "+1555", line = CommunicateLine.Sim,+ remoteId = null, isGroup = false, participants = emptyList(),+ groupTitle = null, isUnknownContact = false, onBack = { backs++ },+ )+ }+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("More")).performClick()+ rule.onNodeWithText(str(com.vayunmathur.library.ui.R.string.delete)).performClick()+ rule.onNodeWithText(str(R.string.delete_conversation_title)).assertIsDisplayed()+ rule.onNodeWithText(str(com.vayunmathur.library.ui.R.string.cancel)).performClick()+ rule.waitForIdle()+ assertEquals(0, backs)+ rule.onNodeWithText(str(R.string.delete_conversation_title)).assertDoesNotExist()+ }++ @Test+ fun `compose attach menu offers media file poll and contact`() {+ val events = mutableListOf<String>()+ rule.setContent {+ ComposeSmsRow(+ draft = "hi", onDraftChange = {}, attachments = emptyList(),+ onAttachMedia = { events.add("media") }, onAttachFile = { events.add("file") },+ onCreatePoll = { events.add("poll") },+ onShareContact = { events.add("contact") },+ onRemoveAttachment = {}, onSend = {},+ )+ }+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("Attachment")).performClick()+ rule.onNodeWithText(str(R.string.attach_media)).performClick()+ rule.waitForIdle()+ assertEquals(listOf("media"), events)+ }++ // -- rcs extras ------------------------------------------------------------------++ @Test+ fun `rcs banner is a no-op off the rcs line`() {+ rule.setContent {+ RcsEncryptionBanner(line = CommunicateLine.Sim, remoteId = null, address = "+1555", refresh = 0)+ }+ rule.onNodeWithText(str(R.string.rcs_encrypted_banner)).assertDoesNotExist()+ }++ @Test+ fun `peer typing is false off the rcs line`() {+ var typing: Boolean? = null+ rule.setContent {+ typing = rememberRcsPeerTyping(+ line = CommunicateLine.Sim, isGroup = false, remoteId = null, address = "+1555",+ )+ }+ rule.waitForIdle()+ assertEquals(false, typing)+ }+}
communicate/src/test/java/com/vayunmathur/communicate/ui/DialerUiPass3Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/ui/DialerUiPass3Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/ui/DialerUiPass3Test.ktnew file mode 100644index 0000000000..a8dea5a2b4--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/ui/DialerUiPass3Test.kt@@ -0,0 +1,94 @@+package com.vayunmathur.communicate.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.communicate.R+import com.vayunmathur.communicate.data.CommunicateContact+import kotlin.test.Test+import kotlin.test.assertEquals+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/**+ * UiPass3 coverage for the dialer (`DialerContent.kt`): contact rows,+ * T9 filtering through the pad, and place-call taps. The pad itself is+ * covered in `CommunicateUiPass3Test`.+ */+@RunWith(RobolectricTestRunner::class)+class DialerUiPass3Test {++ @get:Rule+ val rule = createComposeRule()++ private val context: android.content.Context+ get() = ApplicationProvider.getApplicationContext()++ private fun str(id: Int): String = context.getString(id)++ private val contacts = listOf(+ CommunicateContact(1L, "Alice Adams", "+155501", "Mobile"),+ CommunicateContact(2L, "Bob Brown", "+155502", "Work"),+ CommunicateContact(3L, "Carol Clark", "+155503", "Mobile"),+ )++ @Test+ fun `contacts render with numbers and call on tap`() {+ val placed = mutableListOf<String>()+ rule.setContent { DialerContent(contacts = contacts, onPlace = { placed.add(it) }) }+ rule.onNodeWithText("Alice Adams").assertIsDisplayed()+ rule.onNodeWithText("Mobile +155501").assertIsDisplayed()+ rule.onNodeWithText("Alice Adams").performClick()+ rule.waitForIdle()+ assertEquals(listOf("+155501"), placed)+ }++ @Test+ fun `typing digits t9-filters the list`() {+ rule.setContent { DialerContent(contacts = contacts, onPlace = {}) }+ // 2 = ABC: matches Alice/Bob/Carol names; narrow with 5 (JKL) after.+ rule.onNodeWithText("2").performClick()+ rule.waitForIdle()+ rule.onNodeWithText("Alice Adams").assertIsDisplayed()+ rule.onNodeWithText("5").performClick()+ rule.waitForIdle()+ // "25" (A/B/C + J/K/L): Alice (Al) still matches, Bob (no l/k/j second) drops.+ rule.onNodeWithText("Alice Adams").assertIsDisplayed()+ rule.onNodeWithText("Bob Brown").assertDoesNotExist()+ }++ @Test+ fun `digits with no match show the filtered empty state`() {+ rule.setContent { DialerContent(contacts = contacts, onPlace = {}) }+ val nine = androidx.compose.ui.test.hasText("9") and androidx.compose.ui.test.hasClickAction()+ rule.onNode(nine).performClick()+ rule.onNode(nine).performClick()+ rule.onNode(nine).performClick()+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.empty_contacts_for_digits)).assertExists()+ }++ @Test+ fun `no contacts shows the empty state`() {+ rule.setContent { DialerContent(contacts = emptyList(), onPlace = {}) }+ rule.onNodeWithText(str(R.string.empty_contacts)).assertExists()+ }++ @Test+ fun `call button places the typed number`() {+ val placed = mutableListOf<String>()+ rule.setContent { DialerContent(contacts = emptyList(), onPlace = { placed.add(it) }) }+ rule.onNodeWithText("1").performClick()+ rule.onNodeWithText("5").performClick()+ rule.onNodeWithText("5").performClick()+ rule.onNode(+ androidx.compose.ui.test.hasClickAction() and+ androidx.compose.ui.test.hasContentDescriptionExactly("Call"),+ ).performClick()+ rule.waitForIdle()+ assertEquals(listOf("155"), placed)+ }+}
communicate/src/test/java/com/vayunmathur/communicate/ui/MessagesUiPass3Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/ui/MessagesUiPass3Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/ui/MessagesUiPass3Test.ktnew file mode 100644index 0000000000..b75fc8669c--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/ui/MessagesUiPass3Test.kt@@ -0,0 +1,166 @@+package com.vayunmathur.communicate.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.hasClickAction+import androidx.compose.ui.test.hasContentDescriptionExactly+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.communicate.R+import com.vayunmathur.communicate.data.CommunicateLine+import com.vayunmathur.communicate.data.SmsThread+import kotlin.test.Test+import kotlin.test.assertEquals+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/**+ * UiPass3 coverage for the thread list (`MessagesScreen.kt` stateless+ * [MessagesListContent] + `MessagesThreadRow.kt`): titles, snippets, unread+ * badges, group fallbacks and the delete-confirm flow.+ */+@RunWith(RobolectricTestRunner::class)+class MessagesUiPass3Test {++ @get:Rule+ val rule = createComposeRule()++ private val context: android.content.Context+ get() = ApplicationProvider.getApplicationContext()++ private fun str(id: Int): String = context.getString(id)++ private fun thread(+ id: Long = 1L,+ address: String = "+1555",+ name: String? = "Pat Lee",+ snippet: String = "see you soon",+ unread: Int = 0,+ line: CommunicateLine = CommunicateLine.Sim,+ isGroup: Boolean = false,+ participants: List<String> = emptyList(),+ groupTitle: String? = null,+ ) = SmsThread(+ threadId = id,+ address = address,+ displayName = name,+ snippet = snippet,+ timestampMillis = System.currentTimeMillis(),+ unreadCount = unread,+ line = line,+ isGroup = isGroup,+ participants = participants,+ groupTitle = groupTitle,+ )++ @Test+ fun `row shows title snippet and opens on tap`() {+ val opened = mutableListOf<SmsThread>()+ val t = thread()+ rule.setContent {+ MessagesListContent(threads = listOf(t), onOpenThread = { opened.add(it) }, onDeleteThread = {})+ }+ rule.onNodeWithText("Pat Lee").assertIsDisplayed()+ rule.onNodeWithText("see you soon").assertIsDisplayed()+ rule.onNodeWithText("Pat Lee").performClick()+ rule.waitForIdle()+ assertEquals(listOf(t), opened)+ }++ @Test+ fun `unread threads show a count badge`() {+ rule.setContent {+ MessagesListContent(+ threads = listOf(thread(unread = 4)),+ onOpenThread = {}, onDeleteThread = {},+ )+ }+ rule.onNodeWithText("4").assertIsDisplayed()+ }++ @Test+ fun `read threads show no badge`() {+ rule.setContent {+ MessagesListContent(+ threads = listOf(thread(unread = 0)),+ onOpenThread = {}, onDeleteThread = {},+ )+ }+ rule.onNodeWithText("0").assertDoesNotExist()+ }++ @Test+ fun `group rows prefer the explicit group title`() {+ rule.setContent {+ MessagesListContent(+ threads = listOf(thread(isGroup = true, groupTitle = "Family", name = null)),+ onOpenThread = {}, onDeleteThread = {},+ )+ }+ rule.onNodeWithText("Family").assertIsDisplayed()+ }++ @Test+ fun `group rows fall back to participant names`() {+ rule.setContent {+ MessagesListContent(+ threads = listOf(+ thread(+ isGroup = true, name = null, groupTitle = null,+ participants = listOf("Alice", "Bob", "Cid"),+ ),+ ),+ onOpenThread = {}, onDeleteThread = {},+ )+ }+ rule.onNodeWithText("Alice, Bob +1").assertIsDisplayed()+ }++ @Test+ fun `delete asks first and only then deletes`() {+ val deleted = mutableListOf<SmsThread>()+ val t = thread()+ rule.setContent {+ MessagesListContent(threads = listOf(t), onOpenThread = {}, onDeleteThread = { deleted.add(it) })+ }+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("More")).performClick()+ rule.onNodeWithText(str(com.vayunmathur.library.ui.R.string.delete)).performClick()+ rule.onNodeWithText(str(R.string.delete_conversation_title)).assertIsDisplayed()+ assertEquals(emptyList(), deleted)+ rule.onNodeWithText(str(com.vayunmathur.library.ui.R.string.delete)).performClick()+ rule.waitForIdle()+ assertEquals(listOf(t), deleted)+ }++ @Test+ fun `delete can be cancelled`() {+ val deleted = mutableListOf<SmsThread>()+ rule.setContent {+ MessagesListContent(threads = listOf(thread()), onOpenThread = {}, onDeleteThread = { deleted.add(it) })+ }+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("More")).performClick()+ rule.onNodeWithText(str(com.vayunmathur.library.ui.R.string.delete)).performClick()+ rule.onNodeWithText(str(com.vayunmathur.library.ui.R.string.cancel)).performClick()+ rule.waitForIdle()+ assertEquals(emptyList(), deleted)+ }++ @Test+ fun `whatsapp and signal rows render line tags`() {+ rule.setContent {+ MessagesListContent(+ threads = listOf(+ thread(id = 1L, name = "Wa Pal", line = CommunicateLine.WhatsApp),+ thread(id = 2L, name = "Sig Pal", line = CommunicateLine.Signal),+ ),+ onOpenThread = {}, onDeleteThread = {},+ )+ }+ rule.onNodeWithText("Wa Pal").assertIsDisplayed()+ rule.onNodeWithText("Sig Pal").assertIsDisplayed()+ rule.onNodeWithText("WhatsApp").assertIsDisplayed()+ rule.onNodeWithText("Signal").assertIsDisplayed()+ }+}
communicate/src/test/java/com/vayunmathur/communicate/ui/NewMessagePickerUiPass3Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/ui/NewMessagePickerUiPass3Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/ui/NewMessagePickerUiPass3Test.ktnew file mode 100644index 0000000000..6be89be34c--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/ui/NewMessagePickerUiPass3Test.kt@@ -0,0 +1,127 @@+package com.vayunmathur.communicate.ui++import android.Manifest+import android.app.Application+import androidx.compose.runtime.getValue+import androidx.compose.runtime.setValue+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.assertIsNotEnabled+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.communicate.R+import com.vayunmathur.communicate.data.LineChoice+import kotlin.test.Test+import kotlin.test.assertEquals+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.Shadows++/**+ * UiPass3 coverage for the new-message picker (`NewMessagePicker.kt`):+ * line/group chrome, recipient rows, and the number-formatting helpers.+ * The contacts provider is empty under Robolectric, so the picker shows+ * its search field with no rows — the group flow is asserted on chrome+ * and the disabled Create action rather than on provider data.+ */+@RunWith(RobolectricTestRunner::class)+class NewMessagePickerUiPass3Test {++ @get:Rule+ val rule = createComposeRule()++ private val context: android.content.Context+ get() = ApplicationProvider.getApplicationContext()++ private fun str(id: Int): String = context.getString(id)++ @Test+ fun `formatNumber formats a dialable number and keeps junk as-is`() {+ assertEquals("(555) 010-1234", formatNumber("5550101234", "US"))+ assertEquals("call-me", formatNumber("call-me", "US"))+ assertEquals("", formatNumber("", "US"))+ }++ @Test+ fun `deviceRegion returns an upper-case region code`() {+ val region = deviceRegion(context)+ assertEquals(region.uppercase(), region)+ assertEquals(true, region.length <= 3)+ }++ @Test+ fun `contact pick row reports taps with and without a checkbox`() {+ var taps = 0+ var selected by androidx.compose.runtime.mutableStateOf<Boolean?>(null)+ rule.setContent {+ ContactPickRow(title = "Pat Lee", subtitle = "+1555", selected = selected, onClick = { taps++ })+ }+ rule.onNodeWithText("Pat Lee").assertIsDisplayed()+ rule.onNodeWithText("+1555").assertIsDisplayed()+ rule.onNodeWithText("Pat Lee").performClick()+ rule.runOnIdle { selected = true }+ rule.waitForIdle()+ rule.onNodeWithText("Pat Lee").performClick()+ rule.waitForIdle()+ assertEquals(2, taps)+ }++ @Test+ fun `picker shows search and line chrome for one-to-one`() {+ Shadows.shadowOf(context as Application).grantPermissions(Manifest.permission.READ_CONTACTS)+ rule.setContent {+ NewMessagePicker(+ choices = listOf(LineChoice.GoogleVoice, LineChoice.WhatsApp),+ onDismiss = {},+ onCompose = { _, _ -> },+ onCreateGroup = { _, _, _, _ -> },+ )+ }+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.new_message)).assertIsDisplayed()+ rule.onNodeWithText("Search name or number").assertIsDisplayed()+ rule.onNodeWithText("Group").assertIsDisplayed()+ }++ @Test+ fun `picker group mode asks for members before creating`() {+ Shadows.shadowOf(context as Application).grantPermissions(Manifest.permission.READ_CONTACTS)+ rule.setContent {+ NewMessagePicker(+ choices = listOf(LineChoice.WhatsApp),+ onDismiss = {},+ onCompose = { _, _ -> },+ onCreateGroup = { _, _, _, _ -> },+ )+ }+ rule.waitForIdle()+ // Flip the Group switch: the dialog retitles and Create stays disabled+ // until at least one recipient is picked.+ rule.onNode(androidx.compose.ui.test.isToggleable()).performClick()+ rule.waitForIdle()+ rule.onNodeWithText("New group").assertIsDisplayed()+ rule.onNodeWithText("Create").assertIsNotEnabled()+ rule.onNodeWithText("Group name (optional)").assertIsDisplayed()+ }++ @Test+ fun `picker dismiss button clears without composing`() {+ var dismissed = 0+ var composed = 0+ rule.setContent {+ NewMessagePicker(+ choices = listOf(LineChoice.GoogleVoice),+ onDismiss = { dismissed++ },+ onCompose = { _, _ -> composed++ },+ onCreateGroup = { _, _, _, _ -> },+ )+ }+ rule.waitForIdle()+ rule.onNodeWithText(str(com.vayunmathur.library.ui.R.string.clear)).performClick()+ rule.waitForIdle()+ assertEquals(1, dismissed)+ assertEquals(0, composed)+ }+}
communicate/src/test/java/com/vayunmathur/communicate/ui/PollContactUiPass3Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/ui/PollContactUiPass3Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/ui/PollContactUiPass3Test.ktnew file mode 100644index 0000000000..1af65dee8d--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/ui/PollContactUiPass3Test.kt@@ -0,0 +1,185 @@+package com.vayunmathur.communicate.ui++import android.content.Context+import android.net.Uri+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.assertIsEnabled+import androidx.compose.ui.test.assertIsNotEnabled+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.compose.ui.test.performTextInput+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.communicate.R+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNull+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/**+ * UiPass3 coverage for the poll composer (`PollComposerDialog.kt`) and the+ * contact hand-off helpers (`ContactIntents.kt`, `SharedContactCard.kt`).+ */+@RunWith(RobolectricTestRunner::class)+class PollContactUiPass3Test {++ @get:Rule+ val rule = createComposeRule()++ private val context: Context+ get() = ApplicationProvider.getApplicationContext()++ private fun str(id: Int): String = context.getString(id)++ @Test+ fun `poll needs a question and two options before it can be created`() {+ rule.setContent { PollComposerDialog(onDismiss = {}, onCreate = { _, _ -> }) }+ rule.onNodeWithText(str(R.string.poll_new)).assertIsDisplayed()+ rule.onNodeWithText(str(R.string.poll_create)).assertIsNotEnabled()+ rule.onNodeWithText(str(R.string.poll_question)).performTextInput("Lunch?")+ rule.onNodeWithText(context.getString(R.string.poll_option, 1)).performTextInput("Pizza")+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.poll_create)).assertIsNotEnabled()+ rule.onNodeWithText(context.getString(R.string.poll_option, 2)).performTextInput("Sushi")+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.poll_create)).assertIsEnabled()+ }++ @Test+ fun `poll create trims and drops blank options`() {+ var created: Pair<String, List<String>>? = null+ var dismissed = 0+ rule.setContent {+ PollComposerDialog(onDismiss = { dismissed++ }, onCreate = { q, o -> created = q to o })+ }+ rule.onNodeWithText(str(R.string.poll_question)).performTextInput(" Lunch? ")+ rule.onNodeWithText(context.getString(R.string.poll_option, 1)).performTextInput(" Pizza ")+ rule.onNodeWithText(context.getString(R.string.poll_option, 2)).performTextInput("Sushi")+ rule.onNodeWithText(str(R.string.poll_add_option)).performClick()+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.poll_create)).performClick()+ rule.waitForIdle()+ assertEquals("Lunch?" to listOf("Pizza", "Sushi"), created)+ assertEquals(1, dismissed)+ }++ @Test+ fun `poll options can be added and removed but never below two`() {+ rule.setContent { PollComposerDialog(onDismiss = {}, onCreate = { _, _ -> }) }+ rule.onNodeWithText(str(R.string.poll_add_option)).performClick()+ rule.waitForIdle()+ rule.onNodeWithText(context.getString(R.string.poll_option, 3)).assertIsDisplayed()+ // Removing the third row returns to the two-row floor.+ rule.onAllNodes(+ androidx.compose.ui.test.hasContentDescriptionExactly("Close"),+ )[0].performClick()+ rule.waitForIdle()+ rule.onNodeWithText(context.getString(R.string.poll_option, 3)).assertDoesNotExist()+ }++ @Test+ fun `poll cancel dismisses without creating`() {+ var created = 0+ var dismissed = 0+ rule.setContent {+ PollComposerDialog(onDismiss = { dismissed++ }, onCreate = { _, _ -> created++ })+ }+ rule.onNodeWithText(str(com.vayunmathur.library.ui.R.string.cancel)).performClick()+ rule.waitForIdle()+ assertEquals(0, created)+ assertEquals(1, dismissed)+ }++ // -- contact intents / cards ----------------------------------------------++ @Test+ fun `contact intents ignore blank numbers`() {+ // No activity is started and nothing throws for a blank number.+ ContactIntents.createNew(context, " ")+ ContactIntents.addToExisting(context, "")+ }++ @Test+ fun `reading an unresolvable contact returns null`() {+ assertNull(readSharedContact(context, Uri.parse("content://com.android.contacts/contacts/999")))+ }++ /** Minimal contacts provider: one contact row, two numbers, one email. */+ private class FakeContactsProvider : android.content.ContentProvider() {+ override fun onCreate(): Boolean = true+ override fun getType(uri: Uri): String? = null+ override fun insert(uri: Uri, values: android.content.ContentValues?): Uri? = null+ override fun delete(uri: Uri, selection: String?, args: Array<String>?): Int = 0+ override fun update(+ uri: Uri, values: android.content.ContentValues?, selection: String?, args: Array<String>?,+ ): Int = 0++ override fun query(+ uri: Uri,+ projection: Array<String>?,+ selection: String?,+ selectionArgs: Array<String>?,+ sortOrder: String?,+ ): android.database.Cursor? {+ val path = uri.toString()+ return when {+ path.contains("phones") -> android.database.MatrixCursor(+ arrayOf(+ android.provider.ContactsContract.CommonDataKinds.Phone.NUMBER,+ android.provider.ContactsContract.CommonDataKinds.Phone.LABEL,+ ),+ ).apply {+ addRow(arrayOf("+155501", "Mobile"))+ addRow(arrayOf(" +155502 ", null))+ addRow(arrayOf(" ", "Home"))+ }+ path.contains("emails") -> android.database.MatrixCursor(+ arrayOf(android.provider.ContactsContract.CommonDataKinds.Email.ADDRESS),+ ).apply {+ addRow(arrayOf(" [email protected] "))+ addRow(arrayOf(" "))+ }+ else -> android.database.MatrixCursor(+ arrayOf(+ android.provider.ContactsContract.Contacts._ID,+ android.provider.ContactsContract.Contacts.DISPLAY_NAME_PRIMARY,+ ),+ ).apply { addRow(arrayOf("5", "Pat Lee")) }+ }+ }+ }++ @Test+ fun `reading a picked contact splits the name and trims rows`() {+ org.robolectric.Shadows.shadowOf(context.contentResolver)+ org.robolectric.shadows.ShadowContentResolver.registerProviderInternal(+ android.provider.ContactsContract.AUTHORITY, FakeContactsProvider(),+ )+ val card = readSharedContact(+ context, Uri.parse("content://com.android.contacts/contacts/5"),+ )+ assertEquals("Pat", card?.givenName)+ assertEquals("Lee", card?.familyName)+ assertEquals(+ listOf("+155501" to "Mobile", "+155502" to null),+ card?.phoneNumbers,+ )+ assertEquals(listOf("[email protected]"), card?.emails)+ }++ @Test+ fun `shared contact card keeps its fields`() {+ val card = SharedContactCard(+ givenName = "Pat",+ familyName = "Lee",+ phoneNumbers = listOf("+1555" to "Mobile"),+ emails = listOf("[email protected]"),+ )+ assertEquals("Pat", card.givenName)+ assertEquals("Lee", card.familyName)+ assertEquals(listOf("+1555" to "Mobile"), card.phoneNumbers)+ assertEquals(listOf("[email protected]"), card.emails)+ }+}
communicate/src/test/java/com/vayunmathur/communicate/ui/RcsScreensUiPass3Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/ui/RcsScreensUiPass3Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/ui/RcsScreensUiPass3Test.ktnew file mode 100644index 0000000000..9807e6896f--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/ui/RcsScreensUiPass3Test.kt@@ -0,0 +1,140 @@+package com.vayunmathur.communicate.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.communicate.R+import com.vayunmathur.communicate.data.rcs.RcsDatabase+import kotlin.test.AfterTest+import kotlin.test.BeforeTest+import kotlin.test.Test+import kotlin.test.assertEquals+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/**+ * UiPass3 coverage for the RCS status + safety-number screens. No carrier+ * is provisioned under Robolectric, so both screens must render their+ * honest "not checked / no key yet" states without touching the network.+ */+@RunWith(RobolectricTestRunner::class)+class RcsScreensUiPass3Test {++ @get:Rule+ val rule = createComposeRule()++ private val context: android.content.Context+ get() = ApplicationProvider.getApplicationContext()++ private fun str(id: Int): String = context.getString(id)++ private lateinit var testDb: RcsDatabase++ @BeforeTest+ fun setUp() {+ testDb = androidx.room3.Room.inMemoryDatabaseBuilder(context, RcsDatabase::class.java)+ .setDriver(androidx.sqlite.driver.bundled.BundledSQLiteDriver())+ .allowMainThreadQueries()+ .build()+ RcsDatabase.overrideForTest = testDb+ }++ @AfterTest+ fun tearDown() {+ RcsDatabase.overrideForTest = null+ testDb.close()+ }++ @Test+ fun `rcs status screen renders the unchecked state`() {+ rule.setContent {+ com.vayunmathur.communicate.ui.rcs.RcsRegistrationScreen(onBack = {})+ }+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.rcs_status_title)).assertIsDisplayed()+ rule.onNodeWithText("RCS").assertIsDisplayed()+ rule.onNodeWithText("Not checked yet").assertIsDisplayed()+ rule.onNodeWithText(str(R.string.rcs_retry)).assertIsDisplayed()+ rule.onNodeWithText(str(R.string.rcs_probe)).assertIsDisplayed()+ }++ @Test+ fun `verify screen shows both parties and the unverified status`() {+ rule.setContent {+ com.vayunmathur.communicate.ui.rcs.RcsVerifyScreen(peerE164 = "+1555", onBack = {})+ }+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.rcs_verify_title)).assertIsDisplayed()+ rule.onNodeWithText("Your safety number").assertIsDisplayed()+ rule.onNodeWithText("+1555").assertIsDisplayed()+ rule.onNodeWithText("Not verified").assertIsDisplayed()+ rule.onNodeWithText(str(R.string.rcs_verify_mark)).assertIsDisplayed()+ rule.onNodeWithText(str(R.string.rcs_verify_clear)).assertIsDisplayed()+ }++ @Test+ fun `verify without a peer key reports instead of crashing`() {+ rule.setContent {+ com.vayunmathur.communicate.ui.rcs.RcsVerifyScreen(peerE164 = "+1555", onBack = {})+ }+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.rcs_verify_mark)).performClick()+ rule.waitForIdle()+ // Still on the same screen (the no-key path only shows a message).+ rule.onNodeWithText("Not verified").assertIsDisplayed()+ }++ @Test+ fun `probe reports unavailable without a carrier config`() {+ rule.setContent {+ com.vayunmathur.communicate.ui.rcs.RcsRegistrationScreen(onBack = {})+ }+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.rcs_probe)).performClick()+ rule.waitForIdle()+ // No config URL was ever probed: the diagnostics line says so.+ rule.onNodeWithText("No carrier RCS config URL", substring = true).assertExists()+ }++ @Test+ fun `encryption banner stays hidden without an mls group`() {+ rule.setContent {+ com.vayunmathur.communicate.ui.RcsEncryptionBanner(+ line = com.vayunmathur.communicate.data.CommunicateLine.Rcs,+ remoteId = null, address = "+1555", refresh = 0,+ )+ }+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.rcs_encrypted_banner)).assertDoesNotExist()+ rule.onNodeWithText(str(R.string.rcs_encrypted_pending)).assertDoesNotExist()+ }++ @Test+ fun `peer typing is false for an idle rcs thread`() {+ var typing: Boolean? = null+ rule.setContent {+ typing = com.vayunmathur.communicate.ui.rememberRcsPeerTyping(+ line = com.vayunmathur.communicate.data.CommunicateLine.Rcs,+ isGroup = false, remoteId = null, address = "+1555",+ )+ }+ rule.waitForIdle()+ assertEquals(false, typing)+ }++ @Test+ fun `group members screen renders its title and empty state`() {+ rule.setContent {+ com.vayunmathur.communicate.ui.rcs.RcsGroupMembersScreen(+ conversationId = "rcs-group:+1555", onBack = {},+ )+ }+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.rcs_group_members_title)).assertIsDisplayed()+ rule.onNodeWithText("No members yet").assertIsDisplayed()+ }++}
communicate/src/test/java/com/vayunmathur/communicate/ui/ScreensUiPass3Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/ui/ScreensUiPass3Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/ui/ScreensUiPass3Test.ktnew file mode 100644index 0000000000..b62e7bb263--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/ui/ScreensUiPass3Test.kt@@ -0,0 +1,225 @@+package com.vayunmathur.communicate.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.hasClickAction+import androidx.compose.ui.test.hasContentDescriptionExactly+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.assertIsEnabled+import androidx.compose.ui.test.assertIsNotEnabled+import androidx.compose.ui.test.performTextInput+import androidx.compose.ui.test.performClick+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.communicate.R+import com.vayunmathur.communicate.data.CommunicateLine+import kotlin.test.Test+import kotlin.test.assertEquals+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/**+ * UiPass3 coverage for the top-level screens in their gated/empty states+ * (no default-app role, no permissions, empty providers under Robolectric)+ * plus a full [ConversationScreen] composition on an empty SIM thread and+ * the video layer with no call bound.+ */+@RunWith(RobolectricTestRunner::class)+class ScreensUiPass3Test {++ @get:Rule+ val rule = createComposeRule()++ private val context: android.content.Context+ get() = ApplicationProvider.getApplicationContext()++ private fun str(id: Int): String = context.getString(id)++ @Test+ fun `messages screen asks for the sms role first`() {+ rule.setContent { MessagesScreen(onOpenThread = {}, onOpenAccounts = {}) }+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.messages_title)).assertIsDisplayed()+ rule.onNodeWithText(str(R.string.default_app_title)).assertIsDisplayed()+ }++ @Test+ fun `messages screen accounts button reports`() {+ var accounts = 0+ rule.setContent { MessagesScreen(onOpenThread = {}, onOpenAccounts = { accounts++ }) }+ rule.waitForIdle()+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("Person")).performClick()+ rule.waitForIdle()+ assertEquals(1, accounts)+ }++ @Test+ fun `messages fab opens the new-message picker`() {+ rule.setContent { MessagesScreen(onOpenThread = {}, onOpenAccounts = {}) }+ rule.waitForIdle()+ rule.onNode(+ androidx.compose.ui.test.hasClickAction() and+ androidx.compose.ui.test.hasContentDescriptionExactly("Add"),+ ).performClick()+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.new_message)).assertIsDisplayed()+ }++ @Test+ fun `messages picker composes to a sim thread from a typed number`() {+ org.robolectric.Shadows.shadowOf(context as android.app.Application)+ .grantPermissions(android.Manifest.permission.READ_CONTACTS)+ val opened = mutableListOf<com.vayunmathur.communicate.data.SmsThread>()+ rule.setContent {+ MessagesScreen(onOpenThread = { opened.add(it) }, onOpenAccounts = {})+ }+ rule.waitForIdle()+ rule.onNode(+ androidx.compose.ui.test.hasClickAction() and+ androidx.compose.ui.test.hasContentDescriptionExactly("Add"),+ ).performClick()+ rule.waitForIdle()+ rule.onNodeWithText("Search name or number").performTextInput("5550100")+ rule.waitForIdle()+ rule.onNodeWithText("Send to", substring = true).performClick()+ rule.waitForIdle()+ assertEquals(1, opened.size)+ assertEquals("5550100", opened[0].address)+ assertEquals(CommunicateLine.Sim, opened[0].line)+ }++ @Test+ fun `conversation send clears the draft`() {+ rule.setContent {+ ConversationScreen(+ threadId = -1L, address = "+1555", line = CommunicateLine.Sim,+ remoteId = null, onBack = {},+ )+ }+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.message_hint)).performTextInput("hello thread")+ rule.waitForIdle()+ rule.onNode(+ androidx.compose.ui.test.hasClickAction() and+ androidx.compose.ui.test.hasContentDescriptionExactly("Send"),+ ).performClick()+ rule.waitForIdle()+ // Draft cleared by the send handler (the send itself is provider work).+ rule.onNodeWithText("hello thread").assertDoesNotExist()+ rule.onNodeWithText(str(R.string.message_hint)).assertIsDisplayed()+ }++ @Test+ fun `call logs screen asks for the dialer role first`() {+ rule.setContent { CallLogsScreen() }+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.call_logs_title)).assertIsDisplayed()+ rule.onNodeWithText(str(R.string.default_app_title)).assertIsDisplayed()+ }++ @Test+ fun `voicemail screen asks for the dialer role first`() {+ rule.setContent { VoicemailScreen() }+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.voicemail_title)).assertIsDisplayed()+ rule.onNodeWithText(str(R.string.default_app_title)).assertIsDisplayed()+ }++ @Test+ fun `dialer screen asks for the dialer role first`() {+ rule.setContent { DialerScreen() }+ rule.waitForIdle()+ rule.onNodeWithText(str(R.string.dialer_title)).assertIsDisplayed()+ rule.onNodeWithText(str(R.string.default_app_title)).assertIsDisplayed()+ }++ @Test+ fun `conversation screen composes an empty sim thread`() {+ rule.setContent {+ ConversationScreen(+ threadId = -1L, address = "+1555", line = CommunicateLine.Sim,+ remoteId = null, onBack = {},+ )+ }+ rule.waitForIdle()+ rule.onNodeWithText("+1555").assertIsDisplayed()+ rule.onNodeWithText(str(R.string.message_hint)).assertIsDisplayed()+ }++ @Test+ fun `conversation screen composes a group thread with its title`() {+ rule.setContent {+ ConversationScreen(+ threadId = -1L, address = "g1", line = CommunicateLine.Sim,+ remoteId = "g1", isGroup = true,+ participants = listOf("+1555", "+1666"), groupTitle = "Family",+ onBack = {},+ )+ }+ rule.waitForIdle()+ rule.onNodeWithText("Family").assertIsDisplayed()+ }++ @Test+ fun `typing in a conversation enables send`() {+ rule.setContent {+ ConversationScreen(+ threadId = -1L, address = "+1555", line = CommunicateLine.Sim,+ remoteId = null, onBack = {},+ )+ }+ rule.waitForIdle()+ rule.onNode(+ androidx.compose.ui.test.hasClickAction() and+ androidx.compose.ui.test.hasContentDescriptionExactly("Send"),+ ).assertIsNotEnabled()+ rule.onNodeWithText(str(R.string.message_hint))+ .performTextInput("hello thread")+ rule.waitForIdle()+ rule.onNode(+ androidx.compose.ui.test.hasClickAction() and+ androidx.compose.ui.test.hasContentDescriptionExactly("Send"),+ ).assertIsEnabled()+ }++ @Test+ fun `call video composes nothing without a video controller`() {+ rule.setContent {+ com.vayunmathur.communicate.ui.call.CallVideo(showRemote = true, showLocal = true)+ }+ rule.waitForIdle()+ // No controller bound: the layer returns before creating any renderer.+ assertEquals(+ true,+ com.vayunmathur.communicate.data.call.InAppCallRegistry.videoController == null,+ )+ }++ @Test+ fun `call video stops at a controller with no egl context`() {+ val controller = object :+ com.vayunmathur.communicate.data.call.InAppCallVideoController {+ override fun setVideoEnabled(enabled: Boolean) = Unit+ override fun flipCamera() = Unit+ override fun eglContext(): org.webrtc.EglBase.Context? = null+ override fun attachLocalRenderer(sink: org.webrtc.VideoSink?) = Unit+ override fun attachRemoteRenderer(sink: org.webrtc.VideoSink?) = Unit+ override fun setScreenShareEnabled(enabled: Boolean, permission: android.content.Intent?) = Unit+ }+ com.vayunmathur.communicate.data.call.InAppCallRegistry.videoController = controller+ try {+ rule.setContent {+ com.vayunmathur.communicate.ui.call.CallVideo(showRemote = true, showLocal = true)+ }+ rule.waitForIdle()+ // Null EGL context: still no renderer (a renderer without the shared+ // context would crash the decoder thread).+ assertEquals(+ controller,+ com.vayunmathur.communicate.data.call.InAppCallRegistry.videoController,+ )+ } finally {+ com.vayunmathur.communicate.data.call.InAppCallRegistry.videoController = null+ }+ }+}
communicate/src/test/java/com/vayunmathur/communicate/ui/VoicemailUiPass3Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/ui/VoicemailUiPass3Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/ui/VoicemailUiPass3Test.ktnew file mode 100644index 0000000000..e677c76f01--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/ui/VoicemailUiPass3Test.kt@@ -0,0 +1,163 @@+package com.vayunmathur.communicate.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.hasClickAction+import androidx.compose.ui.test.hasContentDescriptionExactly+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.communicate.R+import com.vayunmathur.communicate.data.CommunicateLine+import com.vayunmathur.communicate.data.VoicemailEntry+import kotlin.test.Test+import kotlin.test.assertEquals+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/**+ * UiPass3 coverage for the voicemail list (`VoicemailContent.kt`): rows,+ * expand/collapse, transcripts, the no-audio state and delete-confirm.+ * The ExoPlayer itself needs real media codecs, so expanded rows here use+ * `hasAudio = false`; player behaviour is listed as an untestable remainder.+ */+@RunWith(RobolectricTestRunner::class)+class VoicemailUiPass3Test {++ @get:Rule+ val rule = createComposeRule()++ private val context: android.content.Context+ get() = ApplicationProvider.getApplicationContext()++ private fun str(id: Int): String = context.getString(id)++ private fun entry(+ id: Long = 1L,+ number: String = "+1555",+ read: Boolean = true,+ hasAudio: Boolean = false,+ transcript: String? = null,+ line: CommunicateLine = CommunicateLine.Sim,+ ) = VoicemailEntry(+ id = id,+ phoneNumber = number,+ timestampMillis = System.currentTimeMillis(),+ durationSeconds = 42L,+ contentUri = "content://voicemail/$id",+ mimeType = "audio/amr",+ hasAudio = hasAudio,+ transcript = transcript,+ isRead = read,+ line = line,+ )++ @Test+ fun `rows show the number and expand on tap`() {+ val toggled = mutableListOf<VoicemailEntry>()+ val e = entry()+ rule.setContent {+ VoicemailContent(+ entries = listOf(e), expandedId = null,+ onToggleExpand = { toggled.add(it) }, onDelete = {},+ )+ }+ rule.onNodeWithText("+1555").assertIsDisplayed()+ rule.onNodeWithText("+1555").performClick()+ rule.waitForIdle()+ assertEquals(listOf(e), toggled)+ }++ @Test+ fun `expanded row without audio says so`() {+ val e = entry(hasAudio = false)+ rule.setContent {+ VoicemailContent(+ entries = listOf(e), expandedId = e.id,+ onToggleExpand = {}, onDelete = {},+ )+ }+ rule.onNodeWithText(str(R.string.voicemail_no_audio)).assertIsDisplayed()+ }++ @Test+ fun `expanded row shows its transcript`() {+ val e = entry(transcript = "call me back please")+ rule.setContent {+ VoicemailContent(+ entries = listOf(e), expandedId = e.id,+ onToggleExpand = {}, onDelete = {},+ )+ }+ rule.onNodeWithText("call me back please").assertIsDisplayed()+ }++ @Test+ fun `collapsed row hides its transcript`() {+ val e = entry(transcript = "call me back please")+ rule.setContent {+ VoicemailContent(+ entries = listOf(e), expandedId = null,+ onToggleExpand = {}, onDelete = {},+ )+ }+ rule.onNodeWithText("call me back please").assertDoesNotExist()+ }++ @Test+ fun `delete asks first and only then deletes`() {+ val deleted = mutableListOf<VoicemailEntry>()+ val e = entry()+ rule.setContent {+ VoicemailContent(+ entries = listOf(e), expandedId = null,+ onToggleExpand = {}, onDelete = { deleted.add(it) },+ )+ }+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("More")).performClick()+ rule.onNodeWithText(str(com.vayunmathur.library.ui.R.string.delete)).performClick()+ rule.onNodeWithText(str(R.string.delete_voicemail_title)).assertIsDisplayed()+ assertEquals(emptyList(), deleted)+ rule.onNodeWithText(str(com.vayunmathur.library.ui.R.string.delete)).performClick()+ rule.waitForIdle()+ assertEquals(listOf(e), deleted)+ }++ @Test+ fun `google voice rows render their line tag`() {+ rule.setContent {+ VoicemailContent(+ entries = listOf(entry(line = CommunicateLine.GoogleVoice)),+ expandedId = null, onToggleExpand = {}, onDelete = {},+ )+ }+ rule.onNodeWithText("+1555").assertIsDisplayed()+ rule.onNodeWithText(str(R.string.line_gv)).assertIsDisplayed()+ }++ @Test+ fun `player composes with a play control for an unreachable clip`() {+ var played = 0+ rule.setContent {+ VoicemailPlayer(audioUri = "content://voicemail/1", onPlayed = { played++ })+ }+ rule.waitForIdle()+ rule.onNode(+ androidx.compose.ui.test.hasClickAction() and+ androidx.compose.ui.test.hasContentDescriptionExactly("Play"),+ ).assertExists()+ assertEquals(0, played)+ }++ @Test+ fun `empty list composes without rows`() {+ rule.setContent {+ VoicemailContent(+ entries = emptyList(), expandedId = null,+ onToggleExpand = {}, onDelete = {},+ )+ }+ rule.onNodeWithText("+1555").assertDoesNotExist()+ }+}