Go through more screens in the integration tests

This commit is contained in:
Stefan Ceriu 2023-08-24 18:20:23 +03:00 committed by Stefan Ceriu
parent 6171d878b0
commit 7712bb0082
4 changed files with 78 additions and 25 deletions

View File

@ -29,6 +29,7 @@ struct A11yIdentifiers {
static let roomNotificationSettingsScreen = RoomNotificationSettingsScreen() static let roomNotificationSettingsScreen = RoomNotificationSettingsScreen()
static let serverConfirmationScreen = ServerConfirmationScreen() static let serverConfirmationScreen = ServerConfirmationScreen()
static let sessionVerificationScreen = SessionVerificationScreen() static let sessionVerificationScreen = SessionVerificationScreen()
static let settingsScreen = SettingsScreen()
static let softLogoutScreen = SoftLogoutScreen() static let softLogoutScreen = SoftLogoutScreen()
static let startChatScreen = StartChatScreen() static let startChatScreen = StartChatScreen()
static let roomMemberDetailsScreen = RoomMemberDetailsScreen() static let roomMemberDetailsScreen = RoomMemberDetailsScreen()
@ -98,6 +99,7 @@ struct A11yIdentifiers {
let name = "room-name" let name = "room-name"
let avatar = "room-avatar" let avatar = "room-avatar"
let attachmentPicker = "room-attachment_picker" let attachmentPicker = "room-attachment_picker"
let timelineItemActionMenu = "room-timeline_item_action_menu"
} }
struct RoomDetailsScreen { struct RoomDetailsScreen {
@ -133,6 +135,10 @@ struct A11yIdentifiers {
let close = "session_verification-close" let close = "session_verification-close"
} }
struct SettingsScreen {
let logout = "settings-logout"
}
struct SoftLogoutScreen { struct SoftLogoutScreen {
let title = "soft_logout-title" let title = "soft_logout-title"
let message = "soft_logout-message" let message = "soft_logout-message"

View File

@ -157,6 +157,8 @@ public struct TimelineItemMenu: View {
} }
} }
} }
.accessibilityElement(children: .combine)
.accessibilityIdentifier(A11yIdentifiers.roomScreen.timelineItemActionMenu)
.presentationDetents([.medium, .large]) .presentationDetents([.medium, .large])
.presentationBackground(Color.compound.bgCanvasDefault) .presentationBackground(Color.compound.bgCanvasDefault)
.presentationDragIndicator(.visible) .presentationDragIndicator(.visible)

View File

