Skip to content

Commit

Permalink
Go through more screens in the integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanceriu committed Aug 24, 2023
1 parent 6171d87 commit 7712bb0
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 25 deletions.
6 changes: 6 additions & 0 deletions ElementX/Sources/Other/AccessibilityIdentifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct A11yIdentifiers {
static let roomNotificationSettingsScreen = RoomNotificationSettingsScreen()
static let serverConfirmationScreen = ServerConfirmationScreen()
static let sessionVerificationScreen = SessionVerificationScreen()
static let settingsScreen = SettingsScreen()
static let softLogoutScreen = SoftLogoutScreen()
static let startChatScreen = StartChatScreen()
static let roomMemberDetailsScreen = RoomMemberDetailsScreen()
Expand Down Expand Up @@ -98,6 +99,7 @@ struct A11yIdentifiers {
let name = "room-name"
let avatar = "room-avatar"
let attachmentPicker = "room-attachment_picker"
let timelineItemActionMenu = "room-timeline_item_action_menu"
}

struct RoomDetailsScreen {
Expand Down Expand Up @@ -133,6 +135,10 @@ struct A11yIdentifiers {
let close = "session_verification-close"
}

struct SettingsScreen {
let logout = "settings-logout"
}

struct SoftLogoutScreen {
let title = "soft_logout-title"
let message = "soft_logout-message"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ public struct TimelineItemMenu: View {
}
}
}
.accessibilityElement(children: .combine)
.accessibilityIdentifier(A11yIdentifiers.roomScreen.timelineItemActionMenu)
.presentationDetents([.medium, .large])
.presentationBackground(Color.compound.bgCanvasDefault)
.presentationDragIndicator(.visible)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ struct SettingsScreen: View {
kind: .button {
showingLogoutConfirmation = true
})
.accessibilityIdentifier("logoutButton")
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.logout)
.alert(L10n.screenSignoutConfirmationDialogTitle, isPresented: $showingLogoutConfirmation) {
Button(L10n.screenSignoutConfirmationDialogSubmit,
role: .destructive,
Expand Down
93 changes: 69 additions & 24 deletions IntegrationTests/Sources/LoginTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,11 @@ class LoginTests: XCTestCase {
self.runLoginLogoutFlow()
}
}

guard let actualDuration = parser.valueForMetric(.clockMonotonicTime) else {
XCTFail("Couldn't retrieve duration")
return
}
}

private func runLoginLogoutFlow() {
let app = Application.launch()

let getStartedButton = app.buttons[A11yIdentifiers.onboardingScreen.signIn]

XCTAssertTrue(getStartedButton.waitForExistence(timeout: 10.0))
Expand Down Expand Up @@ -79,22 +74,22 @@ class LoginTests: XCTestCase {
XCTAssertTrue(nextButton.isEnabled)

nextButton.tap()

sleep(10)

// Handle analytics prompt screen
if app.staticTexts[A11yIdentifiers.analyticsPromptScreen.title].waitForExistence(timeout: 1.0) {
// Wait for login and then handle save password sheet
let savePasswordButton = app.buttons["Save Password"]
if savePasswordButton.waitForExistence(timeout: 10.0) {
savePasswordButton.tap()
}

let enableButton = app.buttons[A11yIdentifiers.analyticsPromptScreen.enable]
XCTAssertTrue(enableButton.waitForExistence(timeout: 10.0))
enableButton.tap()
}

// This might come in a different order, wait for both.
let savePasswordButton = app.buttons["Save Password"]
if savePasswordButton.waitForExistence(timeout: 10.0) {
Expand All @@ -111,44 +106,94 @@ class LoginTests: XCTestCase {
// Migration screen may be shown as an overlay.
// if that pops up soon enough, we just let that happen and wait
let message = app.staticTexts[A11yIdentifiers.migrationScreen.message]

if message.waitForExistence(timeout: 10.0) {
let doesNotExistPredicate = NSPredicate(format: "exists == 0")
expectation(for: doesNotExistPredicate, evaluatedWith: message)
waitForExpectations(timeout: 300.0)
}

// Welcome screen may be shown as an overlay.
if app.buttons[A11yIdentifiers.welcomeScreen.letsGo].waitForExistence(timeout: 1.0) {
let goButton = app.buttons[A11yIdentifiers.welcomeScreen.letsGo]
XCTAssertTrue(goButton.waitForExistence(timeout: 1.0))
goButton.tap()
}

// Wait for the home screen to become visible.
let profileButton = app.buttons[A11yIdentifiers.homeScreen.userAvatar]
// Timeouts are huge because we're waiting for the server.
XCTAssertTrue(profileButton.waitForExistence(timeout: 300.0))

// Open the first room in the list.
let rooms = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH %@", A11yIdentifiers.homeScreen.roomNamePrefix))
rooms.firstMatch.tap()
// Temporary sleep to get it working.
sleep(20)
// Go back to the home screen.
app.navigationBars.firstMatch.buttons["All Chats"].tap()
let firstRoom = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH %@", A11yIdentifiers.homeScreen.roomNamePrefix)).firstMatch
XCTAssertTrue(firstRoom.waitForExistence(timeout: 10.0))
firstRoom.tap()

// Long press on the last message
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
profileButton.forceTap()

let menuLogoutButton = app.buttons["Sign out"]
XCTAssertTrue(menuLogoutButton.waitForExistence(timeout: 10.0))
menuLogoutButton.tap()
// Open the settings
let settingsButton = app.buttons["Settings"]
XCTAssertTrue(settingsButton.waitForExistence(timeout: 10.0))
settingsButton.tap()

// Logout
let logoutButton = app.buttons[A11yIdentifiers.settingsScreen.logout]
XCTAssertTrue(logoutButton.waitForExistence(timeout: 10.0))
logoutButton.tap()

let alertLogoutButton = app.buttons["Sign out"]
// Confirm logout
let alertLogoutButton = app.alerts.firstMatch.buttons["Sign out"]
XCTAssertTrue(alertLogoutButton.waitForExistence(timeout: 10.0))
alertLogoutButton.tap()

// Check that we're back on the login screen
XCTAssertTrue(getStartedButton.waitForExistence(timeout: 10.0))
}
}

0 comments on commit 7712bb0

Please sign in to comment.