Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesquires committed Jul 1, 2024
1 parent 8bafb25 commit de04f16
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ReactiveCollectionsKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
0BA0E2D42C030AC7001FB5AA /* TestViewRegistrationViewType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BA0E2D32C030AC7001FB5AA /* TestViewRegistrationViewType.swift */; };
0BBB8A442C31F09D00200477 /* FakeEmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BBB8A432C31F09D00200477 /* FakeEmptyView.swift */; };
0BBB8A462C31F56000200477 /* FakeCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BBB8A452C31F56000200477 /* FakeCollectionViewController.swift */; };
0BBB8A492C32309800200477 /* TestCollectionViewDriverReconfigure.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BBB8A482C32309800200477 /* TestCollectionViewDriverReconfigure.swift */; };
0BC1EC28267FC37200FF774F /* SupplementaryHeaderViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BC1EC27267FC37200FF774F /* SupplementaryHeaderViewModel.swift */; };
0BC1EC2A267FC3A000FF774F /* SupplementaryFooterViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BC1EC29267FC3A000FF774F /* SupplementaryFooterViewModel.swift */; };
0BC1EC2C267FE71900FF774F /* ViewRegistrationProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BC1EC2B267FE71900FF774F /* ViewRegistrationProvider.swift */; };
Expand Down Expand Up @@ -93,6 +94,7 @@
0BA0E2D32C030AC7001FB5AA /* TestViewRegistrationViewType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestViewRegistrationViewType.swift; sourceTree = "<group>"; };
0BBB8A432C31F09D00200477 /* FakeEmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FakeEmptyView.swift; sourceTree = "<group>"; };
0BBB8A452C31F56000200477 /* FakeCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FakeCollectionViewController.swift; sourceTree = "<group>"; };
0BBB8A482C32309800200477 /* TestCollectionViewDriverReconfigure.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestCollectionViewDriverReconfigure.swift; sourceTree = "<group>"; };
0BC1EC27267FC37200FF774F /* SupplementaryHeaderViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupplementaryHeaderViewModel.swift; sourceTree = "<group>"; };
0BC1EC29267FC3A000FF774F /* SupplementaryFooterViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupplementaryFooterViewModel.swift; sourceTree = "<group>"; };
0BC1EC2B267FE71900FF774F /* ViewRegistrationProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewRegistrationProvider.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -244,6 +246,7 @@
0BA0E2C92C0303DC001FB5AA /* TestCollectionExtensions.swift */,
8872DE94238D18D5005774EA /* TestCollectionViewDriver.swift */,
0BA0E2CB2C030445001FB5AA /* TestCollectionViewDriverOptions.swift */,
0BBB8A482C32309800200477 /* TestCollectionViewDriverReconfigure.swift */,
0B7A18EB2C2A17A700E59C35 /* TestCollectionViewModel.swift */,
0B0433252C2FE25C0083C8DB /* TestDiffableSnapshot.swift */,
0BA0E2CD2C0304B4001FB5AA /* TestEmptyView.swift */,
Expand Down Expand Up @@ -435,6 +438,7 @@
0BA0E2D22C030849001FB5AA /* TestViewRegistrationMethod.swift in Sources */,
0B8F50452C2B46A20081C0D2 /* TestBundle.swift in Sources */,
0BA0E2CC2C030445001FB5AA /* TestCollectionViewDriverOptions.swift in Sources */,
0BBB8A492C32309800200477 /* TestCollectionViewDriverReconfigure.swift in Sources */,
0BFBB2EC2C0BFD1B000842B6 /* FakeCellEventCoordinator.swift in Sources */,
0BFA774C2BB8B717009B9C5B /* FakeCellViewModel.swift in Sources */,
0B7A18F32C2A4E4500E59C35 /* FakeSupplementaryNibView.swift in Sources */,
Expand Down
69 changes: 69 additions & 0 deletions Tests/TestCollectionViewDriverReconfigure.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// Created by Jesse Squires
// https://www.jessesquires.com
//
// Documentation
// https://jessesquires.github.io/ReactiveCollectionsKit
//
// GitHub
// https://github.com/jessesquires/ReactiveCollectionsKit
//
// Copyright © 2019-present Jesse Squires
//

import Foundation
@testable import ReactiveCollectionsKit
import XCTest

final class TestCollectionViewDriverReconfigure: UnitTestCase {

@MainActor
func test_reconfigure_item() async {
var uniqueCell = MyStaticCellViewModel(name: "initial")
uniqueCell.expectation = self.expectation(name: "initial_configure")

let numberCells = (1...5).map { _ in
var viewModel = FakeNumberCellViewModel()
viewModel.expectationConfigureCell = self.expectation(name: "configure_cell_\(viewModel.id)")
return viewModel
}

let section1 = SectionViewModel(id: "one", cells: numberCells)
let section2 = SectionViewModel(id: "two", cells: [uniqueCell])
let section3 = self.fakeSectionViewModel(id: "three")
let model = CollectionViewModel(id: "id", sections: [section1, section2, section3])

let viewController = FakeCollectionViewController()
let driver = CollectionViewDriver(view: viewController.collectionView, viewModel: model)
self.simulateAppearance(viewController: viewController)
self.waitForExpectations()

// Update one cell to be reconfigured
uniqueCell = MyStaticCellViewModel(name: "updated")
uniqueCell.expectation = self.expectation(name: "updated_configure")
let updatedSection = SectionViewModel(id: "two", cells: [uniqueCell])
let updatedModel = CollectionViewModel(id: "id", sections: [section1, updatedSection])
await driver.update(viewModel: updatedModel)
self.waitForExpectations()

self.keepDriverAlive(driver)
}
}

private struct MyStaticCellViewModel: CellViewModel {
let id: UniqueIdentifier = "MyCellViewModel"
let name: String

var expectation: XCTestExpectation?
func configure(cell: FakeCollectionCell) {
expectation?.fulfillAndLog()
}

nonisolated static func == (left: Self, right: Self) -> Bool {
left.name == right.name
}

nonisolated func hash(into hasher: inout Hasher) {
hasher.combine(self.name)
}
}

0 comments on commit de04f16

Please sign in to comment.