Skip to content

Commit 6eef3ad

Browse files
committed
add tests and refactor
1 parent 63c0347 commit 6eef3ad

5 files changed

Lines changed: 32 additions & 21 deletions

File tree

DemoTests/DemoTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,20 @@ class DemoTests: XCTestCase {
3939
XCTAssert(number == 0)
4040
}
4141

42+
func testIsHidden() {
43+
viewController.set(cells: viewController.hideMeCell3, hidden: true)
44+
viewController.reloadData(animated: true)
45+
46+
let isHidden = viewController.isHidden(cell: viewController.hideMeCell3)
47+
XCTAssert(isHidden)
48+
}
49+
50+
func testChangeHeight() {
51+
viewController.set(cells: viewController.hideMeCell3, height: 90)
52+
viewController.reloadData(animated: true)
53+
54+
let height = viewController.hideMeCell3.frame.size.height
55+
XCTAssert(height == 90)
56+
}
57+
4258
}

Source/OriginalRow.swift

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,6 @@ class OriginalRow {
1010
self.cell = cell
1111
self.originalIndexPath = originalIndexPath
1212
}
13-
14-
var hidden: Bool {
15-
get {
16-
return hiddenPlanned
17-
}
18-
set {
19-
if !hiddenReal && newValue {
20-
batchOperation = .delete
21-
} else if hiddenReal && !newValue {
22-
batchOperation = .insert
23-
}
24-
25-
hiddenPlanned = newValue
26-
}
27-
}
2813

2914
var hiddenReal: Bool = false
3015

@@ -39,9 +24,19 @@ class OriginalRow {
3924
var height: CGFloat = CGFloat.greatestFiniteMagnitude
4025

4126
func update() {
42-
if !hidden && batchOperation == .none {
27+
if !hiddenPlanned && batchOperation == .none {
4328
batchOperation = .update
4429
}
4530
}
4631

32+
func set(hidden: Bool) {
33+
if !hiddenReal && hidden {
34+
batchOperation = .delete
35+
} else if hiddenReal && !hidden {
36+
batchOperation = .insert
37+
}
38+
39+
hiddenPlanned = hidden
40+
}
41+
4742
}

Source/OriginalSection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class OriginalSection {
55
var rows: [OriginalRow] = []
66

77
func numberOfVissibleRows() -> Int {
8-
return rows.filter { !$0.hidden }.count
8+
return rows.filter { !$0.hiddenPlanned }.count
99
}
1010

1111
}

Source/OriginalTable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class OriginalTable {
6060

6161
func vissibleOriginalRowWithIndexPath(_ indexPath: IndexPath) -> OriginalRow {
6262
let section = sections[indexPath.section]
63-
let visibleRows = section.rows.filter { !$0.hidden }
63+
let visibleRows = section.rows.filter { !$0.hiddenPlanned }
6464

6565
return visibleRows[indexPath.row]
6666
}
@@ -76,7 +76,7 @@ class OriginalTable {
7676
var indexRow = originalRow.originalIndexPath.row
7777

7878
let section = sections[indexSection]
79-
indexRow = section.rows[0..<indexRow].filter { !$0.hidden }.count
79+
indexRow = section.rows[0..<indexRow].filter { !$0.hiddenPlanned }.count
8080

8181
return IndexPath(row: indexRow, section: indexSection)
8282
}

Source/StaticTableViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ open class StaticTableViewController: UITableViewController, OriginalTableConfig
2626
open func set(cells: UITableViewCell..., hidden: Bool) {
2727
cells.forEach { cell in
2828
let row = originalTable!.originalRowWithTableViewCell(cell)
29-
row.hidden = hidden
29+
row.set(hidden: hidden)
3030
}
3131
}
3232

@@ -38,7 +38,7 @@ open class StaticTableViewController: UITableViewController, OriginalTableConfig
3838
}
3939

4040
open func isHidden(cell: UITableViewCell) -> Bool {
41-
return originalTable!.originalRowWithTableViewCell(cell).hidden
41+
return originalTable!.originalRowWithTableViewCell(cell).hiddenReal
4242
}
4343

4444
open func reloadData(animated: Bool) {

0 commit comments

Comments
 (0)