package com.cottondb.messages.warm import android.app.Application import androidx.activity.ComponentActivity import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import kotlinx.serialization.json.Json import kotlinx.serialization.json.jsonObject import org.junit.Assert.assertEquals import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import 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) class BlockedPageTest { @get:Rule val compose = createAndroidComposeRule() @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"}]}""").jsonObject var 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"}}]}""").jsonObject var 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) } }