Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ra1028 committed Dec 10, 2019
1 parent b581a3e commit 8db42c2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Sources/AppKit/CocoaCollectionViewDiffableDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ open class CocoaCollectionViewDiffableDataSource<SectionIdentifierType: Hashable
/// diffing animation.
/// - completion: An optional completion block which is called when the complete
/// performing updates.
public func apply(_ snapshot: DiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType>, animatingDifferences: Bool = true) {
public func apply(_ snapshot: DiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType>, animatingDifferences: Bool = true, completion: (() -> Void)? = nil) {
core.apply(
snapshot,
view: collectionView,
Expand Down
16 changes: 12 additions & 4 deletions Tests/CocoaCollectionViewDiffableDataSourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,29 @@ final class CocoaCollectionViewDiffableDataSourceTests: XCTestCase {

var snapshot = DiffableDataSourceSnapshot<Int, Int>()

dataSource.apply(snapshot)
let e1 = expectation(description: "testApply() e1")
dataSource.apply(snapshot, completion: e1.fulfill)
wait(for: [e1], timeout: 1)
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 0)

snapshot.appendSections([0])
snapshot.appendItems([0])

dataSource.apply(snapshot)
let e2 = expectation(description: "testApply() e2")
dataSource.apply(snapshot, completion: e2.fulfill)
wait(for: [e2], timeout: 1)
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 1)

dataSource.apply(snapshot)
let e3 = expectation(description: "testApply() e3")
dataSource.apply(snapshot, completion: e3.fulfill)
wait(for: [e3], timeout: 1)
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 1)

snapshot.appendItems([1])

dataSource.apply(snapshot)
let e4 = expectation(description: "testApply() e4")
dataSource.apply(snapshot, completion: e4.fulfill)
wait(for: [e4], timeout: 1)
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 2)
}

Expand Down
16 changes: 12 additions & 4 deletions Tests/CollectionViewDiffableDataSourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,29 @@ final class CollectionViewDiffableDataSourceTests: XCTestCase {

var snapshot = DiffableDataSourceSnapshot<Int, Int>()

dataSource.apply(snapshot)
let e1 = expectation(description: "testApply() e1")
dataSource.apply(snapshot, completion: e1.fulfill)
wait(for: [e1], timeout: 1)
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 0)

snapshot.appendSections([0])
snapshot.appendItems([0])

dataSource.apply(snapshot)
let e2 = expectation(description: "testApply() e2")
dataSource.apply(snapshot, completion: e2.fulfill)
wait(for: [e2], timeout: 1)
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 1)

dataSource.apply(snapshot)
let e3 = expectation(description: "testApply() e3")
dataSource.apply(snapshot, completion: e3.fulfill)
wait(for: [e3], timeout: 1)
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 1)

snapshot.appendItems([1])

dataSource.apply(snapshot)
let e4 = expectation(description: "testApply() e4")
dataSource.apply(snapshot, completion: e4.fulfill)
wait(for: [e4], timeout: 1)
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 2)
}

Expand Down
16 changes: 12 additions & 4 deletions Tests/TableViewDiffableDataSourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,29 @@ final class TableViewDiffableDataSourceTests: XCTestCase {

var snapshot = DiffableDataSourceSnapshot<Int, Int>()

dataSource.apply(snapshot)
let e1 = expectation(description: "testApply() e1")
dataSource.apply(snapshot, completion: e1.fulfill)
wait(for: [e1], timeout: 1)
XCTAssertEqual(tableView.isPerformBatchUpdatesCalledCount, 0)

snapshot.appendSections([0])
snapshot.appendItems([0])

dataSource.apply(snapshot)
let e2 = expectation(description: "testApply() e2")
dataSource.apply(snapshot, completion: e2.fulfill)
wait(for: [e2], timeout: 1)
XCTAssertEqual(tableView.isPerformBatchUpdatesCalledCount, 1)

dataSource.apply(snapshot)
let e3 = expectation(description: "testApply() e3")
dataSource.apply(snapshot, completion: e3.fulfill)
wait(for: [e3], timeout: 1)
XCTAssertEqual(tableView.isPerformBatchUpdatesCalledCount, 1)

snapshot.appendItems([1])

dataSource.apply(snapshot)
let e4 = expectation(description: "testApply() e4")
dataSource.apply(snapshot, completion: e4.fulfill)
wait(for: [e4], timeout: 1)
XCTAssertEqual(tableView.isPerformBatchUpdatesCalledCount, 2)
}

Expand Down

0 comments on commit 8db42c2

Please sign in to comment.