From 92c2d574ae3067c6c199aea65779758fe3a7ad94 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 20 Mar 2024 13:01:44 +1030 Subject: [PATCH] Fix HomeActivityTests --- app/build.gradle | 10 +++--- .../loki/messenger/HomeActivityTests.kt | 36 +++++++++++++------ .../securesms/home/HomeActivity.kt | 1 + .../securesms/onboarding/LandingActivity.kt | 9 +++-- .../pickname/PickDisplayNameActivity.kt | 6 ++-- .../thoughtcrime/securesms/ui/Components.kt | 8 ++++- gradle.properties | 2 +- 7 files changed, 50 insertions(+), 22 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 23fb571d75..7fa2d15fd5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -363,14 +363,16 @@ dependencies { implementation 'androidx.compose.ui:ui:1.6.2' implementation 'androidx.compose.animation:animation: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-pager: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 "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-lifecycle:1.3.1" diff --git a/app/src/androidTest/java/network/loki/messenger/HomeActivityTests.kt b/app/src/androidTest/java/network/loki/messenger/HomeActivityTests.kt index a20a3a2a67..258ba95183 100644 --- a/app/src/androidTest/java/network/loki/messenger/HomeActivityTests.kt +++ b/app/src/androidTest/java/network/loki/messenger/HomeActivityTests.kt @@ -22,6 +22,8 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.LargeTest import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.uiautomator.By +import androidx.test.uiautomator.UiDevice import com.adevinta.android.barista.interaction.PermissionGranter import network.loki.messenger.util.InputBarButtonDrawableMatcher.Companion.inputButtonWithDrawable import org.hamcrest.Matcher @@ -49,9 +51,14 @@ class HomeActivityTests { 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 fun setUp() { InstrumentationRegistry.getInstrumentation().addMonitor(activityMonitor) + } @After @@ -72,25 +79,34 @@ class HomeActivityTests { onView(isRoot()).perform(waitFor(500)) } + private fun objectFromDesc(id: Int) = device.findObject(By.desc(context.getString(id))) + private fun setupLoggedInState(hasViewedSeed: Boolean = false) { // landing activity - onView(withId(R.id.registerButton)).perform(ViewActions.click()) - // session ID - register activity - onView(withId(R.id.registerButton)).perform(ViewActions.click()) + objectFromDesc(R.string.onboardingAccountCreate).click() + // display name selection - onView(withId(R.id.displayNameEditText)).perform(ViewActions.typeText("test-user123")) - onView(withId(R.id.registerButton)).perform(ViewActions.click()) + objectFromDesc(R.string.displayNameEnter).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 if (hasViewedSeed) { // has viewed seed is set to false after register activity 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 PermissionGranter.allowPermissionsIfNeeded(Manifest.permission.POST_NOTIFICATIONS) } + private fun goToMyChat() { onView(withId(R.id.newConversationButton)).perform(ViewActions.click()) onView(withId(R.id.createPrivateChatButton)).perform(ViewActions.click()) @@ -111,8 +127,8 @@ class HomeActivityTests { @Test fun testLaunches_dismiss_seedView() { setupLoggedInState() - onView(allOf(withId(R.id.button), isDescendantOfA(withId(R.id.seedReminderView)))).perform(ViewActions.click()) - onView(withId(R.id.copyButton)).perform(ViewActions.click()) + objectFromDesc(R.string.continue_2).click() + objectFromDesc(R.string.copy).click() pressBack() onView(withId(R.id.seedReminderView)).check(matches(not(isDisplayed()))) } @@ -133,7 +149,7 @@ class HomeActivityTests { fun testChat_withSelf() { setupLoggedInState() goToMyChat() - TextSecurePreferences.setLinkPreviewsEnabled(InstrumentationRegistry.getInstrumentation().targetContext, true) + TextSecurePreferences.setLinkPreviewsEnabled(context, true) sendMessage("howdy") sendMessage("test") // tests url rewriter doesn't crash diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt index 36c0962bad..6a7eaa508a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt @@ -103,6 +103,7 @@ import org.thoughtcrime.securesms.ui.OutlineButton import org.thoughtcrime.securesms.ui.PreviewTheme import org.thoughtcrime.securesms.ui.SessionShieldIcon import org.thoughtcrime.securesms.ui.ThemeResPreviewParameterProvider +import org.thoughtcrime.securesms.ui.contentDescription import org.thoughtcrime.securesms.ui.h8 import org.thoughtcrime.securesms.ui.small import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LandingActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LandingActivity.kt index d30cef79c0..dedb0ed85e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LandingActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LandingActivity.kt @@ -36,6 +36,7 @@ import org.thoughtcrime.securesms.ui.BorderlessButton import org.thoughtcrime.securesms.ui.FilledButton import org.thoughtcrime.securesms.ui.OutlineButton import org.thoughtcrime.securesms.ui.classicDarkColors +import org.thoughtcrime.securesms.ui.contentDescription import org.thoughtcrime.securesms.ui.session_accent import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo @@ -77,9 +78,11 @@ class LandingActivity : BaseActionBarActivity() { OutgoingText(stringResource(R.string.onboardingBubbleCreatingAnAccountIsEasy)) Spacer(modifier = Modifier.weight(1f)) - OutlineButton(text = stringResource(R.string.onboardingAccountCreate), modifier = Modifier - .width(262.dp) - .align(Alignment.CenterHorizontally)) { startPickDisplayNameActivity() } + OutlineButton( + text = stringResource(R.string.onboardingAccountCreate), + modifier = Modifier + .width(262.dp) + .align(Alignment.CenterHorizontally)) { startPickDisplayNameActivity() } Spacer(modifier = Modifier.height(14.dp)) FilledButton(text = stringResource(R.string.onboardingAccountExists), modifier = Modifier .width(262.dp) diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/pickname/PickDisplayNameActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/pickname/PickDisplayNameActivity.kt index d39ee90807..07ed9f7d22 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/pickname/PickDisplayNameActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/pickname/PickDisplayNameActivity.kt @@ -22,8 +22,8 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.ComposeView +import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview 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.base import org.thoughtcrime.securesms.ui.baseBold -import org.thoughtcrime.securesms.ui.classicDark3 -import org.thoughtcrime.securesms.ui.colorDestructive +import org.thoughtcrime.securesms.ui.contentDescription import org.thoughtcrime.securesms.ui.outlinedTextFieldColors import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo import javax.inject.Inject @@ -106,6 +105,7 @@ class PickDisplayNameActivity : BaseActionBarActivity() { OutlinedTextField( value = state.displayName, + modifier = Modifier.contentDescription(R.string.displayNameEnter), onValueChange = { onChange(it) }, placeholder = { Text(stringResource(R.string.displayNameEnter)) }, colors = outlinedTextFieldColors(state.error != null), diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt index 7d9ccedb1f..023353477a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt @@ -71,7 +71,7 @@ fun OutlineButton( onClick: () -> Unit ) { OutlinedButton( - modifier = modifier, + modifier = modifier.contentDescription(GetString(text)), onClick = onClick, border = BorderStroke(1.dp, color), shape = RoundedCornerShape(50), // = 50% percent @@ -262,6 +262,12 @@ fun Modifier.contentDescription(text: GetString?): Modifier { 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 fun OutlineButton(text: GetString, contentDescription: GetString? = text, modifier: Modifier = Modifier, onClick: () -> Unit) { OutlinedButton( diff --git a/gradle.properties b/gradle.properties index 66ea0fcba8..e6dd30852e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ android.enableJetifier=true org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M" org.gradle.unsafe.configuration-cache=true -gradlePluginVersion=7.4.2 +gradlePluginVersion=7.3.1 googleServicesVersion=4.3.12 kotlinVersion=1.8.21 android.useAndroidX=true