Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CalvinChangCC committed May 22, 2024
1 parent 8fabf99 commit 7df5437
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 82 deletions.
100 changes: 84 additions & 16 deletions SectionKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import UIKit
import XCTest

@MainActor
internal final class ListCollectionViewAdapterUICollectionViewDelegateFlowLayoutTests: BaseCollectionViewAdapterUICollectionViewDelegateFlowLayoutTests {
override internal func createCollectionViewAdapter(
final class ListCollectionViewAdapterUICollectionViewDelegateFlowLayoutTests: BaseCollectionViewAdapterUICollectionViewDelegateFlowLayoutTests {
@MainActor
override func createCollectionViewAdapter(
collectionView: UICollectionView,
sections: [Section] = [],
viewController: UIViewController? = nil,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import SectionKit
import XCTest

internal final class BaseFlowLayoutSectionControllerTests: XCTestCase {
@MainActor
internal func testFlowDelegateIsSelf() {
let sectionController = BaseFlowLayoutSectionController()
XCTAssert(sectionController.flowDelegate === sectionController)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ internal final class BaseSectionControllerTests: XCTestCase {
XCTAssert(sectionController.delegate === sectionController)
}

internal func testFlowDelegateIsSelf() {
let sectionController = BaseSectionController()
XCTAssert(sectionController.flowDelegate === sectionController)
}

@available(iOS 11.0, *)
internal func testDragDelegateIsSelf() {
let sectionController = BaseSectionController()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
import SectionKit
import XCTest

@MainActor
internal final class ProtocolDefaultValuesSectionControllerTests: XCTestCase {
private func createSectionController() -> SectionController {
final class ProtocolDefaultValuesSectionControllerTests: XCTestCase {
private var sut: SectionController!

@MainActor
override func setUp() {
super.setUp()
class DefaultSectionController: SectionController {
var context: CollectionViewContext?
var dataSource: SectionDataSource = MockSectionDataSource()
func didUpdate(model: Any) { }
}
return DefaultSectionController()
sut = DefaultSectionController()
}

@available(iOS 10.0, *)
internal func testDataSourcePrefetchingDelegateIsNil() {
let sectionController = createSectionController()
XCTAssertNil(sectionController.dataSourcePrefetchingDelegate)
override func tearDown() {
sut = nil
super.tearDown()
}

internal func testDelegateIsNil() {
let sectionController = createSectionController()
XCTAssertNil(sectionController.delegate)
@MainActor
@available(iOS 10.0, *)
func testDataSourcePrefetchingDelegateIsNil() {
XCTAssertNil(sut.dataSourcePrefetchingDelegate)
}

internal func testFlowDelegateIsNil() {
let sectionController = createSectionController()
XCTAssertNil(sectionController.flowDelegate)
@MainActor
func testDelegateIsNil() {
XCTAssertNil(sut.delegate)
}

@MainActor
@available(iOS 11.0, *)
internal func testDragDelegateIsNil() {
let sectionController = createSectionController()
XCTAssertNil(sectionController.dragDelegate)
func testDragDelegateIsNil() {
XCTAssertNil(sut.dragDelegate)
}

@MainActor
@available(iOS 11.0, *)
internal func testDropDelegateIsNil() {
let sectionController = createSectionController()
XCTAssertNil(sectionController.dropDelegate)
func testDropDelegateIsNil() {
XCTAssertNil(sut.dropDelegate)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@testable import SectionKit
import XCTest

final class BaseCompositionalLayoutSectionControllerTests: XCTestCase {
final class TestLayoutEnvironment: NSObject, NSCollectionLayoutEnvironment {
final class TestLayoutContainer: NSObject, NSCollectionLayoutContainer {
let contentSize: CGSize = .zero
let effectiveContentSize: CGSize = .zero
let contentInsets: NSDirectionalEdgeInsets = .zero
let effectiveContentInsets: NSDirectionalEdgeInsets = .zero
}
let container: NSCollectionLayoutContainer = TestLayoutContainer()
let traitCollection: UITraitCollection = .current
}

@MainActor
func test_layout_isEmpty() {
let sut = BaseCompositionalLayoutSectionController()
let layoutSection = sut.layoutSection(
layoutEnvironment: TestLayoutEnvironment()
)
XCTAssertEqual(layoutSection, .empty)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import SectionKit
import XCTest

internal final class BaseFlowLayoutSectionControllerSectionFlowDelegateTests: BaseFlowLayoutSectionFlowDelegateTests {
@MainActor
override func createSectionFlowDelegate() throws -> SectionFlowDelegate {
BaseFlowLayoutSectionController()
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import SectionKit
import XCTest

@MainActor
internal class BaseSectionFlowDelegateTests: XCTestCase {
internal class BaseFlowLayoutSectionFlowDelegateTests: XCTestCase {
override func setUpWithError() throws {
try super.setUpWithError()
continueAfterFailure = false
try skipIfNeeded()
}

internal func skipIfNeeded() throws {
guard Self.self === BaseSectionFlowDelegateTests.self else { return }
guard Self.self === BaseFlowLayoutSectionFlowDelegateTests.self else { return }
throw XCTSkip("Tests from base class are skipped")
}

@MainActor
internal func createSectionFlowDelegate() throws -> SectionFlowDelegate {
throw XCTSkip("Tests from base class are skipped")
}

@MainActor
internal func testSizeForItemWithFlowLayout() throws {
let sectionFlowDelegate = try createSectionFlowDelegate()
let context = MainCollectionViewContext(
Expand All @@ -39,6 +40,7 @@ internal class BaseSectionFlowDelegateTests: XCTestCase {
)
}

@MainActor
internal func testSizeForItemWithoutFlowLayout() throws {
let sectionFlowDelegate = try createSectionFlowDelegate()
let context = MainCollectionViewContext(
Expand All @@ -58,6 +60,7 @@ internal class BaseSectionFlowDelegateTests: XCTestCase {
)
}

@MainActor
internal func testInsetWithFlowLayout() throws {
let sectionFlowDelegate = try createSectionFlowDelegate()
let context = MainCollectionViewContext(
Expand All @@ -77,6 +80,7 @@ internal class BaseSectionFlowDelegateTests: XCTestCase {
)
}

@MainActor
internal func testInsetWithoutFlowLayout() throws {
let sectionFlowDelegate = try createSectionFlowDelegate()
let context = MainCollectionViewContext(
Expand All @@ -94,6 +98,7 @@ internal class BaseSectionFlowDelegateTests: XCTestCase {
)
}

@MainActor
internal func testMinimumLineSpacingWithFlowLayout() throws {
let sectionFlowDelegate = try createSectionFlowDelegate()
let context = MainCollectionViewContext(
Expand All @@ -112,6 +117,7 @@ internal class BaseSectionFlowDelegateTests: XCTestCase {
)
}

@MainActor
internal func testMinimumLineSpacingWithoutFlowLayout() throws {
let sectionFlowDelegate = try createSectionFlowDelegate()
let context = MainCollectionViewContext(
Expand All @@ -129,6 +135,7 @@ internal class BaseSectionFlowDelegateTests: XCTestCase {
)
}

@MainActor
internal func testMinimumInteritemSpacingWithFlowLayout() throws {
let sectionFlowDelegate = try createSectionFlowDelegate()
let context = MainCollectionViewContext(
Expand All @@ -147,6 +154,7 @@ internal class BaseSectionFlowDelegateTests: XCTestCase {
)
}

@MainActor
internal func testMinimumInteritemSpacingWithoutFlowLayout() throws {
let sectionFlowDelegate = try createSectionFlowDelegate()
let context = MainCollectionViewContext(
Expand All @@ -164,6 +172,7 @@ internal class BaseSectionFlowDelegateTests: XCTestCase {
)
}

@MainActor
internal func testReferenceSizeForHeaderWithFlowLayout() throws {
let sectionFlowDelegate = try createSectionFlowDelegate()
let context = MainCollectionViewContext(
Expand All @@ -183,6 +192,7 @@ internal class BaseSectionFlowDelegateTests: XCTestCase {
)
}

@MainActor
internal func testReferenceSizeForHeaderWithoutFlowLayout() throws {
let sectionFlowDelegate = try createSectionFlowDelegate()
let context = MainCollectionViewContext(
Expand All @@ -200,6 +210,7 @@ internal class BaseSectionFlowDelegateTests: XCTestCase {
)
}

@MainActor
internal func testReferenceSizeForFooterWithFlowLayout() throws {
let sectionFlowDelegate = try createSectionFlowDelegate()
let context = MainCollectionViewContext(
Expand All @@ -219,6 +230,7 @@ internal class BaseSectionFlowDelegateTests: XCTestCase {
)
}

@MainActor
internal func testReferenceSizeForFooterWithoutFlowLayout() throws {
let sectionFlowDelegate = try createSectionFlowDelegate()
let context = MainCollectionViewContext(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SectionKit
import XCTest

@MainActor
internal final class ProtocolDefaultValuesSectionFlowDelegateTests: BaseSectionFlowDelegateTests {
internal final class ProtocolDefaultValuesSectionFlowDelegateTests: BaseFlowLayoutSectionFlowDelegateTests {
override func createSectionFlowDelegate() throws -> SectionFlowDelegate {
class DefaultSectionFlowDelegate: SectionFlowDelegate { }
return DefaultSectionFlowDelegate()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import SectionKit
import XCTest

final class MockFlowLayoutSectionController: MockSectionController,
FlowLayoutSectionController {
lazy var flowDelegate: SectionFlowDelegate? = {
XCTFail("flow delegate is not set")
return nil
}()
}
5 changes: 0 additions & 5 deletions SectionKit/Tests/TestUtilities/MockSectionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ internal class MockSectionController: SectionController {
return nil
}()

internal lazy var flowDelegate: SectionFlowDelegate? = {
XCTFail("flow delegate is not set")
return nil
}()

@available(iOS 11.0, *)
internal lazy var dragDelegate: SectionDragDelegate? = {
XCTFail("dragDelegate is not set")
Expand Down

0 comments on commit 7df5437

Please sign in to comment.