-
Notifications
You must be signed in to change notification settings - Fork 491
Expand file tree
/
Copy pathSceneDelegateTests.swift
More file actions
50 lines (36 loc) · 1.4 KB
/
SceneDelegateTests.swift
File metadata and controls
50 lines (36 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// Copyright © Essential Developer. All rights reserved.
//
import XCTest
import EssentialFeediOS
@testable import EssentialApp
@MainActor
class SceneDelegateTests: XCTestCase {
func test_configureWindow_setsWindowAsKeyAndVisible() throws {
let sut = SceneDelegate()
let window = try UIWindowSpy.make()
sut.window = window
sut.configureWindow()
XCTAssertEqual(window.makeKeyAndVisibleCallCount, 1, "Expected to make window key and visible")
}
func test_configureWindow_configuresRootViewController() throws {
let sut = SceneDelegate()
sut.window = try UIWindowSpy.make()
sut.configureWindow()
let root = sut.window?.rootViewController
let rootNavigation = root as? UINavigationController
let topController = rootNavigation?.topViewController
XCTAssertNotNil(rootNavigation, "Expected a navigation controller as root, got \(String(describing: root)) instead")
XCTAssertTrue(topController is ListViewController, "Expected a feed controller as top view controller, got \(String(describing: topController)) instead")
}
private class UIWindowSpy: UIWindow {
var makeKeyAndVisibleCallCount = 0
static func make() throws -> UIWindowSpy {
let dummyScene = try XCTUnwrap((UIWindowScene.self as NSObject.Type).init() as? UIWindowScene)
return UIWindowSpy(windowScene: dummyScene)
}
override func makeKeyAndVisible() {
makeKeyAndVisibleCallCount += 1
}
}
}