From a37af307f41af399e661b33bec5827e1ae6efbda Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 9 Nov 2020 18:28:23 +0100 Subject: [PATCH] Making progress --- CHANGES.md | 6 ++ .../app/espresso/tools/EspressoPreference.kt | 46 +++++++++ .../vector/app/ui/UiAllScreensSanityTest.kt | 99 +++++++++++++------ .../app/features/popup/PopupAlertManager.kt | 2 +- 4 files changed, 122 insertions(+), 31 deletions(-) create mode 100644 vector/src/androidTest/java/im/vector/app/espresso/tools/EspressoPreference.kt diff --git a/CHANGES.md b/CHANGES.md index fa30acabd5..5a37061259 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,9 @@ SDK API changes ⚠️: Build 🧱: - +Test: + - Add `allScreensTest` to cover all screens of the app + Other changes: - Upgrade Realm dependency to 10.0.0 @@ -1032,5 +1035,8 @@ SDK API changes ⚠️: Build 🧱: - +Test: + - + Other changes: - diff --git a/vector/src/androidTest/java/im/vector/app/espresso/tools/EspressoPreference.kt b/vector/src/androidTest/java/im/vector/app/espresso/tools/EspressoPreference.kt new file mode 100644 index 0000000000..bf60ad681f --- /dev/null +++ b/vector/src/androidTest/java/im/vector/app/espresso/tools/EspressoPreference.kt @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020 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.espresso.tools + +import android.widget.Switch +import androidx.annotation.StringRes +import androidx.preference.Preference +import androidx.recyclerview.widget.RecyclerView +import androidx.test.espresso.Espresso.onData +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItem +import androidx.test.espresso.matcher.PreferenceMatchers.withKey +import androidx.test.espresso.matcher.ViewMatchers.hasDescendant +import androidx.test.espresso.matcher.ViewMatchers.withClassName +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import im.vector.app.R +import org.hamcrest.Matchers.`is` +import org.hamcrest.Matchers.allOf +import org.hamcrest.Matchers.instanceOf + +fun clickOnPreference(@StringRes textResId: Int) { + onView(withId(R.id.recycler_view)) + .perform(actionOnItem( + hasDescendant(withText(textResId)), click())) +} + +fun clickOnSwitchPreference(preferenceKey: String) { + onData(allOf(`is`(instanceOf(Preference::class.java)), withKey(preferenceKey))) + .onChildView(withClassName(`is`(Switch::class.java.name))).perform(click()) +} diff --git a/vector/src/androidTest/java/im/vector/app/ui/UiAllScreensSanityTest.kt b/vector/src/androidTest/java/im/vector/app/ui/UiAllScreensSanityTest.kt index da68bba3f6..1c05a5d529 100644 --- a/vector/src/androidTest/java/im/vector/app/ui/UiAllScreensSanityTest.kt +++ b/vector/src/androidTest/java/im/vector/app/ui/UiAllScreensSanityTest.kt @@ -25,6 +25,7 @@ import androidx.test.espresso.action.ViewActions.longClick import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItem import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers.hasDescendant +import androidx.test.espresso.matcher.ViewMatchers.isRoot import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.rules.ActivityScenarioRule @@ -34,6 +35,7 @@ import com.schibsted.spain.barista.assertion.BaristaListAssertions.assertListIte import com.schibsted.spain.barista.assertion.BaristaVisibilityAssertions.assertDisplayed import com.schibsted.spain.barista.interaction.BaristaClickInteractions.clickBack import com.schibsted.spain.barista.interaction.BaristaClickInteractions.clickOn +import com.schibsted.spain.barista.interaction.BaristaClickInteractions.longClickOn import com.schibsted.spain.barista.interaction.BaristaDialogInteractions.clickDialogNegativeButton import com.schibsted.spain.barista.interaction.BaristaDialogInteractions.clickDialogPositiveButton import com.schibsted.spain.barista.interaction.BaristaEditTextInteractions.writeTo @@ -45,6 +47,7 @@ import im.vector.app.EspressoHelper import im.vector.app.R import im.vector.app.SleepViewAction import im.vector.app.activityIdlingResource +import im.vector.app.espresso.tools.clickOnPreference import im.vector.app.espresso.tools.waitUntilActivityVisible import im.vector.app.features.MainActivity import im.vector.app.features.createdirect.CreateDirectRoomActivity @@ -58,6 +61,7 @@ import im.vector.app.withIdlingResource import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import java.lang.Thread.sleep import java.util.UUID /** @@ -72,6 +76,7 @@ class UiAllScreensSanityTest { private val uiTestBase = UiTestBase() + // Last passing: 2020-11-09 @Test fun allScreensTest() { // Create an account @@ -133,6 +138,8 @@ class UiAllScreensSanityTest { uiTestBase.signout() clickDialogPositiveButton() + + // TODO Deactivate account instead of logout? } private fun ignoreVerification() { @@ -178,14 +185,7 @@ class UiAllScreensSanityTest { navigateToRoomSettings() // Long click on the message - onView(withId(R.id.timelineRecyclerView)) - .perform( - actionOnItem( - hasDescendant(withText("Hello world!")), - longClick() - ) - ) - pressBack() + longClickOnMessageTest() // Menu openMenu() @@ -198,6 +198,47 @@ class UiAllScreensSanityTest { pressBack() } + private fun longClickOnMessageTest() { + // Test quick reaction + longClickOnMessage() + // Add quick reaction + clickOn("👍") + + sleep(1000) + + // Open reactions + longClickOn("👍") + pressBack() + + // Test add reaction + longClickOnMessage() + clickOn(R.string.message_add_reaction) + // Filter + // TODO clickMenu(R.id.search) + clickListItem(R.id.emojiRecyclerView, 4) + + // Test Edit mode + longClickOnMessage() + clickOn(R.string.edit) + // TODO Cancel action + writeTo(R.id.composerEditText, "Hello universe!") + clickOn(R.id.sendButton) + // Open edit history + longClickOnMessage("Hello universe! (edited)") + clickOn(R.string.message_view_edit_history) + pressBack() + } + + private fun longClickOnMessage(text: String = "Hello world!") { + onView(withId(R.id.timelineRecyclerView)) + .perform( + actionOnItem( + hasDescendant(withText(text)), + longClick() + ) + ) + } + private fun navigateToRoomSettings() { clickOn(R.id.roomToolbarTitleView) assertDisplayed(R.id.roomProfileAvatarView) @@ -327,51 +368,51 @@ class UiAllScreensSanityTest { clickOn(R.string.settings_app_term_conditions) pressBack() clickOn(R.string.settings_privacy_policy) - pressBack() - clickOn(R.string.settings_third_party_notices) pressBack() */ + clickOn(R.string.settings_third_party_notices) + clickDialogPositiveButton() } private fun navigateToSettingsAdvanced() { - /* - TODO Find a way to scroll - clickOn(R.string.settings_notifications_targets) - pressBack() - clickOn(R.string.settings_push_rules) + clickOnPreference(R.string.settings_notifications_targets) pressBack() + clickOnPreference(R.string.settings_push_rules) + pressBack() + + /* TODO P2 test developer screens // Enable developer mode - clickOn(R.string.settings_developer_mode) + clickOnSwitchPreference("SETTINGS_DEVELOPER_MODE_PREFERENCE_KEY") - clickOn(R.string.settings_account_data) + clickOnPreference(R.string.settings_account_data) clickOn("m.push_rules") pressBack() pressBack() - clickOn(R.string.settings_key_requests) + clickOnPreference(R.string.settings_key_requests) pressBack() // Disable developer mode - clickOn(R.string.settings_developer_mode) + clickOnSwitchPreference("SETTINGS_DEVELOPER_MODE_PREFERENCE_KEY") */ } private fun navigateToSettingsSecurity() { - clickOn(R.string.settings_active_sessions_show_all) + clickOnPreference(R.string.settings_active_sessions_show_all) pressBack() - /* - TODO Find a way to scroll - clickOn(R.string.encryption_message_recovery) + + clickOnPreference(R.string.encryption_message_recovery) // TODO go deeper here pressBack() - clickOn(R.string.encryption_export_e2e_room_keys) + /* Cannot exit + clickOnPreference(R.string.encryption_export_e2e_room_keys) pressBack() */ } private fun navigateToSettingsPreferences() { clickOn(R.string.settings_interface_language) - onView(ViewMatchers.isRoot()) + onView(isRoot()) .perform(waitForView(withText("Dansk (Danmark)"))) pressBack() clickOn(R.string.settings_theme) @@ -392,7 +433,7 @@ class UiAllScreensSanityTest { clickOn(R.string.settings_call_notifications_preferences) pressBack() */ - clickOn(R.string.settings_notification_troubleshoot) + clickOnPreference(R.string.settings_notification_troubleshoot) pressBack() } @@ -409,13 +450,11 @@ class UiAllScreensSanityTest { clickOn(R.string.add_identity_server) pressBack() pressBack() - /* TODO Find a way to scroll // Identity server - clickListItem(android.preference.R.id.recycler_view, 30) + clickOnPreference(R.string.settings_identity_server) pressBack() // Deactivate account - clickListItem(R.id.recycler_view, 32) + clickOnPreference(R.string.settings_deactivate_my_account) pressBack() - */ } } diff --git a/vector/src/main/java/im/vector/app/features/popup/PopupAlertManager.kt b/vector/src/main/java/im/vector/app/features/popup/PopupAlertManager.kt index 665eb93428..b2257b250a 100644 --- a/vector/src/main/java/im/vector/app/features/popup/PopupAlertManager.kt +++ b/vector/src/main/java/im/vector/app/features/popup/PopupAlertManager.kt @@ -46,7 +46,7 @@ class PopupAlertManager @Inject constructor(private val avatarRenderer: Lazy? = null private var currentAlerter: VectorAlert? = null - private val alertFiFo = ArrayList() + private val alertFiFo = mutableListOf() fun postVectorAlert(alert: VectorAlert) { synchronized(alertFiFo) {