diff --git a/changelog.d/4892.feature b/changelog.d/4892.feature new file mode 100644 index 00000000000..1d66367999a --- /dev/null +++ b/changelog.d/4892.feature @@ -0,0 +1 @@ +Display Analytics opt-in screen at first start-up of the app \ No newline at end of file diff --git a/vector/src/androidTest/java/im/vector/app/espresso/tools/WaitActivity.kt b/vector/src/androidTest/java/im/vector/app/espresso/tools/WaitActivity.kt index 05f1ca2815f..0c03f78bb45 100644 --- a/vector/src/androidTest/java/im/vector/app/espresso/tools/WaitActivity.kt +++ b/vector/src/androidTest/java/im/vector/app/espresso/tools/WaitActivity.kt @@ -26,7 +26,6 @@ import im.vector.app.activityIdlingResource import im.vector.app.waitForView import im.vector.app.withIdlingResource import org.hamcrest.Matcher -import org.hamcrest.Matchers.not inline fun waitUntilActivityVisible(noinline block: (() -> Unit) = {}) { withIdlingResource(activityIdlingResource(T::class.java), block) diff --git a/vector/src/androidTest/java/im/vector/app/ui/robot/AnalyticsRobot.kt b/vector/src/androidTest/java/im/vector/app/ui/robot/AnalyticsRobot.kt new file mode 100644 index 00000000000..86b110ce879 --- /dev/null +++ b/vector/src/androidTest/java/im/vector/app/ui/robot/AnalyticsRobot.kt @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.ui.robot + +import androidx.test.espresso.matcher.ViewMatchers.withId +import com.adevinta.android.barista.assertion.BaristaVisibilityAssertions.assertDisplayed +import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn +import im.vector.app.R +import im.vector.app.espresso.tools.waitUntilActivityVisible +import im.vector.app.espresso.tools.waitUntilViewVisible +import im.vector.app.features.analytics.ui.consent.AnalyticsOptInActivity + +class AnalyticsRobot { + + fun optIn() { + answerOptIn(true) + } + + fun optOut() { + answerOptIn(false) + } + + private fun answerOptIn(optIn: Boolean) { + waitUntilActivityVisible { + waitUntilViewVisible(withId(R.id.title)) + } + assertDisplayed(R.id.title, R.string.analytics_opt_in_title) + if (optIn) { + clickOn(R.id.submit) + } else { + clickOn(R.id.later) + } + } +} diff --git a/vector/src/androidTest/java/im/vector/app/ui/robot/ElementRobot.kt b/vector/src/androidTest/java/im/vector/app/ui/robot/ElementRobot.kt index 74e44786351..22a5a0790b9 100644 --- a/vector/src/androidTest/java/im/vector/app/ui/robot/ElementRobot.kt +++ b/vector/src/androidTest/java/im/vector/app/ui/robot/ElementRobot.kt @@ -32,7 +32,7 @@ import im.vector.app.espresso.tools.waitUntilDialogVisible import im.vector.app.espresso.tools.waitUntilViewVisible import im.vector.app.features.createdirect.CreateDirectRoomActivity import im.vector.app.features.home.HomeActivity -import im.vector.app.features.login.LoginActivity +import im.vector.app.features.onboarding.OnboardingActivity import im.vector.app.initialSyncIdlingResource import im.vector.app.ui.robot.settings.SettingsRobot import im.vector.app.withIdlingResource @@ -43,6 +43,8 @@ class ElementRobot { fun signUp(userId: String) { val onboardingRobot = OnboardingRobot() onboardingRobot.createAccount(userId = userId) + val analyticsRobot = AnalyticsRobot() + analyticsRobot.optOut() waitForHome() } @@ -121,7 +123,7 @@ class ElementRobot { clickDialogPositiveButton() } - waitUntilActivityVisible { + waitUntilActivityVisible { assertDisplayed(R.id.loginSplashLogo) } } diff --git a/vector/src/androidTest/java/im/vector/app/ui/robot/OnboardingRobot.kt b/vector/src/androidTest/java/im/vector/app/ui/robot/OnboardingRobot.kt index 8b87abadab9..633d3cceab4 100644 --- a/vector/src/androidTest/java/im/vector/app/ui/robot/OnboardingRobot.kt +++ b/vector/src/androidTest/java/im/vector/app/ui/robot/OnboardingRobot.kt @@ -45,7 +45,11 @@ class OnboardingRobot { homeServerUrl: String) { waitUntilViewVisible(withId(R.id.loginSplashSubmit)) assertDisplayed(R.id.loginSplashSubmit, R.string.login_splash_submit) - clickOn(R.id.loginSplashSubmit) + if (createAccount) { + clickOn(R.id.loginSplashSubmit) + } else { + clickOn(R.id.loginSplashAlreadyHaveAccount) + } assertDisplayed(R.id.loginServerTitle, R.string.login_server_title) // Chose custom server clickOn(R.id.loginServerChoiceOther) @@ -54,17 +58,7 @@ class OnboardingRobot { assertEnabled(R.id.loginServerUrlFormSubmit) closeSoftKeyboard() clickOn(R.id.loginServerUrlFormSubmit) - onView(isRoot()).perform(waitForView(withId(R.id.loginSignupSigninSubmit))) - - if (createAccount) { - // Click on the signup button - assertDisplayed(R.id.loginSignupSigninSubmit) - clickOn(R.id.loginSignupSigninSubmit) - } else { - // Click on the signin button - assertDisplayed(R.id.loginSignupSigninSignIn) - clickOn(R.id.loginSignupSigninSignIn) - } + onView(isRoot()).perform(waitForView(withId(R.id.loginField))) // Ensure password flow supported assertDisplayed(R.id.loginField) diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt index 4bc2b418459..35c112b63ad 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt @@ -83,12 +83,9 @@ class HomeActivityViewModel @AssistedInject constructor( observeInitialSync() checkSessionPushIsOn() observeCrossSigningReset() - // Disable Analytics opt-in automatic display - // Waiting for translation and for analytic events to be actually sent - // observeAnalytics() + observeAnalytics() } - @Suppress("unused") private fun observeAnalytics() { if (analyticsConfig.isEnabled) { analyticsStore.didAskUserConsentFlow