Skip to content

Commit

Permalink
Add more unit tests for #117
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesquires committed Jul 13, 2024
1 parent 9623761 commit c2ab085
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
30 changes: 24 additions & 6 deletions Tests/TestCellViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ final class TestCellViewModel: XCTestCase {
XCTAssertEqual(viewModel.registration, expected)
}

// swiftlint:disable xct_specific_matcher
@MainActor
func test_eraseToAnyViewModel() {
var viewModel = FakeTextCellViewModel()
Expand All @@ -55,8 +56,6 @@ final class TestCellViewModel: XCTestCase {
XCTAssertEqual(erased.registration, viewModel.registration)
XCTAssertEqual(erased.shouldHighlight, viewModel.shouldHighlight)
XCTAssertIdentical(erased.contextMenuConfiguration, viewModel.contextMenuConfiguration)

// swiftlint:disable:next xct_specific_matcher
XCTAssertTrue(erased.cellClass == viewModel.cellClass)
XCTAssertEqual(erased.reuseIdentifier, viewModel.reuseIdentifier)

Expand All @@ -76,12 +75,30 @@ final class TestCellViewModel: XCTestCase {
XCTAssertNotEqual(erased.hashValue, FakeCellViewModel().eraseToAnyViewModel().hashValue)

let erased3 = viewModel.eraseToAnyViewModel().eraseToAnyViewModel()
XCTAssertEqual(erased, erased3)
XCTAssertEqual(erased.hashValue, erased3.hashValue)
XCTAssertEqual(erased3, erased)
XCTAssertEqual(erased3.hashValue, erased.hashValue)

XCTAssertEqual(erased3, viewModel.eraseToAnyViewModel())
XCTAssertEqual(erased3.hashValue, viewModel.hashValue)
XCTAssertEqual(erased3.id, viewModel.id)
XCTAssertEqual(erased3.registration, viewModel.registration)
XCTAssertEqual(erased3.shouldHighlight, viewModel.shouldHighlight)
XCTAssertIdentical(erased3.contextMenuConfiguration, viewModel.contextMenuConfiguration)
XCTAssertTrue(erased3.cellClass == viewModel.cellClass)
XCTAssertEqual(erased3.reuseIdentifier, viewModel.reuseIdentifier)

let erased4 = (viewModel.eraseToAnyViewModel() as (any CellViewModel)).eraseToAnyViewModel()
XCTAssertEqual(erased, erased4)
XCTAssertEqual(erased.hashValue, erased4.hashValue)
XCTAssertEqual(erased4, erased)
XCTAssertEqual(erased4.hashValue, erased.hashValue)

XCTAssertEqual(erased4, viewModel.eraseToAnyViewModel())
XCTAssertEqual(erased4.hashValue, viewModel.hashValue)
XCTAssertEqual(erased4.id, viewModel.id)
XCTAssertEqual(erased4.registration, viewModel.registration)
XCTAssertEqual(erased4.shouldHighlight, viewModel.shouldHighlight)
XCTAssertIdentical(erased4.contextMenuConfiguration, viewModel.contextMenuConfiguration)
XCTAssertTrue(erased4.cellClass == viewModel.cellClass)
XCTAssertEqual(erased4.reuseIdentifier, viewModel.reuseIdentifier)

let anyViewModel5 = AnyCellViewModel(erased2)
XCTAssertEqual(erased, anyViewModel5)
Expand All @@ -95,6 +112,7 @@ final class TestCellViewModel: XCTestCase {
XCTAssertEqual(erased, anyViewModel7)
XCTAssertEqual(erased.hashValue, anyViewModel7.hashValue)
}
// swiftlint:enable xct_specific_matcher

@MainActor
func test_debugDescription() {
Expand Down
25 changes: 17 additions & 8 deletions Tests/TestSupplementaryViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,17 @@ final class TestSupplementaryViewModel: XCTestCase {
XCTAssertEqual(viewModel.reuseIdentifier, "FakeSupplementaryViewModel")
}

// swiftlint:disable xct_specific_matcher
@MainActor
func test_eraseToAnyViewModel() {
var viewModel = FakeSupplementaryViewModel()
viewModel.expectationConfigureView = self.expectation(name: "configure_view")
viewModel.expectationConfigureView?.expectedFulfillmentCount = 2

let erased = viewModel.eraseToAnyViewModel()
XCTAssertEqual(viewModel.hashValue, erased.hashValue)

XCTAssertEqual(erased.id, viewModel.id)
XCTAssertEqual(erased.hashValue, viewModel.hashValue)
XCTAssertEqual(erased.registration, viewModel.registration)

// swiftlint:disable:next xct_specific_matcher
XCTAssertTrue(erased.viewClass == viewModel.viewClass)
XCTAssertEqual(erased.reuseIdentifier, viewModel.reuseIdentifier)

Expand All @@ -52,12 +50,22 @@ final class TestSupplementaryViewModel: XCTestCase {
XCTAssertNotEqual(erased.hashValue, FakeSupplementaryViewModel().eraseToAnyViewModel().hashValue)

let erased3 = viewModel.eraseToAnyViewModel().eraseToAnyViewModel()
XCTAssertEqual(erased, erased3)
XCTAssertEqual(erased.hashValue, erased3.hashValue)
XCTAssertEqual(erased3, erased)
XCTAssertEqual(erased3.hashValue, erased.hashValue)
XCTAssertEqual(erased3.id, viewModel.id)
XCTAssertEqual(erased3.hashValue, viewModel.hashValue)
XCTAssertEqual(erased3.registration, viewModel.registration)
XCTAssertTrue(erased3.viewClass == viewModel.viewClass)
XCTAssertEqual(erased3.reuseIdentifier, viewModel.reuseIdentifier)

let erased4 = (viewModel.eraseToAnyViewModel() as (any SupplementaryViewModel)).eraseToAnyViewModel()
XCTAssertEqual(erased, erased4)
XCTAssertEqual(erased.hashValue, erased4.hashValue)
XCTAssertEqual(erased4, erased)
XCTAssertEqual(erased4.hashValue, erased.hashValue)
XCTAssertEqual(erased4.id, viewModel.id)
XCTAssertEqual(erased4.hashValue, viewModel.hashValue)
XCTAssertEqual(erased4.registration, viewModel.registration)
XCTAssertTrue(erased4.viewClass == viewModel.viewClass)
XCTAssertEqual(erased4.reuseIdentifier, viewModel.reuseIdentifier)

let anyViewModel5 = AnySupplementaryViewModel(erased2)
XCTAssertEqual(erased, anyViewModel5)
Expand All @@ -71,6 +79,7 @@ final class TestSupplementaryViewModel: XCTestCase {
XCTAssertEqual(erased, anyViewModel7)
XCTAssertEqual(erased.hashValue, anyViewModel7.hashValue)
}
// swiftlint:enable xct_specific_matcher

@MainActor
func test_header() {
Expand Down

0 comments on commit c2ab085

Please sign in to comment.