69 lines · 3.1 KB · KotlinRaw
package com.cottondb.messages.warmimport android.app.Applicationimport androidx.activity.ComponentActivityimport androidx.compose.ui.test.assertCountEqualsimport androidx.compose.ui.test.assertIsDisplayedimport androidx.compose.ui.test.junit4.createAndroidComposeRuleimport androidx.compose.ui.test.onNodeWithTagimport androidx.compose.ui.test.performScrollToimport com.cottondb.messages.chat.Avatarimport org.junit.Assert.assertEqualsimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport 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<ComponentActivity>() 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() }}