Improve user session overview tests

* Add sessions overview UI tests
* Expose static methods from the UserSession name and lastActivity formatters; cleaned up the UserSessionsOverview a bit
* Add UserSessionsOverviewViewModel unit tests
* Add UserSessionsOverviewService unit tests
This commit is contained in:
Stefan Ceriu
2022-09-30 13:49:16 +03:00
committed by GitHub
parent fa7c7a49d6
commit f8d6f43967
21 changed files with 650 additions and 143 deletions

View File

@@ -20,31 +20,39 @@ import SwiftUI
/// Using an enum for the screen allows you define the different state cases with
/// the relevant associated data for each case.
enum MockUserSessionsOverviewScreenState: MockScreenState, CaseIterable {
case verifiedSession
case currentSessionUnverified
case currentSessionVerified
case onlyUnverifiedSessions
case onlyInactiveSessions
case noOtherSessions
/// The associated screen
var screenType: Any.Type {
UserSessionsOverview.self
}
/// A list of screen state definitions
static var allCases: [MockUserSessionsOverviewScreenState] {
// Each of the presence statuses
[.verifiedSession]
}
/// Generate the view struct for the screen state.
var screenView: ([Any], AnyView) {
let service = MockUserSessionsOverviewService()
var service: UserSessionsOverviewServiceProtocol?
switch self {
case .verifiedSession:
break
case .currentSessionUnverified:
service = MockUserSessionsOverviewService(mode: .currentSessionUnverified)
case .currentSessionVerified:
service = MockUserSessionsOverviewService(mode: .currentSessionVerified)
case .onlyUnverifiedSessions:
service = MockUserSessionsOverviewService(mode: .onlyUnverifiedSessions)
case .onlyInactiveSessions:
service = MockUserSessionsOverviewService(mode: .onlyInactiveSessions)
case .noOtherSessions:
service = MockUserSessionsOverviewService(mode: .noOtherSessions)
}
guard let service = service else {
fatalError()
}
let viewModel = UserSessionsOverviewViewModel(userSessionsOverviewService: service)
// can simulate service and viewModel actions here if needs be.
return (
[service, viewModel],
AnyView(UserSessionsOverview(viewModel: viewModel.context)