Add UI tests

This commit is contained in:
Alfonso Grillo
2022-10-26 18:49:47 +02:00
parent d26c919f80
commit 9336079cf2
6 changed files with 65 additions and 22 deletions
@@ -23,8 +23,8 @@ enum MockUserSessionOverviewScreenState: MockScreenState, CaseIterable {
// A case for each state you want to represent
// with specific, minimal associated data that will allow you
// mock that screen.
case currentSession
case otherSession
case currentSession(sessionState: UserSessionInfo.VerificationState)
case otherSession(sessionState: UserSessionInfo.VerificationState)
case sessionWithPushNotifications(enabled: Bool)
case remotelyTogglingPushersNotAvailable
@@ -35,8 +35,10 @@ enum MockUserSessionOverviewScreenState: MockScreenState, CaseIterable {
/// A list of screen state definitions
static var allCases: [MockUserSessionOverviewScreenState] {
[.currentSession,
.otherSession,
[.currentSession(sessionState: .unverified),
.currentSession(sessionState: .verified),
.otherSession(sessionState: .verified),
.otherSession(sessionState: .unverified),
.sessionWithPushNotifications(enabled: true),
.sessionWithPushNotifications(enabled: false),
.remotelyTogglingPushersNotAvailable]
@@ -47,11 +49,11 @@ enum MockUserSessionOverviewScreenState: MockScreenState, CaseIterable {
let session: UserSessionInfo
let service: UserSessionOverviewServiceProtocol
switch self {
case .currentSession:
case .currentSession(let state):
session = UserSessionInfo(id: "alice",
name: "iOS",
deviceType: .mobile,
verificationState: .unverified,
verificationState: state,
lastSeenIP: "10.0.0.10",
lastSeenTimestamp: nil,
applicationName: "Element iOS",
@@ -65,11 +67,11 @@ enum MockUserSessionOverviewScreenState: MockScreenState, CaseIterable {
isActive: true,
isCurrent: true)
service = MockUserSessionOverviewService()
case .otherSession:
case .otherSession(let state):
session = UserSessionInfo(id: "1",
name: "macOS",
deviceType: .desktop,
verificationState: .verified,
verificationState: state,
lastSeenIP: "1.0.0.1",
lastSeenTimestamp: Date().timeIntervalSince1970 - 130_000,
applicationName: "Element MacOS",
@@ -126,3 +128,18 @@ enum MockUserSessionOverviewScreenState: MockScreenState, CaseIterable {
return ([viewModel], AnyView(UserSessionOverview(viewModel: viewModel.context)))
}
}
extension MockUserSessionOverviewScreenState: CustomStringConvertible {
var description: String {
switch self {
case .currentSession(let sessionState):
return "currentSession\(sessionState)"
case .otherSession(let sessionState):
return "otherSession\(sessionState)"
case .remotelyTogglingPushersNotAvailable:
return "remotelyTogglingPushersNotAvailable"
case .sessionWithPushNotifications(let enabled):
return "sessionWithPushNotifications\(enabled)"
}
}
}
@@ -19,19 +19,19 @@ import XCTest
class UserSessionOverviewUITests: MockScreenTestCase {
func test_whenCurrentSessionSelected_correctNavTittleDisplayed() {
app.goToScreenWithIdentifier(MockUserSessionOverviewScreenState.currentSession.title)
app.goToScreenWithIdentifier(MockUserSessionOverviewScreenState.currentSession(sessionState: .unverified).title)
let navTitle = VectorL10n.userSessionOverviewCurrentSessionTitle
XCTAssertTrue(app.navigationBars[navTitle].staticTexts[navTitle].exists)
}
func test_whenOtherSessionSelected_correctNavTittleDisplayed() {
app.goToScreenWithIdentifier(MockUserSessionOverviewScreenState.otherSession.title)
app.goToScreenWithIdentifier(MockUserSessionOverviewScreenState.otherSession(sessionState: .verified).title)
let navTitle = VectorL10n.userSessionOverviewSessionTitle
XCTAssertTrue(app.navigationBars[navTitle].staticTexts[navTitle].exists)
}
func test_whenSessionOverviewPresented_sessionDetailsButtonExists() {
app.goToScreenWithIdentifier(MockUserSessionOverviewScreenState.currentSession.title)
app.goToScreenWithIdentifier(MockUserSessionOverviewScreenState.currentSession(sessionState: .unverified).title)
XCTAssertTrue(app.buttons[VectorL10n.userSessionOverviewSessionDetailsButtonTitle].exists)
}
@@ -61,4 +61,30 @@ class UserSessionOverviewUITests: MockScreenTestCase {
XCTAssertTrue(app.staticTexts[VectorL10n.userSessionPushNotifications].exists)
XCTAssertTrue(app.staticTexts[VectorL10n.userSessionPushNotificationsMessage].exists)
}
func test_whenOtherSessionSelected_learnMoreButtonDoesnExist() {
let title = MockUserSessionOverviewScreenState.currentSession(sessionState: .verified).title
app.goToScreenWithIdentifier(title)
let buttonId = "\(VectorL10n.userOtherSessionVerifiedAdditionalInfo) \(VectorL10n.userSessionLearnMore)"
let button = app.buttons[buttonId]
XCTAssertFalse(button.exists)
}
func test_whenOtherVerifiedSessionSelected_learnMoreButtonExists() {
app.goToScreenWithIdentifier(MockUserSessionOverviewScreenState.otherSession(sessionState: .verified).title)
let buttonId = "\(VectorL10n.userOtherSessionVerifiedAdditionalInfo) \(VectorL10n.userSessionLearnMore)"
let button = app.buttons[buttonId]
XCTAssertTrue(button.exists)
button.tap()
XCTAssertTrue(app.staticTexts[VectorL10n.userSessionVerifiedSessionTitle].exists)
}
func test_whenOtherUnverifiedSessionSelected_learnMoreButtonExists() {
app.goToScreenWithIdentifier(MockUserSessionOverviewScreenState.otherSession(sessionState: .unverified).title)
let buttonId = "\(VectorL10n.userOtherSessionUnverifiedAdditionalInfo) \(VectorL10n.userSessionLearnMore)"
let button = app.buttons[buttonId]
XCTAssertTrue(button.exists)
button.tap()
XCTAssertTrue(app.staticTexts[VectorL10n.userSessionUnverifiedSessionTitle].exists)
}
}
@@ -83,9 +83,9 @@ struct UserSessionOverview: View {
}
.accentColor(theme.colors.accent)
.bottomSheet(isPresented: $viewModel.showBottomSheet) {
InfoView(title: viewModel.viewState.bottomSheetTitle,
description: viewModel.viewState.bottomSheetDescription,
action: .init(text: VectorL10n.userSessionGotIt, action: { viewModel.showBottomSheet = false }))
InfoSheet(title: viewModel.viewState.bottomSheetTitle,
description: viewModel.viewState.bottomSheetDescription,
action: .init(text: VectorL10n.userSessionGotIt, action: { viewModel.showBottomSheet = false }))
}
}
}