mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Bootstrap custom version of the app for UI tests
This commit is contained in:
@@ -10,7 +10,7 @@ import UIKit
|
||||
@main
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
private var appCoordinator: AppCoordinator!
|
||||
private var appCoordinator: Coordinator!
|
||||
|
||||
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
|
||||
|
||||
@@ -27,11 +27,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
}
|
||||
|
||||
if isRunningUITests {
|
||||
// Bootstrap a different version of the application
|
||||
return true
|
||||
appCoordinator = UITestsAppCoordinator()
|
||||
} else {
|
||||
appCoordinator = AppCoordinator()
|
||||
}
|
||||
|
||||
appCoordinator = AppCoordinator()
|
||||
appCoordinator.start()
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// UITestsAppCoordinator.swift
|
||||
// ElementX
|
||||
//
|
||||
// Created by Stefan Ceriu on 29/04/2022.
|
||||
// Copyright © 2022 element.io. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import SwiftUI
|
||||
|
||||
class UITestsAppCoordinator: Coordinator {
|
||||
private let window: UIWindow
|
||||
private let mainNavigationController: UINavigationController
|
||||
|
||||
var childCoordinators: [Coordinator] = []
|
||||
|
||||
init() {
|
||||
mainNavigationController = UINavigationController()
|
||||
window = UIWindow(frame: UIScreen.main.bounds)
|
||||
window.rootViewController = mainNavigationController
|
||||
|
||||
let screens = mockScreens()
|
||||
let rootView = UITestsRootView(mockCoordinators: screens) { id in
|
||||
guard let coordinator = screens.filter({ $0.id == id }).first else {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
self.mainNavigationController.pushViewController(coordinator.coordinator.toPresentable(), animated: true)
|
||||
}
|
||||
|
||||
mainNavigationController.setViewControllers([UIHostingController(rootView: rootView)], animated: false)
|
||||
}
|
||||
|
||||
func start() {
|
||||
window.makeKeyAndVisible()
|
||||
}
|
||||
|
||||
private func mockScreens() -> [MockScreens] {
|
||||
[MockScreens(id: "Login screen", coordinator: LoginScreenCoordinator(parameters: .init()))]
|
||||
}
|
||||
}
|
||||
|
||||
struct MockScreens: Identifiable {
|
||||
let id: String
|
||||
let coordinator: Presentable
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// UITestsRootView.swift
|
||||
// ElementX
|
||||
//
|
||||
// Created by Stefan Ceriu on 29/04/2022.
|
||||
// Copyright © 2022 element.io. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct UITestsRootView: View {
|
||||
|
||||
let mockCoordinators: [MockScreens]
|
||||
var selectionCallback: ((String) -> Void)?
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
List(mockCoordinators) { coordinator in
|
||||
Button(coordinator.id) {
|
||||
selectionCallback?(coordinator.id)
|
||||
}
|
||||
}
|
||||
.listStyle(.plain)
|
||||
}
|
||||
.navigationTitle("Screens")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user