Skip to content

Commit 8db42c2

Browse files
committed
Add tests
1 parent b581a3e commit 8db42c2

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

Sources/AppKit/CocoaCollectionViewDiffableDataSource.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ open class CocoaCollectionViewDiffableDataSource<SectionIdentifierType: Hashable
3535
/// diffing animation.
3636
/// - completion: An optional completion block which is called when the complete
3737
/// performing updates.
38-
public func apply(_ snapshot: DiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType>, animatingDifferences: Bool = true) {
38+
public func apply(_ snapshot: DiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType>, animatingDifferences: Bool = true, completion: (() -> Void)? = nil) {
3939
core.apply(
4040
snapshot,
4141
view: collectionView,

Tests/CocoaCollectionViewDiffableDataSourceTests.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,29 @@ final class CocoaCollectionViewDiffableDataSourceTests: XCTestCase {
2222

2323
var snapshot = DiffableDataSourceSnapshot<Int, Int>()
2424

25-
dataSource.apply(snapshot)
25+
let e1 = expectation(description: "testApply() e1")
26+
dataSource.apply(snapshot, completion: e1.fulfill)
27+
wait(for: [e1], timeout: 1)
2628
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 0)
2729

2830
snapshot.appendSections([0])
2931
snapshot.appendItems([0])
3032

31-
dataSource.apply(snapshot)
33+
let e2 = expectation(description: "testApply() e2")
34+
dataSource.apply(snapshot, completion: e2.fulfill)
35+
wait(for: [e2], timeout: 1)
3236
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 1)
3337

34-
dataSource.apply(snapshot)
38+
let e3 = expectation(description: "testApply() e3")
39+
dataSource.apply(snapshot, completion: e3.fulfill)
40+
wait(for: [e3], timeout: 1)
3541
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 1)
3642

3743
snapshot.appendItems([1])
3844

39-
dataSource.apply(snapshot)
45+
let e4 = expectation(description: "testApply() e4")
46+
dataSource.apply(snapshot, completion: e4.fulfill)
47+
wait(for: [e4], timeout: 1)
4048
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 2)
4149
}
4250

Tests/CollectionViewDiffableDataSourceTests.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,29 @@ final class CollectionViewDiffableDataSourceTests: XCTestCase {
2222

2323
var snapshot = DiffableDataSourceSnapshot<Int, Int>()
2424

25-
dataSource.apply(snapshot)
25+
let e1 = expectation(description: "testApply() e1")
26+
dataSource.apply(snapshot, completion: e1.fulfill)
27+
wait(for: [e1], timeout: 1)
2628
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 0)
2729

2830
snapshot.appendSections([0])
2931
snapshot.appendItems([0])
3032

31-
dataSource.apply(snapshot)
33+
let e2 = expectation(description: "testApply() e2")
34+
dataSource.apply(snapshot, completion: e2.fulfill)
35+
wait(for: [e2], timeout: 1)
3236
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 1)
3337

34-
dataSource.apply(snapshot)
38+
let e3 = expectation(description: "testApply() e3")
39+
dataSource.apply(snapshot, completion: e3.fulfill)
40+
wait(for: [e3], timeout: 1)
3541
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 1)
3642

3743
snapshot.appendItems([1])
3844

39-
dataSource.apply(snapshot)
45+
let e4 = expectation(description: "testApply() e4")
46+
dataSource.apply(snapshot, completion: e4.fulfill)
47+
wait(for: [e4], timeout: 1)
4048
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 2)
4149
}
4250

Tests/TableViewDiffableDataSourceTests.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,29 @@ final class TableViewDiffableDataSourceTests: XCTestCase {
2222

2323
var snapshot = DiffableDataSourceSnapshot<Int, Int>()
2424

25-
dataSource.apply(snapshot)
25+
let e1 = expectation(description: "testApply() e1")
26+
dataSource.apply(snapshot, completion: e1.fulfill)
27+
wait(for: [e1], timeout: 1)
2628
XCTAssertEqual(tableView.isPerformBatchUpdatesCalledCount, 0)
2729

2830
snapshot.appendSections([0])
2931
snapshot.appendItems([0])
3032

31-
dataSource.apply(snapshot)
33+
let e2 = expectation(description: "testApply() e2")
34+
dataSource.apply(snapshot, completion: e2.fulfill)
35+
wait(for: [e2], timeout: 1)
3236
XCTAssertEqual(tableView.isPerformBatchUpdatesCalledCount, 1)
3337

34-
dataSource.apply(snapshot)
38+
let e3 = expectation(description: "testApply() e3")
39+
dataSource.apply(snapshot, completion: e3.fulfill)
40+
wait(for: [e3], timeout: 1)
3541
XCTAssertEqual(tableView.isPerformBatchUpdatesCalledCount, 1)
3642

3743
snapshot.appendItems([1])
3844

39-
dataSource.apply(snapshot)
45+
let e4 = expectation(description: "testApply() e4")
46+
dataSource.apply(snapshot, completion: e4.fulfill)
47+
wait(for: [e4], timeout: 1)
4048
XCTAssertEqual(tableView.isPerformBatchUpdatesCalledCount, 2)
4149
}
4250

0 commit comments

Comments
 (0)