-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathStatefulViewControllerTests.swift
More file actions
70 lines (56 loc) · 2.44 KB
/
StatefulViewControllerTests.swift
File metadata and controls
70 lines (56 loc) · 2.44 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// StatefulViewControllerTests.swift
// StatefulViewControllerTests
//
// Created by Alexander Schuch on 12/01/15.
// Copyright (c) 2015 Alexander Schuch. All rights reserved.
//
#if canImport(UIKit)
import UIKit
import XCTest
import StatefulViewController
class StatefulViewControllerTests: XCTestCase {
lazy var stateMachine = ViewStateMachine(view: UIView())
var errorView: UIView = UIView()
var loadingView: UIView = UIView()
var emptyView: UIView = UIView()
override func setUp() {
super.setUp()
errorView = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 480))
errorView.backgroundColor = UIColor.red
loadingView = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 480))
loadingView.backgroundColor = UIColor.blue
emptyView = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 480))
emptyView.backgroundColor = UIColor.gray
stateMachine.addView(errorView, forState: "error")
stateMachine.addView(loadingView, forState: "loading")
stateMachine.addView(emptyView, forState: "empty")
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testStateMachine() {
stateMachine.transitionToState(.view("error"), animated: true) {
XCTAssertTrue(self.errorView.superview === self.stateMachine.view, "")
XCTAssertNil(self.loadingView.superview, "")
XCTAssertNil(self.emptyView.superview, "")
}
stateMachine.transitionToState(.view("loading"), animated: true) {
XCTAssertNil(self.errorView.superview, "")
XCTAssertTrue(self.loadingView.superview === self.stateMachine.view, "")
XCTAssertNil(self.emptyView.superview, "")
}
stateMachine.transitionToState(.none, animated: true) {
XCTAssertNil(self.errorView.superview, "")
XCTAssertNil(self.loadingView.superview, "")
XCTAssertNil(self.emptyView.superview, "")
}
stateMachine.transitionToState(.view("empty"), animated: true) {
XCTAssertNil(self.errorView.superview, "")
XCTAssertNil(self.loadingView.superview, "")
XCTAssertFalse(self.emptyView.superview === self.stateMachine.view, "")
}
}
}
#endif