@ -166,7 +166,7 @@ struct SettingsScreen: View {
kind: .button { kind: .button {
showingLogoutConfirmation = true showingLogoutConfirmation = true
}) })
.accessibilityIdentifier("logoutButton") .accessibilityIdentifier(A11yIdentifiers.settingsScreen.logout)
.alert(L10n.screenSignoutConfirmationDialogTitle, isPresented: $showingLogoutConfirmation) { .alert(L10n.screenSignoutConfirmationDialogTitle, isPresented: $showingLogoutConfirmation) {
Button(L10n.screenSignoutConfirmationDialogSubmit, Button(L10n.screenSignoutConfirmationDialogSubmit,
role: .destructive, role: .destructive,

View File

@ -32,16 +32,11 @@ class LoginTests: XCTestCase {
self.runLoginLogoutFlow() self.runLoginLogoutFlow()
} }
} }
guard let actualDuration = parser.valueForMetric(.clockMonotonicTime) else {
XCTFail("Couldn't retrieve duration")
return
}
} }
private func runLoginLogoutFlow() { private func runLoginLogoutFlow() {
let app = Application.launch() let app = Application.launch()
let getStartedButton = app.buttons[A11yIdentifiers.onboardingScreen.signIn] let getStartedButton = app.buttons[A11yIdentifiers.onboardingScreen.signIn]
XCTAssertTrue(getStartedButton.waitForExistence(timeout: 10.0)) XCTAssertTrue(getStartedButton.waitForExistence(timeout: 10.0))
@ -79,9 +74,9 @@ class LoginTests: XCTestCase {
XCTAssertTrue(nextButton.isEnabled) XCTAssertTrue(nextButton.isEnabled)
nextButton.tap() nextButton.tap()
sleep(10) sleep(10)
// Handle analytics prompt screen // Handle analytics prompt screen
if app.staticTexts[A11yIdentifiers.analyticsPromptScreen.title].waitForExistence(timeout: 1.0) { if app.staticTexts[A11yIdentifiers.analyticsPromptScreen.title].waitForExistence(timeout: 1.0) {
// Wait for login and then handle save password sheet // Wait for login and then handle save password sheet
@ -89,12 +84,12 @@ class LoginTests: XCTestCase {
if savePasswordButton.waitForExistence(timeout: 10.0) { if savePasswordButton.waitForExistence(timeout: 10.0) {
savePasswordButton.tap() savePasswordButton.tap()
} }
let enableButton = app.buttons[A11yIdentifiers.analyticsPromptScreen.enable] let enableButton = app.buttons[A11yIdentifiers.analyticsPromptScreen.enable]
XCTAssertTrue(enableButton.waitForExistence(timeout: 10.0)) XCTAssertTrue(enableButton.waitForExistence(timeout: 10.0))
enableButton.tap() enableButton.tap()
} }
// This might come in a different order, wait for both. // This might come in a different order, wait for both.
let savePasswordButton = app.buttons["Save Password"] let savePasswordButton = app.buttons["Save Password"]
if savePasswordButton.waitForExistence(timeout: 10.0) { if savePasswordButton.waitForExistence(timeout: 10.0) {
@ -111,44 +106,94 @@ class LoginTests: XCTestCase {
// Migration screen may be shown as an overlay. // Migration screen may be shown as an overlay.
// if that pops up soon enough, we just let that happen and wait // if that pops up soon enough, we just let that happen and wait
let message = app.staticTexts[A11yIdentifiers.migrationScreen.message] let message = app.staticTexts[A11yIdentifiers.migrationScreen.message]
if message.waitForExistence(timeout: 10.0) { if message.waitForExistence(timeout: 10.0) {
let doesNotExistPredicate = NSPredicate(format: "exists == 0") let doesNotExistPredicate = NSPredicate(format: "exists == 0")
expectation(for: doesNotExistPredicate, evaluatedWith: message) expectation(for: doesNotExistPredicate, evaluatedWith: message)
waitForExpectations(timeout: 300.0) waitForExpectations(timeout: 300.0)
} }
// Welcome screen may be shown as an overlay. // Welcome screen may be shown as an overlay.
if app.buttons[A11yIdentifiers.welcomeScreen.letsGo].waitForExistence(timeout: 1.0) { if app.buttons[A11yIdentifiers.welcomeScreen.letsGo].waitForExistence(timeout: 1.0) {
let goButton = app.buttons[A11yIdentifiers.welcomeScreen.letsGo] let goButton = app.buttons[A11yIdentifiers.welcomeScreen.letsGo]
XCTAssertTrue(goButton.waitForExistence(timeout: 1.0)) XCTAssertTrue(goButton.waitForExistence(timeout: 1.0))
goButton.tap() goButton.tap()
} }
// Wait for the home screen to become visible. // Wait for the home screen to become visible.
let profileButton = app.buttons[A11yIdentifiers.homeScreen.userAvatar] let profileButton = app.buttons[A11yIdentifiers.homeScreen.userAvatar]
// Timeouts are huge because we're waiting for the server. // Timeouts are huge because we're waiting for the server.
XCTAssertTrue(profileButton.waitForExistence(timeout: 300.0)) XCTAssertTrue(profileButton.waitForExistence(timeout: 300.0))
// Open the first room in the list. // Open the first room in the list.
let rooms = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH %@", A11yIdentifiers.homeScreen.roomNamePrefix)) let firstRoom = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH %@", A11yIdentifiers.homeScreen.roomNamePrefix)).firstMatch
rooms.firstMatch.tap() XCTAssertTrue(firstRoom.waitForExistence(timeout: 10.0))
// Temporary sleep to get it working. firstRoom.tap()
sleep(20)
// Go back to the home screen. // Long press on the last message
app.navigationBars.firstMatch.buttons["All Chats"].tap() let lastMessage = app.cells.firstMatch
XCTAssertTrue(lastMessage.waitForExistence(timeout: 10.0))
lastMessage.press(forDuration: 2.0)
// Hide the bottom sheet
let timelineItemActionMenu = app.otherElements[A11yIdentifiers.roomScreen.timelineItemActionMenu].firstMatch
XCTAssertTrue(timelineItemActionMenu.waitForExistence(timeout: 10.0))
timelineItemActionMenu.swipeDown(velocity: .fast)
// Open the room details
let roomHeader = app.staticTexts["room-name"]
XCTAssertTrue(roomHeader.waitForExistence(timeout: 10.0))
roomHeader.tap()
// Open the room member details
let roomMembers = app.buttons["room_details-people"]
XCTAssertTrue(roomMembers.waitForExistence(timeout: 10.0))
roomMembers.tap()
// Open the first member's details
let firstRoomMember = app.scrollViews.buttons.firstMatch
XCTAssertTrue(firstRoomMember.waitForExistence(timeout: 10.0))
firstRoomMember.tap()
// Go back to the room member details
var backButton = app.buttons["People"]
XCTAssertTrue(backButton.waitForExistence(timeout: 10.0))
backButton.tap()
// Go back to the room details
backButton = app.buttons["Back"]
XCTAssertTrue(backButton.waitForExistence(timeout: 10.0))
backButton.tap()
// Go back to the room
backButton = app.buttons["Back"]
XCTAssertTrue(backButton.waitForExistence(timeout: 10.0))
backButton.tap()
// Go back to the room list
backButton = app.navigationBars.firstMatch.buttons["All Chats"]
XCTAssertTrue(backButton.waitForExistence(timeout: 10.0))
backButton.tap()
// `Failed to scroll to visible (by AX action) Button` https://stackoverflow.com/a/33534187/730924 // `Failed to scroll to visible (by AX action) Button` https://stackoverflow.com/a/33534187/730924
profileButton.forceTap() profileButton.forceTap()
let menuLogoutButton = app.buttons["Sign out"] // Open the settings
XCTAssertTrue(menuLogoutButton.waitForExistence(timeout: 10.0)) let settingsButton = app.buttons["Settings"]
menuLogoutButton.tap() XCTAssertTrue(settingsButton.waitForExistence(timeout: 10.0))
settingsButton.tap()
let alertLogoutButton = app.buttons["Sign out"] // Logout
let logoutButton = app.buttons[A11yIdentifiers.settingsScreen.logout]
XCTAssertTrue(logoutButton.waitForExistence(timeout: 10.0))
logoutButton.tap()
// Confirm logout
let alertLogoutButton = app.alerts.firstMatch.buttons["Sign out"]
XCTAssertTrue(alertLogoutButton.waitForExistence(timeout: 10.0)) XCTAssertTrue(alertLogoutButton.waitForExistence(timeout: 10.0))
alertLogoutButton.tap() alertLogoutButton.tap()
// Check that we're back on the login screen
XCTAssertTrue(getStartedButton.waitForExistence(timeout: 10.0)) XCTAssertTrue(getStartedButton.waitForExistence(timeout: 10.0))
} }
} }