-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
ProjectActivitiesDataSourceTests.swift
97 lines (86 loc) · 4.39 KB
/
ProjectActivitiesDataSourceTests.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
@testable import Kickstarter_Framework
@testable import KsApi
@testable import Library
import Prelude
import XCTest
internal final class ProjectActivitiesDataSourceTests: XCTestCase {
let dataSource = ProjectActivitiesDataSource()
let tableView = UITableView()
func testDataSource() {
let timeZone = TimeZone(abbreviation: "UTC")!
var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = timeZone
withEnvironment(calendar: calendar) {
let section = ProjectActivitiesDataSource.Section.activities.rawValue
let project = Project.template
let activities = [
Activity.template
|> Activity.lens.category .~ Activity.Category.backing
|> Activity.lens.createdAt .~ 1_474_606_800 // 2016-09-23T05:00:00Z
|> Activity.lens.project .~ project,
Activity.template
|> Activity.lens.category .~ Activity.Category.commentPost
|> Activity.lens.createdAt .~ 1_474_605_000 // 2016-09-23T04:30:00Z
|> Activity.lens.project .~ project,
Activity.template
|> Activity.lens.category .~ Activity.Category.success
|> Activity.lens.createdAt .~ 1_474_700_400 // 2016-09-24T07:00:00Z
|> Activity.lens.project .~ project,
Activity.template
|> Activity.lens.category .~ Activity.Category.launch
|> Activity.lens.createdAt .~ 1_474_538_400 // 2016-09-22T10:00:00Z
|> Activity.lens.project .~ project
]
self.dataSource.load(
projectActivityData:
ProjectActivityData(activities: activities, project: project, groupedDates: true)
)
XCTAssertEqual(section + 1, self.dataSource.numberOfSections(in: tableView))
XCTAssertEqual(7, self.dataSource.tableView(tableView, numberOfRowsInSection: section))
XCTAssertEqual("ProjectActivityDateCell", self.dataSource.reusableId(item: 0, section: section))
XCTAssertEqual("ProjectActivitySuccessCell", self.dataSource.reusableId(item: 1, section: section))
XCTAssertEqual("ProjectActivityDateCell", self.dataSource.reusableId(item: 2, section: section))
XCTAssertEqual("ProjectActivityBackingCell", self.dataSource.reusableId(item: 3, section: section))
XCTAssertEqual("ProjectActivityCommentCell", self.dataSource.reusableId(item: 4, section: section))
XCTAssertEqual("ProjectActivityDateCell", self.dataSource.reusableId(item: 5, section: section))
XCTAssertEqual("ProjectActivityLaunchCell", self.dataSource.reusableId(item: 6, section: section))
}
}
func testGroupedDatesIsFalse() {
let timeZone = TimeZone(abbreviation: "UTC")!
var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = timeZone
withEnvironment(calendar: calendar) {
let section = ProjectActivitiesDataSource.Section.activities.rawValue
let project = Project.template
let activities = [
Activity.template
|> Activity.lens.category .~ Activity.Category.backing
|> Activity.lens.createdAt .~ 1_474_606_800 // 2016-09-23T05:00:00Z
|> Activity.lens.project .~ project,
Activity.template
|> Activity.lens.category .~ Activity.Category.success
|> Activity.lens.createdAt .~ 1_474_605_000 // 2016-09-23T04:30:00Z
|> Activity.lens.project .~ project
]
self.dataSource.load(
projectActivityData:
ProjectActivityData(activities: activities, project: project, groupedDates: false)
)
XCTAssertEqual(4, self.dataSource.tableView(tableView, numberOfRowsInSection: section))
XCTAssertEqual("ProjectActivityDateCell", self.dataSource.reusableId(item: 0, section: section))
XCTAssertEqual("ProjectActivityBackingCell", self.dataSource.reusableId(item: 1, section: section))
XCTAssertEqual(
"ProjectActivityDateCell", self.dataSource.reusableId(item: 2, section: section),
"Should append second date cell, even though date is the same as the first date cell"
)
XCTAssertEqual("ProjectActivitySuccessCell", self.dataSource.reusableId(item: 3, section: section))
}
}
func testEmptyState() {
let section = ProjectActivitiesDataSource.Section.emptyState.rawValue
self.dataSource.emptyState(visible: true)
XCTAssertEqual(1, self.dataSource.tableView(self.tableView, numberOfRowsInSection: section))
XCTAssertEqual("ProjectActivityEmptyStateCell", self.dataSource.reusableId(item: 0, section: section))
}
}