diff --git a/RiotSwiftUI/Modules/Common/Mock/MockAppScreens.swift b/RiotSwiftUI/Modules/Common/Mock/MockAppScreens.swift index a222edf3f..e028c5fb1 100644 --- a/RiotSwiftUI/Modules/Common/Mock/MockAppScreens.swift +++ b/RiotSwiftUI/Modules/Common/Mock/MockAppScreens.swift @@ -19,6 +19,6 @@ import Foundation /// The static list of mocked screens in RiotSwiftUI @available(iOS 14.0, *) enum MockAppScreens { - static let appScreens = [MockTemplateProfileUserScreenState.self] + static let appScreens = [MockTemplateUserProfileScreenState.self] } diff --git a/RiotSwiftUI/Modules/Common/Mock/ScreenList.swift b/RiotSwiftUI/Modules/Common/Mock/ScreenList.swift index 62b857769..973ab530b 100644 --- a/RiotSwiftUI/Modules/Common/Mock/ScreenList.swift +++ b/RiotSwiftUI/Modules/Common/Mock/ScreenList.swift @@ -44,6 +44,6 @@ struct ScreenList: View { @available(iOS 14.0, *) struct ScreenList_Previews: PreviewProvider { static var previews: some View { - ScreenList(screens: [MockTemplateProfileUserScreenState.self]) + ScreenList(screens: [MockTemplateUserProfileScreenState.self]) } } diff --git a/RiotSwiftUI/Modules/Common/Test/UI/MockScreenTest.swift b/RiotSwiftUI/Modules/Common/Test/UI/MockScreenTest.swift index 9d3a65e6d..1146d4715 100644 --- a/RiotSwiftUI/Modules/Common/Test/UI/MockScreenTest.swift +++ b/RiotSwiftUI/Modules/Common/Test/UI/MockScreenTest.swift @@ -31,6 +31,10 @@ class MockScreenTest: XCTestCase { return nil } + class func createTest() -> MockScreenTest { + return MockScreenTest() + } + var screenState: MockScreenState? var screenStateKey: String? let app = XCUIApplication() @@ -48,13 +52,11 @@ class MockScreenTest: XCTestCase { return testSuite } - private class func addTestFor(screenState: MockScreenState, screenStateKey: String, toTestSuite testSuite: XCTestSuite) { - testInvocations.forEach { invocation in - let testCase = TestUserProfileUITests(invocation: invocation) - testCase.screenState = screenState - testCase.screenStateKey = screenStateKey - testSuite.addTest(testCase) - } + class func addTestFor(screenState: MockScreenState, screenStateKey: String, toTestSuite testSuite: XCTestSuite) { + let test = createTest() + test.screenState = screenState + test.screenStateKey = screenStateKey + testSuite.addTest(test) } open override func setUpWithError() throws { diff --git a/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Coordinator/TemplateUserProfileCoordinator.swift b/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Coordinator/TemplateUserProfileCoordinator.swift index c42a297a7..5818b543b 100644 --- a/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Coordinator/TemplateUserProfileCoordinator.swift +++ b/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Coordinator/TemplateUserProfileCoordinator.swift @@ -39,7 +39,7 @@ final class TemplateUserProfileCoordinator: Coordinator { @available(iOS 14.0, *) init(parameters: TemplateUserProfileCoordinatorParameters) { self.parameters = parameters - let viewModel = TemplateUserProfileViewModel(userService: TemplateUserProfileService(session: parameters.session)) + let viewModel = TemplateUserProfileViewModel(templateUserProfileService: TemplateUserProfileService(session: parameters.session)) let view = TemplateUserProfile(viewModel: viewModel) .addDependency(AvatarService.instantiate(mediaManager: parameters.session.mediaManager)) templateUserProfileViewModel = viewModel diff --git a/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Service/Mock/MockTemplateProfileUserScreenState.swift b/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Service/Mock/MockTemplateUserProfileScreenState.swift similarity index 86% rename from RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Service/Mock/MockTemplateProfileUserScreenState.swift rename to RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Service/Mock/MockTemplateUserProfileScreenState.swift index 29092cd8d..4388c4d1d 100644 --- a/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Service/Mock/MockTemplateProfileUserScreenState.swift +++ b/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Service/Mock/MockTemplateUserProfileScreenState.swift @@ -21,7 +21,7 @@ import SwiftUI /// Using an enum for the screen allows you define the different state cases with /// the relevant associated data for each case. @available(iOS 14.0, *) -enum MockTemplateProfileUserScreenState: MockScreenState, CaseIterable { +enum MockTemplateUserProfileScreenState: MockScreenState, CaseIterable { // A case for each state you want to represent // with specific, minimal associated data that will allow you // mock that screen. @@ -34,9 +34,9 @@ enum MockTemplateProfileUserScreenState: MockScreenState, CaseIterable { } /// A list of screen state definitions - static var allCases: [MockTemplateProfileUserScreenState] { + static var allCases: [MockTemplateUserProfileScreenState] { // Each of the presence statuses - TemplateUserProfilePresence.allCases.map(MockTemplateProfileUserScreenState.presence) + TemplateUserProfilePresence.allCases.map(MockTemplateUserProfileScreenState.presence) // A long display name + [.longDisplayName("Somebody with a super long name we would like to test")] } @@ -50,7 +50,7 @@ enum MockTemplateProfileUserScreenState: MockScreenState, CaseIterable { case .longDisplayName(let displayName): service = MockTemplateUserProfileService(displayName: displayName) } - let viewModel = TemplateUserProfileViewModel(userService: service) + let viewModel = TemplateUserProfileViewModel(templateUserProfileService: service) // can simulate service and viewModel actions here if needs be. diff --git a/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Test/UI/TestUserProfileUITests.swift b/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Test/UI/TemplateUserProfileUITests.swift similarity index 62% rename from RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Test/UI/TestUserProfileUITests.swift rename to RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Test/UI/TemplateUserProfileUITests.swift index 2bfd4d319..3507fcdf9 100644 --- a/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Test/UI/TestUserProfileUITests.swift +++ b/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Test/UI/TemplateUserProfileUITests.swift @@ -18,29 +18,33 @@ import XCTest import RiotSwiftUI @available(iOS 14.0, *) -class TestUserProfileUITests: MockScreenTest { +class TemplateUserProfileUITests: MockScreenTest { override class var screenType: MockScreenState.Type { - return MockTemplateProfileUserScreenState.self + return MockTemplateUserProfileScreenState.self + } + + override class func createTest() -> MockScreenTest { + return TemplateUserProfileUITests(selector: #selector(verifyTemplateUserProfileScreen)) } - func testTemplateUserProfileScreen() throws { - guard let screenState = screenState as? MockTemplateProfileUserScreenState else { fatalError("no screen") } + func verifyTemplateUserProfileScreen() throws { + guard let screenState = screenState as? MockTemplateUserProfileScreenState else { fatalError("no screen") } switch screenState { case .presence(let presence): - testTemplateUserProfilePresence(presence: presence) + verifyTemplateUserProfilePresence(presence: presence) case .longDisplayName(let name): - testTemplateUserProfileLongName(name: name) + verifyTemplateUserProfileLongName(name: name) } } - func testTemplateUserProfilePresence(presence: TemplateUserProfilePresence) { + func verifyTemplateUserProfilePresence(presence: TemplateUserProfilePresence) { let presenceText = app.staticTexts["presenceText"] XCTAssert(presenceText.exists) XCTAssert(presenceText.label == presence.title) } - func testTemplateUserProfileLongName(name: String) { + func verifyTemplateUserProfileLongName(name: String) { let displayNameText = app.staticTexts["displayNameText"] XCTAssert(displayNameText.exists) XCTAssert(displayNameText.label == name) diff --git a/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Test/Unit/TemplateUserProfileViewModelTests.swift b/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Test/Unit/TemplateUserProfileViewModelTests.swift index 74925f5d7..f14b1a2e6 100644 --- a/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Test/Unit/TemplateUserProfileViewModelTests.swift +++ b/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Test/Unit/TemplateUserProfileViewModelTests.swift @@ -30,7 +30,7 @@ class TemplateUserProfileViewModelTests: XCTestCase { var cancellables = Set() override func setUpWithError() throws { service = MockTemplateUserProfileService(displayName: Constants.displayName, presence: Constants.presenceInitialValue) - viewModel = TemplateUserProfileViewModel(userService: service) + viewModel = TemplateUserProfileViewModel(templateUserProfileService: service) } func testInitialState() { diff --git a/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/View/TemplateUserProfile.swift b/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/View/TemplateUserProfile.swift index 6025fceba..64cbf3ca4 100644 --- a/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/View/TemplateUserProfile.swift +++ b/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/View/TemplateUserProfile.swift @@ -67,6 +67,6 @@ struct TemplateUserProfile: View { @available(iOS 14.0, *) struct TemplateUserProfile_Previews: PreviewProvider { static var previews: some View { - MockTemplateProfileUserScreenState.screenGroup() + MockTemplateUserProfileScreenState.screenGroup() } } diff --git a/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/ViewModel/TemplateUserProfileViewModel.swift b/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/ViewModel/TemplateUserProfileViewModel.swift index cf625e152..f6b60cc3d 100644 --- a/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/ViewModel/TemplateUserProfileViewModel.swift +++ b/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/ViewModel/TemplateUserProfileViewModel.swift @@ -23,7 +23,7 @@ class TemplateUserProfileViewModel: ObservableObject, TemplateUserProfileViewMod // MARK: - Properties // MARK: Private - private let userService: TemplateUserProfileServiceProtocol + private let templateUserProfileService: TemplateUserProfileServiceProtocol private var cancellables = Set() // MARK: Public @@ -32,11 +32,11 @@ class TemplateUserProfileViewModel: ObservableObject, TemplateUserProfileViewMod var completion: ((TemplateUserProfileViewModelResult) -> Void)? // MARK: - Setup - init(userService: TemplateUserProfileServiceProtocol, initialState: TemplateUserProfileViewState? = nil) { - self.userService = userService - self.viewState = initialState ?? Self.defaultState(userService: userService) + init(templateUserProfileService: TemplateUserProfileServiceProtocol, initialState: TemplateUserProfileViewState? = nil) { + self.templateUserProfileService = templateUserProfileService + self.viewState = initialState ?? Self.defaultState(templateUserProfileService: templateUserProfileService) - userService.presenceSubject + templateUserProfileService.presenceSubject .map(TemplateUserProfileStateAction.updatePresence) .receive(on: DispatchQueue.main) .sink(receiveValue: { [weak self] action in @@ -45,8 +45,12 @@ class TemplateUserProfileViewModel: ObservableObject, TemplateUserProfileViewMod .store(in: &cancellables) } - private static func defaultState(userService: TemplateUserProfileServiceProtocol) -> TemplateUserProfileViewState { - return TemplateUserProfileViewState(avatar: userService.avatarData, displayName: userService.displayName, presence: userService.presenceSubject.value) + private static func defaultState(templateUserProfileService: TemplateUserProfileServiceProtocol) -> TemplateUserProfileViewState { + return TemplateUserProfileViewState( + avatar: templateUserProfileService.avatarData, + displayName: templateUserProfileService.displayName, + presence: templateUserProfileService.presenceSubject.value + ) } // MARK: - Public