-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
PledgeAmountViewControllerTests.swift
164 lines (124 loc) · 5.89 KB
/
PledgeAmountViewControllerTests.swift
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
@testable import Kickstarter_Framework
@testable import KsApi
@testable import Library
import Prelude
import UIKit
private let regularHeight: CGFloat = 150
private let expandedHeight: CGFloat = 350
final class PledgeAmountViewControllerTests: TestCase {
override func setUp() {
super.setUp()
AppEnvironment.pushEnvironment(mainBundle: Bundle.framework)
UIView.setAnimationsEnabled(false)
}
override func tearDown() {
AppEnvironment.popEnvironment()
UIView.setAnimationsEnabled(true)
super.tearDown()
}
func testView() {
[Device.phone4_7inch, Device.pad].forEach { device in
let controller = PledgeAmountViewController.instantiate()
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)
parent.view.frame.size.height = regularHeight
controller.configureWith(value: (project: .template, reward: .template, 0))
FBSnapshotVerifyView(parent.view, identifier: "device_\(device)")
}
}
func testView_LargerText() {
UITraitCollection.allCases.forEach { additionalTraits in
let controller = PledgeAmountViewController.instantiate()
let (parent, _) = traitControllers(child: controller, additionalTraits: additionalTraits)
parent.view.frame.size.height = expandedHeight
controller.configureWith(value: (project: .template, reward: .template, 0))
FBSnapshotVerifyView(
parent.view, identifier: "trait_\(additionalTraits.preferredContentSizeCategory.rawValue)"
)
}
}
func testView_ShowsCurrencySymbol() {
let project = Project.template
|> Project.lens.country .~ Project.Country.ca
[Device.phone4_7inch, Device.pad].forEach { device in
let controller = PledgeAmountViewController.instantiate()
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)
parent.view.frame.size.height = regularHeight
controller.configureWith(value: (project: project, reward: .template, 0))
FBSnapshotVerifyView(parent.view, identifier: "device_\(device)")
}
}
func testView_StepperDecrementButtonDisabled_WhenStepperValueSetToMinimum() {
let reward = Reward.template
|> Reward.lens.minimum .~ 0
[Device.phone4_7inch, Device.pad].forEach { device in
let controller = PledgeAmountViewController.instantiate()
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)
parent.view.frame.size.height = regularHeight
controller.configureWith(value: (project: .template, reward: reward, 0))
controller.stepperValueChanged(UIStepper(frame: .zero) |> \.value .~ 0)
controller.textFieldDidChange(UITextField(frame: .zero) |> \.text .~ "0")
FBSnapshotVerifyView(parent.view, identifier: "device_\(device)")
}
}
func testView_StepperIncrementButtonDisabled_WhenStepperValueSetToMaximumStepperValue() {
let maxValue = PledgeAmountStepperConstants.max
let stepper = UIStepper(frame: .zero)
|> \.maximumValue .~ maxValue
|> \.value .~ maxValue
let textField = UITextField(frame: .zero)
|> \.text .~ String(format: "%.0f", maxValue)
[Device.phone4_7inch, Device.pad].forEach { device in
let controller = PledgeAmountViewController.instantiate()
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)
parent.view.frame.size.height = regularHeight
controller.configureWith(value: (project: .template, reward: .template, 0))
controller.stepperValueChanged(stepper)
controller.textFieldDidChange(textField)
FBSnapshotVerifyView(parent.view, identifier: "device_\(device)")
}
}
func testView_TextColorIsGreenWhenEqualToMinimumPledgeAmount() {
let reward = Reward.template
|> Reward.lens.minimum .~ 10
let stepper = UIStepper(frame: .zero)
|> \.value .~ 0
[Device.phone4_7inch, Device.pad].forEach { device in
let controller = PledgeAmountViewController.instantiate()
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)
parent.view.frame.size.height = regularHeight
controller.configureWith(value: (project: .template, reward: reward, 0))
controller.stepperValueChanged(stepper)
FBSnapshotVerifyView(parent.view, identifier: "device_\(device)")
}
}
func testView_TextColorIsGreenWhenEqualToMaximumPledgeAmount() {
let project = Project.template
|> (Project.lens.country .. Project.Country.lens.maxPledge) .~ 10_000
let stepper = UIStepper(frame: .zero)
|> \.maximumValue .~ PledgeAmountStepperConstants.max
|> \.value .~ 10_000
[Device.phone4_7inch, Device.pad].forEach { device in
let controller = PledgeAmountViewController.instantiate()
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)
parent.view.frame.size.height = regularHeight
controller.configureWith(value: (project: project, reward: .template, 0))
controller.stepperValueChanged(stepper)
FBSnapshotVerifyView(parent.view, identifier: "device_\(device)")
}
}
func testView_ErrorMessageAppears_And_TextColorIsRedWhenAboveMaximumPledgeAmount() {
let project = Project.template
|> (Project.lens.country .. Project.Country.lens.maxPledge) .~ 10_000
let stepper = UIStepper(frame: .zero)
|> \.maximumValue .~ PledgeAmountStepperConstants.max
|> \.value .~ 10_001
[Device.phone4_7inch, Device.pad].forEach { device in
let controller = PledgeAmountViewController.instantiate()
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)
parent.view.frame.size.height = regularHeight
controller.configureWith(value: (project: project, reward: .template, 0))
controller.stepperValueChanged(stepper)
FBSnapshotVerifyView(parent.view, identifier: "device_\(device)")
}
}
}