generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BIT-174 Adds app-wide navigation layer
- Loading branch information
1 parent
e0e05b2
commit 4dddce6
Showing
30 changed files
with
636 additions
and
136 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import BitwardenShared | ||
import UIKit | ||
|
||
class AppDelegate: UIResponder, UIApplicationDelegate {} |
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,37 @@ | ||
import BitwardenShared | ||
import UIKit | ||
|
||
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | ||
// MARK: Properties | ||
|
||
/// The root module to use to create sub-coordinators. | ||
var appModule: AppModule = DefaultAppModule() | ||
|
||
/// The root coordinator of this scene. | ||
var appCoordinator: AnyCoordinator<AppRoute>? | ||
|
||
/// The main window for this scene. | ||
var window: UIWindow? | ||
|
||
// MARK: Methods | ||
|
||
func scene( | ||
_ scene: UIScene, | ||
willConnectTo session: UISceneSession, | ||
options connectionOptions: UIScene.ConnectionOptions | ||
) { | ||
guard let windowScene = (scene as? UIWindowScene) else { | ||
return | ||
} | ||
|
||
let appWindow = UIWindow(windowScene: windowScene) | ||
let rootViewController = RootViewController() | ||
let coordinator = appModule.makeAppCoordinator(navigator: rootViewController) | ||
coordinator.start() | ||
|
||
appWindow.rootViewController = rootViewController | ||
appWindow.makeKeyAndVisible() | ||
appCoordinator = coordinator | ||
window = appWindow | ||
} | ||
} |
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,61 @@ | ||
import BitwardenShared | ||
import XCTest | ||
|
||
@testable import Bitwarden | ||
|
||
// MARK: - SceneDelegateTests | ||
|
||
class SceneDelegateTests: BitwardenTestCase { | ||
// MARK: Properties | ||
|
||
var appCoordinator: MockCoordinator<AppRoute>! | ||
var appModule: MockAppModule! | ||
var subject: SceneDelegate! | ||
|
||
// MARK: Setup & Teardown | ||
|
||
override func setUp() { | ||
super.setUp() | ||
appCoordinator = MockCoordinator<AppRoute>() | ||
appModule = MockAppModule() | ||
appModule.appCoordinator = appCoordinator.asAnyCoordinator() | ||
subject = SceneDelegate() | ||
subject.appModule = appModule | ||
} | ||
|
||
override func tearDown() { | ||
super.tearDown() | ||
appModule = nil | ||
subject = nil | ||
} | ||
|
||
// MARK: Tests | ||
|
||
/// `scene(_:willConnectTo:options:)` with a `UIWindowScene` creates the app's UI. | ||
func test_sceneWillConnectTo_withWindowScene() throws { | ||
let session = TestInstanceFactory.create(UISceneSession.self) | ||
let scene = TestInstanceFactory.create(UIWindowScene.self, properties: [ | ||
"session": session, | ||
]) | ||
let options = TestInstanceFactory.create(UIScene.ConnectionOptions.self) | ||
subject.scene(scene, willConnectTo: session, options: options) | ||
|
||
XCTAssertNotNil(subject.appCoordinator) | ||
XCTAssertNotNil(subject.window) | ||
XCTAssertTrue(appCoordinator.isStarted) | ||
} | ||
|
||
/// `scene(_:willConnectTo:options:)` without a `UIWindowScene` fails to create the app's UI. | ||
func test_sceneWillConnectTo_withNonWindowScene() throws { | ||
let session = TestInstanceFactory.create(UISceneSession.self) | ||
let scene = TestInstanceFactory.create(UIScene.self, properties: [ | ||
"session": session, | ||
]) | ||
let options = TestInstanceFactory.create(UIScene.ConnectionOptions.self) | ||
subject.scene(scene, willConnectTo: session, options: options) | ||
|
||
XCTAssertNil(subject.appCoordinator) | ||
XCTAssertNil(subject.window) | ||
XCTAssertFalse(appCoordinator.isStarted) | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
Bitwarden/Application/TestHelpers/Support/TestInstanceFactory.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,11 @@ | ||
import Foundation | ||
|
||
enum TestInstanceFactory { | ||
static func create<T: NSObject>(_ type: T.Type, properties: [String: Any] = [:]) -> T { | ||
let instance = type.init() | ||
for property in properties { | ||
instance.setValue(property.value, forKey: property.key) | ||
} | ||
return instance | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import UIKit | ||
|
||
/// Determine the app delegate class that should be used during this launch of the app. If the `TestingAppDelegate` | ||
/// can be found, the app was launched in a test environment, and we should use the `TestingAppDelegate` for | ||
/// handling all app lifecycle events. | ||
private let appDelegateClass: AnyClass = NSClassFromString("BitwardenTests.TestingAppDelegate") ?? AppDelegate.self | ||
|
||
UIApplicationMain(CommandLine.argc, CommandLine.unsafeArgv, nil, NSStringFromClass(appDelegateClass)) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.