Fix HomeActivityTests

This commit is contained in:
Andrew 2024-03-20 13:01:44 +10:30
parent d083b19a12
commit 92c2d574ae
7 changed files with 50 additions and 22 deletions

View File

@ -363,14 +363,16 @@ dependencies {
implementation 'androidx.compose.ui:ui:1.6.2' implementation 'androidx.compose.ui:ui:1.6.2'
implementation 'androidx.compose.animation:animation:1.6.2' implementation 'androidx.compose.animation:animation:1.6.2'
implementation 'androidx.compose.ui:ui-tooling:1.6.2' implementation 'androidx.compose.ui:ui-tooling:1.6.2'
implementation "androidx.compose.runtime:runtime-livedata:1.6.2"
implementation 'androidx.compose.foundation:foundation-layout:1.6.2'
implementation 'androidx.compose.material:material:1.6.2'
androidTestImplementation 'androidx.compose.ui:ui-test-junit4-android:1.6.2'
debugImplementation 'androidx.compose.ui:ui-test-manifest:1.6.2'
implementation "com.google.accompanist:accompanist-themeadapter-appcompat:0.33.1-alpha" implementation "com.google.accompanist:accompanist-themeadapter-appcompat:0.33.1-alpha"
implementation "com.google.accompanist:accompanist-pager:0.33.1-alpha" implementation "com.google.accompanist:accompanist-pager:0.33.1-alpha"
implementation "com.google.accompanist:accompanist-pager-indicators:0.33.1-alpha" implementation "com.google.accompanist:accompanist-pager-indicators:0.33.1-alpha"
implementation "com.google.accompanist:accompanist-permissions:0.33.1-alpha" implementation "com.google.accompanist:accompanist-permissions:0.33.1-alpha"
implementation "androidx.compose.runtime:runtime-livedata:1.6.2"
implementation 'androidx.compose.foundation:foundation-layout:1.6.2'
implementation 'androidx.compose.material:material:1.6.2'
implementation "androidx.camera:camera-camera2:1.3.1" implementation "androidx.camera:camera-camera2:1.3.1"
implementation "androidx.camera:camera-lifecycle:1.3.1" implementation "androidx.camera:camera-lifecycle:1.3.1"

View File

@ -22,6 +22,8 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest import androidx.test.filters.LargeTest
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import com.adevinta.android.barista.interaction.PermissionGranter import com.adevinta.android.barista.interaction.PermissionGranter
import network.loki.messenger.util.InputBarButtonDrawableMatcher.Companion.inputButtonWithDrawable import network.loki.messenger.util.InputBarButtonDrawableMatcher.Companion.inputButtonWithDrawable
import org.hamcrest.Matcher import org.hamcrest.Matcher
@ -49,9 +51,14 @@ class HomeActivityTests {
private val activityMonitor = Instrumentation.ActivityMonitor(ConversationActivityV2::class.java.name, null, false) private val activityMonitor = Instrumentation.ActivityMonitor(ConversationActivityV2::class.java.name, null, false)
private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
private val context = InstrumentationRegistry.getInstrumentation().targetContext
@Before @Before
fun setUp() { fun setUp() {
InstrumentationRegistry.getInstrumentation().addMonitor(activityMonitor) InstrumentationRegistry.getInstrumentation().addMonitor(activityMonitor)
} }
@After @After
@ -72,25 +79,34 @@ class HomeActivityTests {
onView(isRoot()).perform(waitFor(500)) onView(isRoot()).perform(waitFor(500))
} }
private fun objectFromDesc(id: Int) = device.findObject(By.desc(context.getString(id)))
private fun setupLoggedInState(hasViewedSeed: Boolean = false) { private fun setupLoggedInState(hasViewedSeed: Boolean = false) {
// landing activity // landing activity
onView(withId(R.id.registerButton)).perform(ViewActions.click()) objectFromDesc(R.string.onboardingAccountCreate).click()
// session ID - register activity
onView(withId(R.id.registerButton)).perform(ViewActions.click())
// display name selection // display name selection
onView(withId(R.id.displayNameEditText)).perform(ViewActions.typeText("test-user123")) objectFromDesc(R.string.displayNameEnter).click()
onView(withId(R.id.registerButton)).perform(ViewActions.click()) device.pressKeyCode(28)
device.pressKeyCode(29)
device.pressKeyCode(30)
// Continue with display name
objectFromDesc(R.string.continue_2).click()
// Continue with default push notification setting
objectFromDesc(R.string.continue_2).click()
// PN select // PN select
if (hasViewedSeed) { if (hasViewedSeed) {
// has viewed seed is set to false after register activity // has viewed seed is set to false after register activity
TextSecurePreferences.setHasViewedSeed(InstrumentationRegistry.getInstrumentation().targetContext, true) TextSecurePreferences.setHasViewedSeed(InstrumentationRegistry.getInstrumentation().targetContext, true)
} }
onView(withId(R.id.backgroundPollingOptionView)).perform(ViewActions.click())
onView(withId(R.id.registerButton)).perform(ViewActions.click())
// allow notification permission // allow notification permission
PermissionGranter.allowPermissionsIfNeeded(Manifest.permission.POST_NOTIFICATIONS) PermissionGranter.allowPermissionsIfNeeded(Manifest.permission.POST_NOTIFICATIONS)
} }
private fun goToMyChat() { private fun goToMyChat() {
onView(withId(R.id.newConversationButton)).perform(ViewActions.click()) onView(withId(R.id.newConversationButton)).perform(ViewActions.click())
onView(withId(R.id.createPrivateChatButton)).perform(ViewActions.click()) onView(withId(R.id.createPrivateChatButton)).perform(ViewActions.click())
@ -111,8 +127,8 @@ class HomeActivityTests {
@Test @Test
fun testLaunches_dismiss_seedView() { fun testLaunches_dismiss_seedView() {
setupLoggedInState() setupLoggedInState()
onView(allOf(withId(R.id.button), isDescendantOfA(withId(R.id.seedReminderView)))).perform(ViewActions.click()) objectFromDesc(R.string.continue_2).click()
onView(withId(R.id.copyButton)).perform(ViewActions.click()) objectFromDesc(R.string.copy).click()
pressBack() pressBack()
onView(withId(R.id.seedReminderView)).check(matches(not(isDisplayed()))) onView(withId(R.id.seedReminderView)).check(matches(not(isDisplayed())))
} }
@ -133,7 +149,7 @@ class HomeActivityTests {
fun testChat_withSelf() { fun testChat_withSelf() {
setupLoggedInState() setupLoggedInState()
goToMyChat() goToMyChat()
TextSecurePreferences.setLinkPreviewsEnabled(InstrumentationRegistry.getInstrumentation().targetContext, true) TextSecurePreferences.setLinkPreviewsEnabled(context, true)
sendMessage("howdy") sendMessage("howdy")
sendMessage("test") sendMessage("test")
// tests url rewriter doesn't crash // tests url rewriter doesn't crash

View File

@ -103,6 +103,7 @@ import org.thoughtcrime.securesms.ui.OutlineButton
import org.thoughtcrime.securesms.ui.PreviewTheme import org.thoughtcrime.securesms.ui.PreviewTheme
import org.thoughtcrime.securesms.ui.SessionShieldIcon import org.thoughtcrime.securesms.ui.SessionShieldIcon
import org.thoughtcrime.securesms.ui.ThemeResPreviewParameterProvider import org.thoughtcrime.securesms.ui.ThemeResPreviewParameterProvider
import org.thoughtcrime.securesms.ui.contentDescription
import org.thoughtcrime.securesms.ui.h8 import org.thoughtcrime.securesms.ui.h8
import org.thoughtcrime.securesms.ui.small import org.thoughtcrime.securesms.ui.small
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities

View File

@ -36,6 +36,7 @@ import org.thoughtcrime.securesms.ui.BorderlessButton
import org.thoughtcrime.securesms.ui.FilledButton import org.thoughtcrime.securesms.ui.FilledButton
import org.thoughtcrime.securesms.ui.OutlineButton import org.thoughtcrime.securesms.ui.OutlineButton
import org.thoughtcrime.securesms.ui.classicDarkColors import org.thoughtcrime.securesms.ui.classicDarkColors
import org.thoughtcrime.securesms.ui.contentDescription
import org.thoughtcrime.securesms.ui.session_accent import org.thoughtcrime.securesms.ui.session_accent
import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo
@ -77,9 +78,11 @@ class LandingActivity : BaseActionBarActivity() {
OutgoingText(stringResource(R.string.onboardingBubbleCreatingAnAccountIsEasy)) OutgoingText(stringResource(R.string.onboardingBubbleCreatingAnAccountIsEasy))
Spacer(modifier = Modifier.weight(1f)) Spacer(modifier = Modifier.weight(1f))
OutlineButton(text = stringResource(R.string.onboardingAccountCreate), modifier = Modifier OutlineButton(
.width(262.dp) text = stringResource(R.string.onboardingAccountCreate),
.align(Alignment.CenterHorizontally)) { startPickDisplayNameActivity() } modifier = Modifier
.width(262.dp)
.align(Alignment.CenterHorizontally)) { startPickDisplayNameActivity() }
Spacer(modifier = Modifier.height(14.dp)) Spacer(modifier = Modifier.height(14.dp))
FilledButton(text = stringResource(R.string.onboardingAccountExists), modifier = Modifier FilledButton(text = stringResource(R.string.onboardingAccountExists), modifier = Modifier
.width(262.dp) .width(262.dp)

View File

@ -22,8 +22,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -38,8 +38,7 @@ import org.thoughtcrime.securesms.ui.OutlineButton
import org.thoughtcrime.securesms.ui.PreviewTheme import org.thoughtcrime.securesms.ui.PreviewTheme
import org.thoughtcrime.securesms.ui.base import org.thoughtcrime.securesms.ui.base
import org.thoughtcrime.securesms.ui.baseBold import org.thoughtcrime.securesms.ui.baseBold
import org.thoughtcrime.securesms.ui.classicDark3 import org.thoughtcrime.securesms.ui.contentDescription
import org.thoughtcrime.securesms.ui.colorDestructive
import org.thoughtcrime.securesms.ui.outlinedTextFieldColors import org.thoughtcrime.securesms.ui.outlinedTextFieldColors
import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo
import javax.inject.Inject import javax.inject.Inject
@ -106,6 +105,7 @@ class PickDisplayNameActivity : BaseActionBarActivity() {
OutlinedTextField( OutlinedTextField(
value = state.displayName, value = state.displayName,
modifier = Modifier.contentDescription(R.string.displayNameEnter),
onValueChange = { onChange(it) }, onValueChange = { onChange(it) },
placeholder = { Text(stringResource(R.string.displayNameEnter)) }, placeholder = { Text(stringResource(R.string.displayNameEnter)) },
colors = outlinedTextFieldColors(state.error != null), colors = outlinedTextFieldColors(state.error != null),

View File

@ -71,7 +71,7 @@ fun OutlineButton(
onClick: () -> Unit onClick: () -> Unit
) { ) {
OutlinedButton( OutlinedButton(
modifier = modifier, modifier = modifier.contentDescription(GetString(text)),
onClick = onClick, onClick = onClick,
border = BorderStroke(1.dp, color), border = BorderStroke(1.dp, color),
shape = RoundedCornerShape(50), // = 50% percent shape = RoundedCornerShape(50), // = 50% percent
@ -262,6 +262,12 @@ fun Modifier.contentDescription(text: GetString?): Modifier {
return text?.let { semantics { contentDescription = it(context) } } ?: this return text?.let { semantics { contentDescription = it(context) } } ?: this
} }
@Composable
fun Modifier.contentDescription(id: Int?): Modifier {
val context = LocalContext.current
return id?.let { semantics { contentDescription = context.getString(it) } } ?: this
}
@Composable @Composable
fun OutlineButton(text: GetString, contentDescription: GetString? = text, modifier: Modifier = Modifier, onClick: () -> Unit) { fun OutlineButton(text: GetString, contentDescription: GetString? = text, modifier: Modifier = Modifier, onClick: () -> Unit) {
OutlinedButton( OutlinedButton(

View File

@ -16,7 +16,7 @@ android.enableJetifier=true
org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M" org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M"
org.gradle.unsafe.configuration-cache=true org.gradle.unsafe.configuration-cache=true
gradlePluginVersion=7.4.2 gradlePluginVersion=7.3.1
googleServicesVersion=4.3.12 googleServicesVersion=4.3.12
kotlinVersion=1.8.21 kotlinVersion=1.8.21
android.useAndroidX=true android.useAndroidX=true