UI and unit tests

This commit is contained in:
Aleksandrs Proskurins
2022-10-28 17:25:56 +03:00
parent 4bd8e2a02f
commit 912bf55e09
2 changed files with 60 additions and 7 deletions
@@ -38,12 +38,6 @@ class UserOtherSessionsUITests: MockScreenTestCase {
XCTAssertTrue(app.staticTexts[VectorL10n.userOtherSessionUnverifiedSessionsHeaderSubtitle].exists)
}
func test_whenOtherSessionsWithUnverifiedSessionFilterPresented_correctItemsDisplayed() {
app.goToScreenWithIdentifier(MockUserOtherSessionsScreenState.unverifiedSessions.title)
XCTAssertTrue(app.buttons["iOS, Unverified · Your current session"].exists)
}
func test_whenOtherSessionsWithAllSessionFilterPresented_correctHeaderDisplayed() {
app.goToScreenWithIdentifier(MockUserOtherSessionsScreenState.all.title)
@@ -57,11 +51,12 @@ class UserOtherSessionsUITests: MockScreenTestCase {
XCTAssertTrue(app.staticTexts[VectorL10n.userOtherSessionVerifiedSessionsHeaderSubtitle].exists)
}
func test_whenOtherSessionsMoreMenuButtonSelected_selectSessionsButtonExists() {
func test_whenOtherSessionsMoreMenuButtonSelected_moreMenuIsCorrect() {
app.goToScreenWithIdentifier(MockUserOtherSessionsScreenState.all.title)
app.buttons["More"].tap()
XCTAssertTrue(app.buttons["Select sessions"].exists)
XCTAssertTrue(app.buttons["Sign out of 6 sessions"].exists)
}
func test_whenOtherSessionsSelectSessionsSelected_navBarContainsCorrectButtons() {
@@ -69,6 +64,9 @@ class UserOtherSessionsUITests: MockScreenTestCase {
app.buttons["More"].tap()
app.buttons["Select sessions"].tap()
let singOutButton = app.buttons["Sign out"]
XCTAssertTrue(singOutButton.exists)
XCTAssertFalse(singOutButton.isEnabled)
XCTAssertTrue(app.buttons["Select All"].exists)
XCTAssertTrue(app.buttons["Cancel"].exists)
}
@@ -92,4 +90,18 @@ class UserOtherSessionsUITests: MockScreenTestCase {
}
XCTAssertTrue(app.buttons["Deselect All"].exists)
}
func test_whenChangingSessionSelection_signOutButtonChangesItState() {
app.goToScreenWithIdentifier(MockUserOtherSessionsScreenState.all.title)
app.buttons["More"].tap()
app.buttons["Select sessions"].tap()
let singOutButton = app.buttons["Sign out"]
XCTAssertTrue(singOutButton.exists)
XCTAssertFalse(singOutButton.isEnabled)
let sessionListItem = app.buttons["UserSessionListItem_0"]
sessionListItem.tap()
XCTAssertTrue(singOutButton.isEnabled)
sessionListItem.tap()
XCTAssertFalse(singOutButton.isEnabled)
}
}
@@ -281,6 +281,47 @@ class UserOtherSessionsViewModelTests: XCTestCase {
XCTAssertEqual(sut.state, expectedState)
}
func test_whenSignOutAllUserSessions_correctCompletionResultReceived() {
let sessionInfoWithSessionId1 = createUserSessionInfo(sessionId: "session 1")
let sessionInfoWithSessionId3 = createUserSessionInfo(sessionId: "session 3")
let sessionInfos = [sessionInfoWithSessionId1,
createUserSessionInfo(sessionId: "session 2"),
sessionInfoWithSessionId3]
let sut = createSUT(sessionInfos: sessionInfos, filter: .all)
var receivedUserSessions = [UserSessionInfo]()
sut.completion = { result in
switch result {
case let .singOutFromUserSessions(sessionInfos: sessionInfos):
receivedUserSessions = sessionInfos
default:
break
}
}
toggleEditMode(for: sut, value: true)
sut.process(viewAction: .userOtherSessionSelected(sessionId: sessionInfoWithSessionId1.id))
sut.process(viewAction: .userOtherSessionSelected(sessionId: sessionInfoWithSessionId3.id))
sut.process(viewAction: .signOutSelectedUserSessions)
XCTAssertEqual(receivedUserSessions, [sessionInfoWithSessionId1, sessionInfoWithSessionId3])
}
func test_whenSignOutSelectedUserSessions_correctCompletionResultReceived() {
let sessionInfos = [createUserSessionInfo(sessionId: "session 1"),
createUserSessionInfo(sessionId: "session 2"),
createUserSessionInfo(sessionId: "session 3")]
let sut = createSUT(sessionInfos: sessionInfos, filter: .all)
var receivedUserSessions = [UserSessionInfo]()
sut.completion = { result in
switch result {
case let .singOutFromUserSessions(sessionInfos: sessionInfos):
receivedUserSessions = sessionInfos
default:
break
}
}
sut.process(viewAction: .signOutAllUserSessions)
XCTAssertEqual(receivedUserSessions, sessionInfos)
}
private func toggleEditMode(for model: UserOtherSessionsViewModel, value: Bool) {
model.context.isEditModeEnabled = value
model.process(viewAction: .editModeWasToggled)