package com.cottondb.messages.warm import android.app.Application import androidx.activity.ComponentActivity import androidx.compose.ui.test.assertCountEquals import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performScrollTo import com.cottondb.messages.chat.Avatar 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 /** * A person imported from WhatsApp has no number: Block (asked first) then only drew the core's refusal "This chat * isn't a Cotton chat.", so it is not offered there; a Cotton person keeps it. Invented people. */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], qualifiers = "w400dp-h860dp-mdpi", application = Application::class) class PersonPageTest { @get:Rule val compose = createAndroidComposeRule() private val words = PersonWords( "Back", "Message", "Call", "Video", "Between you", "Nothing between you yet.", { "Calls themselves $it" }, "Number", "Mute", "Unmute", "Mute notifications", "Block", "Unblock", "You blocked them.", "Close", ) private fun page(number: String?) { compose.setContent { WarmTheme(night = false) { PersonPage(PersonView("Odile Example", null, Avatar("OE", 1, null), number, "", emptyList(), emptyList(), false, false, emptyList(), emptyList()), words, {}, {}, {}, {}, {}, {}, {}) } } compose.waitForIdle() } @Test fun an_imported_person_with_no_number_is_offered_no_block() { page(null) assertEquals(0, compose.onAllNodes(androidx.compose.ui.test.hasTestTag("person-block")).fetchSemanticsNodes().size) } /** Each photo of Between you is "Photo" to TalkBack: all were named "Between you", the heading's own words. */ @Test fun a_photo_between_you_is_named_photo() { compose.setContent { WarmTheme(night = false) { val view = PersonView("Odile Example", null, Avatar("OE", 1, null), "+15550139888", "", listOf("msg:a:0", "msg:b:0"), emptyList(), false, false, emptyList(), emptyList()) val named = PersonWords( "Back", "Message", "Call", "Video", "Between you", "Nothing between you yet.", { "Calls themselves $it" }, "Number", "Mute", "Unmute", "Mute notifications", "Block", "Unblock", "You blocked them.", "Close", photo = "Photo", ) PersonPage(view, named, {}, {}, {}, {}, {}, {}, {}) } } compose.onAllNodes(androidx.compose.ui.test.hasContentDescription("Photo")).assertCountEquals(2) compose.onAllNodes(androidx.compose.ui.test.hasContentDescription("Between you")).assertCountEquals(0) } @Test fun a_cotton_person_keeps_block() { page("+15550139888") compose.onNodeWithTag("person-block").performScrollTo().assertIsDisplayed() } }