package com.cottondb.messages.warmimport android.app.Applicationimport androidx.activity.ComponentActivityimport androidx.compose.ui.test.assertIsDisplayedimport androidx.compose.ui.test.junit4.createAndroidComposeRuleimport androidx.compose.ui.test.onNodeWithTagimport androidx.compose.ui.test.onNodeWithTextimport androidx.compose.ui.test.performClickimport kotlinx.serialization.json.Jsonimport kotlinx.serialization.json.jsonObjectimport org.junit.Assert.assertEqualsimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Config/** * Blocked stays in Comms when Senders leaves with Mail (COMMS WITHOUT MAIL, 26 Nov 2026): the one place a blocked * sender's texts wait 30 days, each saying when it is erased, with Unblock, and an act the Mac has still to do with * Try again. Invented senders. */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w400dp-h860dp-xhdpi", application = Application::class)classBlockedPageTest { @get:Ruleval compose = createAndroidComposeRule<ComponentActivity>() @Test fun blocked_says_when_each_is_erased_and_unblocks() {val blocked = Json.parseToJsonElement("""{"title":"Blocked","line":"Nothing from these shows anywhere else in Comms.","empty":"Nobody is blocked.","rows":[{"key":"HDFCBK","kind":"name","name":"HDFCBK","sent":7,"sentLine":"7 messages","erases":"Erased on 24 December 2026","unblock":"Unblock"}]}""").jsonObjectvar unblocked: String? = null compose.setContent { WarmTheme(night = false) { BlockedPage(blocked, "Back", onBack = {}) { unblocked = it } } } compose.onNodeWithText("7 messages · Erased on 24 December 2026").assertIsDisplayed() compose.onNodeWithTag("unblock-HDFCBK").performClick() assertEquals("HDFCBK", unblocked) } @Test fun nobody_blocked_says_so() {val blocked = Json.parseToJsonElement("""{"title":"Blocked","empty":"Nobody is blocked.","rows":[]}""").jsonObject compose.setContent { WarmTheme(night = false) { BlockedPage(blocked, "Back", onBack = {}) {} } } compose.onNodeWithTag("blocked-empty").assertIsDisplayed() compose.onNodeWithText("Nobody is blocked.").assertIsDisplayed() }/** ACTS TRUTH: a block the Mac could not carry to WhatsApp says why on its row, with Try again. */ @Test fun a_failed_block_on_whatsapp_says_why_and_offers_try_again() {val blocked = Json.parseToJsonElement("""{"title":"Blocked","rows":[{"key":"+15550107301","kind":"number","name":"Promo Deals","sentLine":"3 messages","erases":"Erased on 24 December 2026","unblock":"Unblock", "source":{"kind":"block","state":"failed","line":"Not blocked on WhatsApp: your Mac could not do it","retry":"Try again"}}]}""").jsonObjectvar retried: String? = null compose.setContent { WarmTheme(night = false) { BlockedPage(blocked, "Back", onBack = {}, onRetry = { retried = it }) {} } } compose.onNodeWithText("Not blocked on WhatsApp: your Mac could not do it").assertIsDisplayed() compose.onNodeWithTag("sender-retry-+15550107301").performClick() assertEquals("+15550107301", retried) }}