Skip to content

Commit

Permalink
Update test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Jan 13, 2025
1 parent 41b575c commit c40679f
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
// ID: FAF0B683EB49BE9BABC9009857940A1E

#if os(iOS)
@_spi(ForOpenSwiftUIOnly) public import OpenSwiftUICore
@_spi(ForOpenSwiftUIOnly)
@_spi(Private)
public import OpenSwiftUICore
public import UIKit

@available(macOS, unavailable)
Expand Down
3 changes: 3 additions & 0 deletions Sources/OpenSwiftUI/Test/TestApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// Status: WIP
// ID: A519B5B95CA8FF4E3445832668F0B2D2

@_spi(Testing)
import OpenSwiftUICore

public struct _TestApp {
public init() {
preconditionFailure("TODO")
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUICore/View/Input/ViewOutputs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct _ViewOutputs {

private var _layoutComputer: OptionalAttribute<LayoutComputer>

init() {
package init() {
preferences = PreferencesOutputs()
_layoutComputer = OptionalAttribute()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// IdentifiedViewProxyTests.swift
// OpenSwiftUICompatibilityTests

import Testing
#if os(iOS)
import UIKit
#endif

@MainActor
struct IdentifiedViewProxyTests {
@Test
func boundingRect() async {
#if os(iOS) && OPENSWIFTUI_COMPATIBILITY_TEST // FIXME: add _identified modifier
let identifier = "Test"
let hosting = UIHostingController(rootView: AnyView(EmptyView())._identified(by: identifier))
await confirmation { @MainActor confirmation in
hosting._forEachIdentifiedView { proxy in
confirmation()
#expect(proxy.identifier == AnyHashable(identifier))
#expect(proxy.boundingRect == .zero)
}
}
#endif
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// IdentifiedViewTreeTests.swift
// OpenSwiftUICompatibilityTests

import Testing

struct IdentifiedViewTreeTests {
@Test
func forEachEmpty() async {
let tree = _IdentifiedViewTree.empty
await confirmation(expectedCount: 0) { confirm in
tree.forEach { _ in
confirm()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// IdentifiedViewTreeTests.swift
// OpenSwiftUITests

import Testing
import OpenSwiftUI
@_spi(ForOpenSwiftUIOnly)
import OpenSwiftUICore
#if os(iOS)
import UIKit
#endif

struct IdentifiedViewTreeTests {
private func helper(identifier: AnyHashable) -> _IdentifiedViewProxy {
return _IdentifiedViewProxy(
identifier: identifier,
size: .zero,
position: .zero,
transform: .init(),
accessibilityNode: nil,
platform: .init(.init(inputs: .invalidInputs(.invalid), outputs: _ViewOutputs()))
)
}

@Test
func forEachProxy() async {
let tree = _IdentifiedViewTree.proxy(helper(identifier: "1"))
await confirmation(expectedCount: 1) { confirm in
tree.forEach { _ in
confirm()
}
}
}

@Test
func forEachArray() async {
let tree = _IdentifiedViewTree.array([
.proxy(helper(identifier: "1")),
.empty,
.array([.proxy(helper(identifier: "2"))])
])
await confirmation(expectedCount: 2) { confirm in
tree.forEach { _ in
confirm()
}
}
}

@Test
func forEachEmpty() async {
let tree = _IdentifiedViewTree.empty
await confirmation(expectedCount: 0) { confirm in
tree.forEach { _ in
confirm()
}
}
}
}

0 comments on commit c40679f

Please sign in to comment.