Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenSwiftUI UITest target support #80

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Configurations/Example.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PRODUCT_BUNDLE_IDENTIFIER=org.OpenSwiftUIProject.OpenSwiftUI.Example
1 change: 1 addition & 0 deletions Configurations/HostingExample.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PRODUCT_BUNDLE_IDENTIFIER=org.OpenSwiftUIProject.OpenSwiftUI.HostingExample
1 change: 1 addition & 0 deletions Configurations/OpenSwiftUIUITests.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PRODUCT_BUNDLE_IDENTIFIER=org.OpenSwiftUIProject.OpenSwiftUI.OpenSwiftUIUITests
2 changes: 2 additions & 0 deletions Configurations/Shared/OpenSwiftUI-debug.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "basic/OpenSwiftUI.xcconfig"
#include "basic/debug.xcconfig"
2 changes: 2 additions & 0 deletions Configurations/Shared/OpenSwiftUI-release.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "basic/OpenSwiftUI.xcconfig"
#include "basic/release.xcconfig"
2 changes: 2 additions & 0 deletions Configurations/Shared/SwiftUI-debug.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "basic/SwiftUI.xcconfig"
#include "basic/debug.xcconfig"
2 changes: 2 additions & 0 deletions Configurations/Shared/SwiftUI-release.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "basic/SwiftUI.xcconfig"
#include "basic/release.xcconfig"
2 changes: 2 additions & 0 deletions Configurations/Shared/basic/OpenSwiftUI.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) OPENSWIFTUI=1
SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited) OPENSWIFTUI
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions Configurations/Shared/basic/debug.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) DEBUG=1
SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited) DEBUG
Empty file.
1 change: 1 addition & 0 deletions Configurations/TestHost.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PRODUCT_BUNDLE_IDENTIFIER=org.OpenSwiftUIProject.OpenSwiftUI.TestHost
330 changes: 304 additions & 26 deletions Example/Example.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

105 changes: 0 additions & 105 deletions Tests/OpenSwiftUIUITests/ContentView_FB13341321.swift

This file was deleted.

23 changes: 0 additions & 23 deletions Tests/OpenSwiftUIUITests/LaunchTests.swift

This file was deleted.

20 changes: 0 additions & 20 deletions Tests/OpenSwiftUIUITests/UITests.swift

This file was deleted.

110 changes: 110 additions & 0 deletions TestsHost/OpenSwiftUIUITests/FB13341321.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//
// FB13341321.swift
// Test
//
// Created by Kyle on 2023/11/6.
//

// (4 toggles: C1T1 C1T2 C2T1 C2T2 - C1T1&C2T1 use the same truth, C1T2&C2T2 use the same truth )
// macOS 14 behavior with SwiftUI
// C1T1's UI will only be updated at most 1 time if we only tap T1.
// C2T1 will always reflect the latest value in UI. A tap for T2 will make C1T1's UI up to data.
// Tap on C1T2 or C2T2 will update both toggle at the same time. (Expected)
//
// iOS 17 behavior with SwiftUI
// Tap on C2T1 will only update toggle C2T1 while the UI of C1T1 remains the same.
// Tap on C1T1 will update both toggle(C1T1 & C2T1) at the same time. (Expected)
// Tap on C1T2 or C2T2 will update both toggle at the same time. (Expected)
//
// iOS 15.5 behavior with SwiftUI
// Tap on C1T1 or C2T1 will update both toggle at the same time. (Expected)
// Tap on C1T2 or C2T2 will update both toggle at the same time. (Expected)
// But one is with transactino and the other is not.

import SwiftUI
import Observation

@available(iOS 14, *)
enum FB13341321 {
public struct Section: View {

public let content: AnyView

public init(
@ViewBuilder content: @escaping () -> some View
) {

self.content = content().eraseToAnyView()
}

public var body: some View {
content
}
}

@resultBuilder
public struct SectionBuilder {
public static func buildBlock(_ sections: Section...) -> [Section] {
sections
}
}
public struct Container: View {
private let builder: () -> [Section]

public init(
@SectionBuilder builder: @escaping () -> [Section]
) {
self.builder = builder
}

public var body: some View {
let sections = builder()
return sections[0]
}
}

public struct Container2: View {
private let sections: [Section]

public init(
sections: [Section] = []
) {
self.sections = sections
}

public var body: some View {
return sections[0]
}
}

struct ContentView: View {
@AppStorage("Test") private var toggle = false
@State private var toggle2 = false
var body: some View {
Container {
Section {
Toggle("Demo Toggle", isOn: $toggle)
Toggle("Demo Toggle2", isOn: $toggle2)
}
}
Container2(sections: [
Section {
Toggle("Demo Toggle", isOn: $toggle)
Toggle("Demo Toggle2", isOn: $toggle2)
}
])
}
}
}

extension View {
func eraseToAnyView() -> AnyView {
AnyView(self)
}
}

@available(iOS 14, *)
#Preview {
FB13341321.ContentView()
.padding(20)
}
34 changes: 34 additions & 0 deletions TestsHost/OpenSwiftUIUITests/View/View/AnyViewTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// AnyViewTests.swift
// OpenSwiftUIUITests

import XCTest

#if OPENSWIFTUI
import OpenSwiftUI
#else
import SwiftUI
#endif

#if os(iOS)
import UIKit

#if !OPENSWIFTUI
@available(iOS 15, *)
#endif
final class AnyViewTests: XCTestCase {
// @Test("Attribute setter crash for basic AnyView", .bug("https://github.com/OpenSwiftUIProject/OpenGraph/issues/58", relationship: .verifiesFix))
func testBasicAnyView() throws {
struct ContentView: View {
var body: some View {
AnyView(EmptyView())
}
}
let vc = UIHostingController(rootView: ContentView())
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
window.rootViewController = vc
window.makeKeyAndVisible()
vc.view.layoutSubviews()
}
}
#endif
Loading
Loading