-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathDiscoveryFiltersDataSourceTests.swift
122 lines (107 loc) · 5.84 KB
/
DiscoveryFiltersDataSourceTests.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
import XCTest
@testable import Kickstarter_Framework
@testable import Library
import KsApi
import Prelude
internal final class DiscoveryFiltersDataSourceTests: XCTestCase {
fileprivate let collectionsHeader = DiscoveryFiltersDataSource.Section.collectionsHeader.rawValue
fileprivate let collections = DiscoveryFiltersDataSource.Section.collections.rawValue
fileprivate let categoriesHeader = DiscoveryFiltersDataSource.Section.categoriesHeader.rawValue
fileprivate let categories = DiscoveryFiltersDataSource.Section.categories.rawValue
fileprivate let favoritesHeader = DiscoveryFiltersDataSource.Section.favoritesHeader.rawValue
fileprivate let favorites = DiscoveryFiltersDataSource.Section.favorites.rawValue
fileprivate let dataSource = DiscoveryFiltersDataSource()
fileprivate let tableView = UITableView()
func testLoadTopRows() {
self.dataSource.load(topRows: [
SelectableRow(isSelected: false, params: .defaults),
SelectableRow(isSelected: false, params: .defaults),
SelectableRow(isSelected: false, params: .defaults),
SelectableRow(isSelected: false, params: .defaults)
],
categoryId: nil
)
XCTAssertEqual(4, self.dataSource.tableView(self.tableView, numberOfRowsInSection: collections))
XCTAssertEqual("DiscoverySelectableRowCell", self.dataSource.reusableId(item: 0, section: collections))
XCTAssertEqual(1, self.dataSource.tableView(self.tableView, numberOfRowsInSection: collectionsHeader))
XCTAssertEqual("DiscoveryFiltersStaticRowCell",
self.dataSource.reusableId(item: 0, section: collectionsHeader))
}
func testLoadFavoriteRows() {
self.dataSource.load(favoriteRows: [
SelectableRow(isSelected: false, params: .defaults),
SelectableRow(isSelected: false, params: .defaults),
SelectableRow(isSelected: false, params: .defaults),
SelectableRow(isSelected: false, params: .defaults)
],
categoryId: nil
)
XCTAssertEqual(4, self.dataSource.tableView(self.tableView, numberOfRowsInSection: favorites))
XCTAssertEqual("DiscoverySelectableRowCell", self.dataSource.reusableId(item: 0, section: favorites))
XCTAssertEqual(1, self.dataSource.tableView(self.tableView, numberOfRowsInSection: favoritesHeader))
XCTAssertEqual("DiscoveryFiltersStaticRowCell",
self.dataSource.reusableId(item: 0, section: favoritesHeader))
}
func testLoadCategories() {
self.dataSource.load(categoryRows: [
ExpandableRow(
isExpanded: false,
params: .defaults,
selectableRows: [
SelectableRow(isSelected: false, params: .defaults),
SelectableRow(isSelected: false, params: .defaults)
]
),
ExpandableRow(
isExpanded: false,
params: .defaults,
selectableRows: [
SelectableRow(isSelected: false, params: .defaults),
SelectableRow(isSelected: false, params: .defaults)
]
)
],
categoryId: nil)
XCTAssertEqual(2, self.dataSource.tableView(self.tableView, numberOfRowsInSection: categories))
XCTAssertEqual("DiscoveryExpandableRowCell", self.dataSource.reusableId(item: 0, section: categories))
XCTAssertEqual("DiscoveryExpandableRowCell", self.dataSource.reusableId(item: 1, section: categories))
XCTAssertEqual(1, self.dataSource.tableView(self.tableView, numberOfRowsInSection: categoriesHeader))
}
func testLoadCategoriesWithExpansion() {
self.dataSource.load(categoryRows: [
ExpandableRow(
isExpanded: false,
params: .defaults,
selectableRows: [
SelectableRow(isSelected: false, params: .defaults),
SelectableRow(isSelected: false, params: .defaults)
]
),
ExpandableRow(
isExpanded: true,
params: .defaults,
selectableRows: [
SelectableRow(isSelected: false, params: .defaults),
SelectableRow(isSelected: false, params: .defaults)
]
)
],
categoryId: nil)
XCTAssertEqual(4, self.dataSource.tableView(self.tableView, numberOfRowsInSection: categories))
XCTAssertEqual("DiscoveryExpandableRowCell", self.dataSource.reusableId(item: 0, section: categories))
XCTAssertEqual("DiscoveryExpandableRowCell", self.dataSource.reusableId(item: 1, section: categories))
XCTAssertEqual("DiscoveryExpandedSelectableRowCell",
self.dataSource.reusableId(item: 2, section: categories))
XCTAssertEqual("DiscoveryExpandedSelectableRowCell",
self.dataSource.reusableId(item: 3, section: categories))
}
func testLoadCategoriesLoaderRow() {
self.dataSource.loadCategoriesLoaderRow()
let row1 = self.dataSource.deleteCategoriesLoaderRow(self.tableView)
XCTAssertNotNil(row1)
XCTAssertEqual(row1?.first?.row, .some(0))
XCTAssertEqual(row1?.first?.section, .some(DiscoveryFiltersDataSource.Section.categoriesLoader.rawValue))
let row2 = self.dataSource.deleteCategoriesLoaderRow(self.tableView)
XCTAssertNil(row2)
}
}