-
-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathDataTabGridDelegateTests.swift
More file actions
113 lines (89 loc) · 3.23 KB
/
DataTabGridDelegateTests.swift
File metadata and controls
113 lines (89 loc) · 3.23 KB
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
//
// DataTabGridDelegateTests.swift
// TableProTests
//
import AppKit
import Foundation
import Testing
@testable import TablePro
@MainActor
private final class FakeTableViewCoordinator: TableViewCoordinating {
var insertedCalls: [IndexSet] = []
var removedCalls: [IndexSet] = []
var fullReplaceCount: Int = 0
var invalidateCount: Int = 0
var deltaCalls: [Delta] = []
var commitEditCount: Int = 0
func applyInsertedRows(_ indices: IndexSet) {
insertedCalls.append(indices)
}
func applyRemovedRows(_ indices: IndexSet) {
removedCalls.append(indices)
}
func applyFullReplace() {
fullReplaceCount += 1
}
func invalidateCachesForUndoRedo() {
invalidateCount += 1
}
func applyDelta(_ delta: Delta) {
deltaCalls.append(delta)
}
func commitActiveCellEdit() {
commitEditCount += 1
}
var beginEditingCalls: [(row: Int, column: Int)] = []
func beginEditing(displayRow: Int, column: Int) {
beginEditingCalls.append((row: displayRow, column: column))
}
var refreshFKCount: Int = 0
var scrollToTopCount: Int = 0
func refreshForeignKeyColumns() { refreshFKCount += 1 }
func scrollToTop() { scrollToTopCount += 1 }
}
@Suite("DataTabGridDelegate row-delta forwarding")
@MainActor
struct DataTabGridDelegateTests {
@Test("dataGridDidInsertRows(at:) forwards the IndexSet to applyInsertedRows")
func insertForwardsIndices() {
let delegate = DataTabGridDelegate()
let applier = FakeTableViewCoordinator()
delegate.tableViewCoordinator = applier
let indices = IndexSet([1, 3, 5])
delegate.dataGridDidInsertRows(at: indices)
#expect(applier.insertedCalls.count == 1)
#expect(applier.insertedCalls.first == indices)
#expect(applier.removedCalls.isEmpty)
#expect(applier.fullReplaceCount == 0)
}
@Test("dataGridDidRemoveRows(at:) forwards the IndexSet to applyRemovedRows")
func removeForwardsIndices() {
let delegate = DataTabGridDelegate()
let applier = FakeTableViewCoordinator()
delegate.tableViewCoordinator = applier
let indices = IndexSet(integersIn: 4..<7)
delegate.dataGridDidRemoveRows(at: indices)
#expect(applier.removedCalls.count == 1)
#expect(applier.removedCalls.first == indices)
#expect(applier.insertedCalls.isEmpty)
#expect(applier.fullReplaceCount == 0)
}
@Test("dataGridDidReplaceAllRows() forwards to applyFullReplace")
func fullReplaceForwards() {
let delegate = DataTabGridDelegate()
let applier = FakeTableViewCoordinator()
delegate.tableViewCoordinator = applier
delegate.dataGridDidReplaceAllRows()
#expect(applier.fullReplaceCount == 1)
#expect(applier.insertedCalls.isEmpty)
#expect(applier.removedCalls.isEmpty)
}
@Test("Calls are no-ops when tableViewCoordinator is nil")
func nilCoordinatorIsNoOp() {
let delegate = DataTabGridDelegate()
#expect(delegate.tableViewCoordinator == nil)
delegate.dataGridDidInsertRows(at: IndexSet([0]))
delegate.dataGridDidRemoveRows(at: IndexSet([0]))
delegate.dataGridDidReplaceAllRows()
}
}