diff --git a/Tests/ComposableArchitectureTests/UIKit/DiffableDataSourceQueueTests.swift b/Tests/ComposableArchitectureTests/UIKit/DiffableDataSourceQueueTests.swift new file mode 100644 index 000000000000..dbac0a254b86 --- /dev/null +++ b/Tests/ComposableArchitectureTests/UIKit/DiffableDataSourceQueueTests.swift @@ -0,0 +1,40 @@ +#if canImport(UIKit) && !os(watchOS) +import Dispatch +import UIKit +import XCTest + +@testable import ComposableArchitecture + +class CollectionView: UICollectionView { + override func reloadData() { + super.reloadData() + mainActorNow { + XCTAssertTrue(Thread.isMainThread) + } + } +} + +@available(iOS 13.0, *) +final class DiffableDataSourceQueueTests: BaseTCATestCase { + @MainActor + func testDiffableDataSourceWithMainActorNow() async { + let collectionView = CollectionView( + frame: .init(x: 0, y: 0, width: 10, height: 10), + collectionViewLayout: UICollectionViewFlowLayout() + ) + collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "Cell") + + let dataSource = UICollectionViewDiffableDataSource( + collectionView: collectionView + ) { collectionView, indexPath, item in + collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) + } + + var snapshot = NSDiffableDataSourceSnapshot() + snapshot.appendSections([0]) + snapshot.appendItems([1]) + dataSource.apply(snapshot, animatingDifferences: true) + } +} + +#endif