added UI tests for new App Layout's screens (#7305)
This commit is contained in:
		
							parent
							
								
									31811bb7e0
								
							
						
					
					
						commit
						59cf20be35
					
				| @ -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() | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -135,6 +135,14 @@ class UiAllScreensSanityTest { | ||||
| 
 | ||||
|         elementRobot.space { selectSpace(spaceName) } | ||||
| 
 | ||||
|         elementRobot.layoutPreferences { | ||||
|             crawl() | ||||
|         } | ||||
| 
 | ||||
|         elementRobot.roomList { | ||||
|             crawlTabs() | ||||
|         } | ||||
| 
 | ||||
|         elementRobot.withDeveloperMode { | ||||
|             settings { | ||||
|                 advancedSettings { crawlDeveloperOptions() } | ||||
|  | ||||
| @ -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 | ||||
| @ -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) | ||||
|  | ||||
| @ -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) | ||||
|     } | ||||
| } | ||||
| @ -21,29 +21,41 @@ import androidx.test.espresso.Espresso.onView | ||||
| 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.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 | ||||
| 
 | ||||
| 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() | ||||
|                         ) | ||||
|                 ) | ||||
| @ -53,7 +65,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) | ||||
| @ -67,4 +79,19 @@ 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)) | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user