From 912bf55e093a5c3e50b36a68f842e6440e791e2e Mon Sep 17 00:00:00 2001 From: Aleksandrs Proskurins Date: Fri, 28 Oct 2022 17:25:56 +0300 Subject: [PATCH] UI and unit tests --- .../Test/UI/UserOtherSessionsUITests.swift | 26 ++++++++---- .../UserOtherSessionsViewModelTests.swift | 41 +++++++++++++++++++ 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/RiotSwiftUI/Modules/UserSessions/UserOtherSessions/Test/UI/UserOtherSessionsUITests.swift b/RiotSwiftUI/Modules/UserSessions/UserOtherSessions/Test/UI/UserOtherSessionsUITests.swift index 45d43f3b3..115b54189 100644 --- a/RiotSwiftUI/Modules/UserSessions/UserOtherSessions/Test/UI/UserOtherSessionsUITests.swift +++ b/RiotSwiftUI/Modules/UserSessions/UserOtherSessions/Test/UI/UserOtherSessionsUITests.swift @@ -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) + } } diff --git a/RiotSwiftUI/Modules/UserSessions/UserOtherSessions/Test/Unit/UserOtherSessionsViewModelTests.swift b/RiotSwiftUI/Modules/UserSessions/UserOtherSessions/Test/Unit/UserOtherSessionsViewModelTests.swift index 67376d61c..8fa060fee 100644 --- a/RiotSwiftUI/Modules/UserSessions/UserOtherSessions/Test/Unit/UserOtherSessionsViewModelTests.swift +++ b/RiotSwiftUI/Modules/UserSessions/UserOtherSessions/Test/Unit/UserOtherSessionsViewModelTests.swift @@ -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)