Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added UI tests for new App Layout's screens #7305

Merged
merged 2 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.espresso.tools

import android.view.View
import androidx.test.espresso.PerformException
import androidx.test.espresso.UiController
import androidx.test.espresso.ViewAction
import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import com.google.android.material.tabs.TabLayout
import org.hamcrest.Matchers.allOf

fun selectTabAtPosition(tabIndex: Int): ViewAction {
return object : ViewAction {
override fun getDescription() = "with tab at index $tabIndex"

override fun getConstraints() = allOf(isDisplayed(), isAssignableFrom(TabLayout::class.java))

override fun perform(uiController: UiController, view: View) {
val tabLayout = view as TabLayout
val tabAtIndex: TabLayout.Tab = tabLayout.getTabAt(tabIndex)
?: throw PerformException.Builder()
.withCause(Throwable("No tab at index $tabIndex"))
.build()

tabAtIndex.select()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ class UiAllScreensSanityTest {

elementRobot.space { selectSpace(spaceName) }

elementRobot.layoutPreferences {
crawl()
}

elementRobot.roomList {
crawlTabs()
}

elementRobot.withDeveloperMode {
settings {
advancedSettings { crawlDeveloperOptions() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package im.vector.app.ui.robot

import android.view.View
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.closeSoftKeyboard
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu
import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.click
Expand Down Expand Up @@ -94,6 +96,18 @@ class ElementRobot(
waitUntilViewVisible(withId(R.id.roomListContainer))
}

fun layoutPreferences(block: LayoutPreferencesRobot.() -> Unit) {
openActionBarOverflowOrOptionsMenu(
ApplicationProvider.getApplicationContext()
)
clickOn(R.string.home_layout_preferences)
waitUntilDialogVisible(withId(R.id.home_layout_settings_recents))

block(LayoutPreferencesRobot())

pressBack()
}

fun newDirectMessage(block: NewDirectMessageRobot.() -> Unit) {
if (labsPreferences.isNewAppLayoutEnabled) {
clickOn(R.id.newLayoutCreateChatButton)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn
import im.vector.app.R

class LayoutPreferencesRobot {

fun crawl() {
toggleRecents()
toggleFilters()
useAZOrderd()
useActivityOrder()
}

fun toggleRecents() {
clickOn(R.id.home_layout_settings_recents)
}

fun toggleFilters() {
clickOn(R.id.home_layout_settings_filters)
}

fun useAZOrderd() {
clickOn(R.id.home_layout_settings_sort_name)
}

fun useActivityOrder() {
clickOn(R.id.home_layout_settings_sort_activity)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,43 @@ import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.adevinta.android.barista.assertion.BaristaVisibilityAssertions
import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn
import im.vector.app.R
import im.vector.app.espresso.tools.selectTabAtPosition
import im.vector.app.espresso.tools.waitUntilActivityVisible
import im.vector.app.espresso.tools.waitUntilDialogVisible
import im.vector.app.espresso.tools.waitUntilViewVisible
import im.vector.app.features.home.HomeActivity
import im.vector.app.features.home.room.list.home.header.HomeRoomFilter
import im.vector.app.features.roomdirectory.RoomDirectoryActivity
import im.vector.app.ui.robot.settings.labs.LabFeaturesPreferences
import im.vector.app.waitForView
import kotlinx.coroutines.delay

class RoomListRobot(private val labsPreferences: LabFeaturesPreferences) {

fun openRoom(roomName: String, block: RoomDetailRobot.() -> Unit) {
clickOn(roomName)
onView(withId(R.id.roomListView))
.perform(
RecyclerViewActions.actionOnItem<RecyclerView.ViewHolder>(
hasDescendant(withText(roomName)),
ViewActions.click()
)
)
block(RoomDetailRobot())
pressBack()
}

fun verifyCreatedRoom() {
onView(ViewMatchers.withId(R.id.roomListView))
onView(withId(R.id.roomListView))
.perform(
RecyclerViewActions.actionOnItem<RecyclerView.ViewHolder>(
ViewMatchers.hasDescendant(withText(R.string.room_displayname_empty_room)),
hasDescendant(withText(R.string.room_displayname_empty_room)),
ViewActions.longClick()
)
)
Expand All @@ -53,7 +68,7 @@ class RoomListRobot(private val labsPreferences: LabFeaturesPreferences) {
fun newRoom(block: NewRoomRobot.() -> Unit) {
if (labsPreferences.isNewAppLayoutEnabled) {
clickOn(R.id.newLayoutCreateChatButton)
waitUntilDialogVisible(ViewMatchers.withId(R.id.create_room))
waitUntilDialogVisible(withId(R.id.create_room))
clickOn(R.id.create_room)
} else {
clickOn(R.id.createGroupRoomButton)
Expand All @@ -67,4 +82,21 @@ class RoomListRobot(private val labsPreferences: LabFeaturesPreferences) {
pressBack()
}
}

fun crawlTabs(){
waitUntilActivityVisible<HomeActivity> {
waitUntilViewVisible(withId(R.id.roomListContainer))
}

selectFilterTab(HomeRoomFilter.UNREADS)
waitForView(withId(R.id.emptyTitleView))
selectFilterTab(HomeRoomFilter.ALL)
waitForView(withId(R.id.roomNameView))
}


fun selectFilterTab(filter: HomeRoomFilter) {
onView(withId(R.id.home_filter_tabs_tabs)).perform(selectTabAtPosition(filter.ordinal))
}

}