-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
FundingGraphViewTests.swift
136 lines (110 loc) · 4.27 KB
/
FundingGraphViewTests.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
@testable import Kickstarter_Framework
@testable import KsApi
import Library
import Prelude
import ReactiveExtensions_TestHelpers
import XCTest
internal final class FundingGraphViewTests: TestCase {
fileprivate let vm: DashboardFundingCellViewModelType = DashboardFundingCellViewModel()
fileprivate let graphData = TestObserver<FundingGraphData, Never>()
override func setUp() {
super.setUp()
AppEnvironment.pushEnvironment(mainBundle: Bundle.framework)
self.vm.outputs.graphData.observe(self.graphData.observer)
}
override func tearDown() {
super.tearDown()
AppEnvironment.popEnvironment()
}
func testGoalLabelLanguages() {
let graphView = FundingGraphView(frame: CGRect(x: 0, y: 0, width: 300, height: 225))
let stats = [3_000, 4_000, 5_000, 7_000, 8_000, 13_000, 14_000, 15_000, 17_000, 18_000]
self.vm.inputs.configureWith(
fundingDateStats: fundingStats(forProject: project, pledgeValues: stats),
project: project
)
graphView.project = self.graphData.lastValue!.project
graphView.stats = self.graphData.lastValue!.stats
graphView.yAxisTickSize = self.graphData.lastValue!.yAxisTickSize
Language.allLanguages.forEach { language in
withEnvironment(language: language) {
graphView.setNeedsDisplay()
FBSnapshotVerifyView(graphView, identifier: "lang_\(language)")
}
}
}
func testGraphStates() {
let graphView = FundingGraphView(frame: CGRect(x: 0, y: 0, width: 300, height: 225))
let underFundedStats = [
3_000, 4_000, 5_000, 7_000, 8_000
]
let justFundedStats = underFundedStats + [
13_000, 14_000, 15_000, 17_000, 18_000,
20_000, 21_000, 22_000, 24_000
]
let backUnderFundedStats = justFundedStats + [
23_000, 22_500, 20_000, 19_500, 18_000
]
let backOverFunded = backUnderFundedStats + [
21_000, 21_500, 22_500, 24_000, 25_000,
26_000, 29_000
]
let oneDayLeft = backOverFunded + [
32_000, 38_000, 48_000, 50_000
]
let completedStats = oneDayLeft + [55_000]
let statStates = [
"Under Funded": underFundedStats,
"Just Funded": justFundedStats,
"Back Under Funded": backUnderFundedStats,
"Back Over Funded": backOverFunded,
"One Day Left": oneDayLeft,
"Completed": completedStats
]
for (key, stats) in statStates {
self.vm.inputs.configureWith(
fundingDateStats: fundingStats(forProject: project, pledgeValues: stats),
project: project
)
graphView.project = self.graphData.lastValue!.project
graphView.stats = self.graphData.lastValue!.stats
graphView.yAxisTickSize = self.graphData.lastValue!.yAxisTickSize
FBSnapshotVerifyView(graphView, identifier: "state_\(key)")
}
}
func testOneDayProject() {
let oneDayProject = .template
|> Project.lens.stats.goal .~ 2_000
|> Project.lens.dates.launchedAt .~ 123_456_789.0
|> Project.lens.dates.deadline .~ Double(123_456_789 + 60 * 60 * 24)
let graphView = FundingGraphView(frame: CGRect(x: 0, y: 0, width: 300, height: 225))
let statStates = [
"Under Funded": [200, 1_000],
"Just Funded": [200, 2_100],
"Way Over Funded": [3_000, 6_000]
]
for (key, stats) in statStates {
self.vm.inputs.configureWith(
fundingDateStats: fundingStats(forProject: oneDayProject, pledgeValues: stats),
project: oneDayProject
)
graphView.project = self.graphData.lastValue!.project
graphView.stats = self.graphData.lastValue!.stats
graphView.yAxisTickSize = self.graphData.lastValue!.yAxisTickSize
FBSnapshotVerifyView(graphView, identifier: "state_\(key)")
}
}
}
private let project = .template
|> Project.lens.stats.goal .~ 22_000
|> Project.lens.dates.launchedAt .~ 1_477_494_745.0
|> Project.lens.dates.deadline .~ 1_480_187_443.0
private func fundingStats(forProject project: Project, pledgeValues: [Int])
-> [ProjectStatsEnvelope.FundingDateStats] {
return pledgeValues.enumerated().map { (idx: Int, pledged: Int) in
ProjectStatsEnvelope.FundingDateStats.template
|> ProjectStatsEnvelope.FundingDateStats.lens.cumulativePledged .~ pledged
|> ProjectStatsEnvelope.FundingDateStats.lens.date
.~ (project.dates.launchedAt + TimeInterval(idx * 60 * 60 * 24))
}
}