Skip to content

Commit

Permalink
fix: adapter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
s2mr committed Nov 1, 2023
1 parent 4bfac18 commit f01f801
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
14 changes: 12 additions & 2 deletions Sources/SwiftUISupport/ComponentSwiftUISupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,18 @@ private struct ComponentRepresenting<C: Component>: UIViewRepresentable {
}

@available(iOS 16.0, *)
func sizeThatFits(_ proposal: ProposedViewSize, uiView: UIComponentView, context: Context) -> CGSize? {
uiView.intrinsicContentSize
func sizeThatFits(
_ proposal: ProposedViewSize,
uiView: UIComponentView,
context: Context
) -> CGSize? {
if let width = proposal.width {
uiView.bounds.width = width
}
if let height = proposal.height {
uiView.bounds.height = height
}
return uiView.intrinsicContentSize
}
}

Expand Down
30 changes: 15 additions & 15 deletions Tests/Adapters/UITableViewAdapterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import XCTest

final class UITableViewAdapterTests: XCTestCase {
func testNumberOfSections() {
let adapter = UITableViewAdapter()
let adapter = UITableViewAdapter(data: [])
adapter.data = [
Section(id: TestID.a),
Section(id: TestID.b),
Expand All @@ -14,7 +14,7 @@ final class UITableViewAdapterTests: XCTestCase {
}

func testNumberOfRowsInSection() {
let adapter = UITableViewAdapter()
let adapter = UITableViewAdapter(data: [])
adapter.data = [
Section(
id: TestID.a,
Expand All @@ -36,7 +36,7 @@ final class UITableViewAdapterTests: XCTestCase {
}

func testCellForRow() {
let adapter = UITableViewAdapter()
let adapter = UITableViewAdapter(data: [])
let component = A.Component()
adapter.data = [
Section(
Expand All @@ -61,7 +61,7 @@ final class UITableViewAdapterTests: XCTestCase {
}

func testViewForHeader() {
let adapter = UITableViewAdapter()
let adapter = UITableViewAdapter(data: [])
let component = A.Component()
adapter.data = [
Section(
Expand All @@ -86,7 +86,7 @@ final class UITableViewAdapterTests: XCTestCase {
}

func testViewForFooter() {
let adapter = UITableViewAdapter()
let adapter = UITableViewAdapter(data: [])
let component = A.Component()
adapter.data = [
Section(
Expand All @@ -111,7 +111,7 @@ final class UITableViewAdapterTests: XCTestCase {
}

func testHeightForRow() {
let adapter = UITableViewAdapter()
let adapter = UITableViewAdapter(data: [])
let tableView = UITableView()
let referenceSize = CGSize(width: 100, height: 200)
let defaultHeight: CGFloat = 300
Expand All @@ -135,7 +135,7 @@ final class UITableViewAdapterTests: XCTestCase {
}

func testEstimatedHeightForRow() {
let adapter = UITableViewAdapter()
let adapter = UITableViewAdapter(data: [])
let tableView = UITableView()
let referenceSize = CGSize(width: 100, height: 200)
let defaultHeight: CGFloat = 300
Expand All @@ -159,7 +159,7 @@ final class UITableViewAdapterTests: XCTestCase {
}

func testHeightForHeader() {
let adapter = UITableViewAdapter()
let adapter = UITableViewAdapter(data: [])
let tableView = UITableView()
let referenceSize = CGSize(width: 100, height: 200)
let defaultHeight: CGFloat = 300
Expand All @@ -181,7 +181,7 @@ final class UITableViewAdapterTests: XCTestCase {
}

func testEstimatedHeightForHeader() {
let adapter = UITableViewAdapter()
let adapter = UITableViewAdapter(data: [])
let tableView = UITableView()
let referenceSize = CGSize(width: 100, height: 200)
let defaultHeight: CGFloat = 300
Expand All @@ -203,7 +203,7 @@ final class UITableViewAdapterTests: XCTestCase {
}

func testHeightForFooter() {
let adapter = UITableViewAdapter()
let adapter = UITableViewAdapter(data: [])
let tableView = UITableView()
let referenceSize = CGSize(width: 100, height: 200)
let defaultHeight: CGFloat = 300
Expand All @@ -225,7 +225,7 @@ final class UITableViewAdapterTests: XCTestCase {
}

func testEstimatedHeightForFooter() {
let adapter = UITableViewAdapter()
let adapter = UITableViewAdapter(data: [])
let tableView = UITableView()
let referenceSize = CGSize(width: 100, height: 200)
let defaultHeight: CGFloat = 300
Expand All @@ -247,7 +247,7 @@ final class UITableViewAdapterTests: XCTestCase {
}

func testDidSelect() {
let adapter = UITableViewAdapter()
let adapter = UITableViewAdapter(data: [])
let tableView = UITableView()
let indexPath = IndexPath(row: 0, section: 0)
let node = CellNode(MockIdentifiableComponent(id: TestID.a))
Expand All @@ -274,7 +274,7 @@ final class UITableViewAdapterTests: XCTestCase {
}

func testDisplaying() {
let adapter = UITableViewAdapter()
let adapter = UITableViewAdapter(data: [])
let tableView = UITableView()
let headerComponent = MockComponent()
let cellComponent = MockIdentifiableComponent(id: TestID.a)
Expand Down Expand Up @@ -309,7 +309,7 @@ final class UITableViewAdapterTests: XCTestCase {
}

func testCustomCell() {
let adapter = MockCustomTableViewAdapter()
let adapter = MockCustomTableViewAdapter(data: [])
let component = A.Component()
adapter.data = [
Section(
Expand Down Expand Up @@ -346,7 +346,7 @@ final class UITableViewAdapterTests: XCTestCase {
}

func testViewForHeaderFooter() {
let adapter = MockCustomTableViewAdapter()
let adapter = MockCustomTableViewAdapter(data: [])
let component = A.Component()
adapter.data = [
Section(
Expand Down
4 changes: 2 additions & 2 deletions Tests/Updater/UITableViewReloadDataUpdaterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DifferenceKit
final class UITableViewReloadDataUpdaterTests: XCTestCase {
func testPrepare() {
let updater = MockTableViewReloadDataUpdater()
let adapter = MockTableViewAdapter()
let adapter = MockTableViewAdapter(data: [])
let tableView = MockTableView()
updater.prepare(target: tableView, adapter: adapter)

Expand All @@ -16,7 +16,7 @@ final class UITableViewReloadDataUpdaterTests: XCTestCase {

func testPerformUpdates() {
let updater = MockTableViewReloadDataUpdater()
let adapter = MockTableViewAdapter()
let adapter = MockTableViewAdapter(data: [])
let tableView = MockTableView()

updater.performUpdates(target: tableView, adapter: adapter, data: [Section(id: TestID.a)])
Expand Down
12 changes: 6 additions & 6 deletions Tests/Updater/UITableViewUpdaterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class UITableViewUpdaterTests: XCTestCase {

func testPrepare() {
let updater = MockTableViewUpdater()
let adapter = MockTableViewAdapter()
let adapter = MockTableViewAdapter(data: [])
let tableView = MockTableView()
updater.prepare(target: tableView, adapter: adapter)

Expand All @@ -28,7 +28,7 @@ final class UITableViewUpdaterTests: XCTestCase {

func testReloadDataFallbackIfNotInViewHierarchy() {
let updater = MockTableViewUpdater()
let adapter = MockTableViewAdapter()
let adapter = MockTableViewAdapter(data: [])
let tableView = MockTableView()

performAsyncTests(
Expand All @@ -44,7 +44,7 @@ final class UITableViewUpdaterTests: XCTestCase {

func testReloadDataFallbackIfOverAnimatableChangeCount() {
let updater = MockTableViewUpdater()
let adapter = MockTableViewAdapter()
let adapter = MockTableViewAdapter(data: [])
let tableView = MockTableView().addingToWindow()
let sourceData = [
Section(id: 0)
Expand All @@ -71,7 +71,7 @@ final class UITableViewUpdaterTests: XCTestCase {

func testNopAndCompletion() {
let updater = MockTableViewUpdater()
let adapter = MockTableViewAdapter()
let adapter = MockTableViewAdapter(data: [])
let tableView = MockTableView().addingToWindow()
let data = [Section(id: TestID.a)]

Expand All @@ -91,7 +91,7 @@ final class UITableViewUpdaterTests: XCTestCase {

func testDifferentialUpdates() {
let updater = MockTableViewUpdater()
let adapter = MockTableViewAdapter()
let adapter = MockTableViewAdapter(data: [])
let tableView = MockTableView().addingToWindow()

// Rendering visible components is no needed in this test.
Expand Down Expand Up @@ -123,7 +123,7 @@ final class UITableViewUpdaterTests: XCTestCase {

func testAlwaysRenderVisibleComponents() {
let updater = MockTableViewUpdater()
let adapter = MockTableViewAdapter()
let adapter = MockTableViewAdapter(data: [])
let tableView = MockTableView().addingToWindow()

let visible = (
Expand Down

0 comments on commit f01f801

Please sign in to comment.