-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6750 from vector-im/alex/6693_dm_session_details
Device manager: User session details screen (PSG-685) #6693
- Loading branch information
Showing
18 changed files
with
725 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...I/Modules/UserSessions/UserSessionDetails/Coordinator/UserSessionDetailsCoordinator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// Copyright 2021 New Vector Ltd | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import SwiftUI | ||
import CommonKit | ||
|
||
struct UserSessionDetailsCoordinatorParameters { | ||
let session: MXSession | ||
let userSessionInfo: UserSessionInfo | ||
} | ||
|
||
final class UserSessionDetailsCoordinator: Coordinator, Presentable { | ||
|
||
// MARK: - Properties | ||
|
||
// MARK: Private | ||
|
||
private let parameters: UserSessionDetailsCoordinatorParameters | ||
private let userSessionDetailsHostingController: UIViewController | ||
private var userSessionDetailsViewModel: UserSessionDetailsViewModelProtocol | ||
|
||
private var indicatorPresenter: UserIndicatorTypePresenterProtocol | ||
private var loadingIndicator: UserIndicator? | ||
|
||
// MARK: Public | ||
|
||
// Must be used only internally | ||
var childCoordinators: [Coordinator] = [] | ||
var completion: ((UserSessionDetailsViewModelResult) -> Void)? | ||
|
||
// MARK: - Setup | ||
|
||
init(parameters: UserSessionDetailsCoordinatorParameters) { | ||
self.parameters = parameters | ||
|
||
let viewModel = UserSessionDetailsViewModel(userSessionInfo: parameters.userSessionInfo) | ||
let view = UserSessionDetails(viewModel: viewModel.context) | ||
userSessionDetailsViewModel = viewModel | ||
userSessionDetailsHostingController = VectorHostingController(rootView: view) | ||
|
||
indicatorPresenter = UserIndicatorTypePresenter(presentingViewController: userSessionDetailsHostingController) | ||
} | ||
|
||
// MARK: - Public | ||
|
||
func start() { | ||
MXLog.debug("[UserSessionDetailsCoordinator] did start.") | ||
userSessionDetailsViewModel.completion = { [weak self] result in | ||
guard let self = self else { return } | ||
MXLog.debug("[UserSessionDetailsCoordinator] UserSessionDetailsViewModel did complete with result: \(result).") | ||
self.completion?(result) | ||
} | ||
} | ||
|
||
func toPresentable() -> UIViewController { | ||
return self.userSessionDetailsHostingController | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
RiotSwiftUI/Modules/UserSessions/UserSessionDetails/MockUserSessionDetailsScreenState.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// Copyright 2021 New Vector Ltd | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// Using an enum for the screen allows you define the different state cases with | ||
/// the relevant associated data for each case. | ||
enum MockUserSessionDetailsScreenState: MockScreenState, CaseIterable { | ||
// A case for each state you want to represent | ||
// with specific, minimal associated data that will allow you | ||
// mock that screen. | ||
case allSections | ||
case sessionSectionOnly | ||
|
||
/// The associated screen | ||
var screenType: Any.Type { | ||
UserSessionDetails.self | ||
} | ||
|
||
/// A list of screen state definitions | ||
static var allCases: [MockUserSessionDetailsScreenState] { | ||
// Each of the presence statuses | ||
return [.allSections, sessionSectionOnly] | ||
} | ||
|
||
/// Generate the view struct for the screen state. | ||
var screenView: ([Any], AnyView) { | ||
let currentSessionInfo: UserSessionInfo | ||
switch self { | ||
case .allSections: | ||
currentSessionInfo = UserSessionInfo(sessionId: "session", | ||
sessionName: "iOS", | ||
deviceType: .mobile, | ||
isVerified: false, | ||
lastSeenIP: "10.0.0.10", | ||
lastSeenTimestamp: Date().timeIntervalSince1970 - 100) | ||
case .sessionSectionOnly: | ||
currentSessionInfo = UserSessionInfo(sessionId: "session", | ||
sessionName: "iOS", | ||
deviceType: .mobile, | ||
isVerified: false, | ||
lastSeenIP: nil, | ||
lastSeenTimestamp: Date().timeIntervalSince1970 - 100) | ||
} | ||
let viewModel = UserSessionDetailsViewModel(userSessionInfo: currentSessionInfo) | ||
|
||
// can simulate service and viewModel actions here if needs be. | ||
|
||
return ( | ||
[currentSessionInfo], | ||
AnyView(UserSessionDetails(viewModel: viewModel.context)) | ||
) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
RiotSwiftUI/Modules/UserSessions/UserSessionDetails/Test/UI/UserSessionDetailsUITests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// Copyright 2021 New Vector Ltd | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import XCTest | ||
import RiotSwiftUI | ||
|
||
class UserSessionDetailsUITests: MockScreenTestCase { | ||
|
||
func test_longPressDetailsCell_CopiesValueToClipboard() throws { | ||
app.goToScreenWithIdentifier(MockUserSessionDetailsScreenState.allSections.title) | ||
|
||
UIPasteboard.general.string = "" | ||
|
||
let tables = app.tables | ||
let sessionNameIosCell = tables.cells["Session name, iOS"] | ||
sessionNameIosCell.press(forDuration: 0.5) | ||
|
||
app.buttons["Copy"].tap() | ||
|
||
let clipboard = try XCTUnwrap(UIPasteboard.general.string) | ||
XCTAssertEqual(clipboard,"iOS") | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
.../Modules/UserSessions/UserSessionDetails/Test/Unit/UserSessionDetailsViewModelTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// | ||
// Copyright 2021 New Vector Ltd | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import XCTest | ||
|
||
@testable import RiotSwiftUI | ||
|
||
class UserSessionDetailsViewModelTests: XCTestCase { | ||
|
||
func test_whenSessionNameAndLastSeenIPNil_viewStateCorrect() { | ||
let userSessionInfo = createUserSessionInfo(sessionId: "session", | ||
sessionName: nil, | ||
lastSeenIP: nil) | ||
|
||
var sessionItems = [UserSessionDetailsSectionItemViewData]() | ||
sessionItems.append(sessionIdItem(sessionId: userSessionInfo.sessionId)) | ||
|
||
var sections = [UserSessionDetailsSectionViewData]() | ||
sections.append(UserSessionDetailsSectionViewData(header: VectorL10n.userSessionDetailsSessionSectionHeader, | ||
footer: VectorL10n.userSessionDetailsSessionSectionFooter, | ||
items: sessionItems)) | ||
let expectedModel = UserSessionDetailsViewState(sections: sections) | ||
let sut = UserSessionDetailsViewModel(userSessionInfo: userSessionInfo) | ||
|
||
XCTAssertEqual(sut.state, expectedModel) | ||
} | ||
|
||
func test_whenSessionNameNotNilLastSeenIPNil_viewStateCorrect() { | ||
let userSessionInfo = createUserSessionInfo(sessionId: "session", | ||
sessionName: "session name", | ||
lastSeenIP: nil) | ||
|
||
var sessionItems = [UserSessionDetailsSectionItemViewData]() | ||
sessionItems.append(sessionNameItem(sessionName: "session name")) | ||
sessionItems.append(sessionIdItem(sessionId: userSessionInfo.sessionId)) | ||
|
||
var sections = [UserSessionDetailsSectionViewData]() | ||
sections.append(UserSessionDetailsSectionViewData(header: VectorL10n.userSessionDetailsSessionSectionHeader, | ||
footer: VectorL10n.userSessionDetailsSessionSectionFooter, | ||
items: sessionItems)) | ||
|
||
let expectedModel = UserSessionDetailsViewState(sections: sections) | ||
let sut = UserSessionDetailsViewModel(userSessionInfo: userSessionInfo) | ||
|
||
XCTAssertEqual(sut.state, expectedModel) | ||
} | ||
|
||
func test_whenUserSessionInfoContainsAllValues_viewStateCorrect() { | ||
let userSessionInfo = createUserSessionInfo(sessionId: "session", | ||
sessionName: "session name", | ||
lastSeenIP: "0.0.0.0") | ||
|
||
var sessionItems = [UserSessionDetailsSectionItemViewData]() | ||
sessionItems.append(sessionNameItem(sessionName: "session name")) | ||
sessionItems.append(sessionIdItem(sessionId: userSessionInfo.sessionId)) | ||
|
||
var sections = [UserSessionDetailsSectionViewData]() | ||
sections.append(UserSessionDetailsSectionViewData(header: VectorL10n.userSessionDetailsSessionSectionHeader, | ||
footer: VectorL10n.userSessionDetailsSessionSectionFooter, | ||
items: sessionItems)) | ||
|
||
var deviceSectionItems = [UserSessionDetailsSectionItemViewData]() | ||
deviceSectionItems.append(UserSessionDetailsSectionItemViewData(title: VectorL10n.userSessionDetailsDeviceIpAddress, | ||
value: "0.0.0.0")) | ||
sections.append(UserSessionDetailsSectionViewData(header: VectorL10n.userSessionDetailsDeviceSectionHeader, | ||
footer: nil, | ||
items: deviceSectionItems)) | ||
|
||
let expectedModel = UserSessionDetailsViewState(sections: sections) | ||
let sut = UserSessionDetailsViewModel(userSessionInfo: userSessionInfo) | ||
|
||
XCTAssertEqual(sut.state, expectedModel) | ||
} | ||
|
||
private func createUserSessionInfo(sessionId: String, | ||
sessionName: String?, | ||
deviceType: DeviceType = .mobile, | ||
isVerified: Bool = false, | ||
lastSeenIP: String?, | ||
lastSeenTimestamp: TimeInterval = Date().timeIntervalSince1970) -> UserSessionInfo { | ||
UserSessionInfo(sessionId: sessionId, | ||
sessionName: sessionName, | ||
deviceType: deviceType, | ||
isVerified: isVerified, | ||
lastSeenIP: lastSeenIP, | ||
lastSeenTimestamp: lastSeenTimestamp) | ||
|
||
} | ||
|
||
private func sessionNameItem(sessionName: String) -> UserSessionDetailsSectionItemViewData { | ||
UserSessionDetailsSectionItemViewData(title: VectorL10n.userSessionDetailsSessionName, | ||
value: sessionName) | ||
} | ||
|
||
private func sessionIdItem(sessionId: String) -> UserSessionDetailsSectionItemViewData { | ||
UserSessionDetailsSectionItemViewData(title: VectorL10n.keyVerificationManuallyVerifyDeviceIdTitle, | ||
value: sessionId) | ||
} | ||
} |
Oops, something went wrong.