Skip to content

Commit

Permalink
Merge branch '0.8.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Naumov committed Jun 17, 2021
2 parents 46c4c00 + bf86a47 commit a9b0d2a
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The library provides helpers for writing asynchronous tests for views with callb

### Which views and modifiers are supported?

Check out the [API coverage](readiness.md). There is currently almost full support for SwiftUI 1.0 API, the 2.0 support is under active development.
Check out the [API coverage](readiness.md). There is currently almost full support for SwiftUI v1 API, the v2 and v3 support is under active development.

### Is it using private APIs?

Expand Down
2 changes: 1 addition & 1 deletion Sources/ViewInspector/SwiftUI/Alert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal extension Content {
throw InspectionError.notSupported(
"""
Please refer to the Guide for inspecting the Alert: \
https://github.com/nalexn/ViewInspector/blob/master/guide.md#alert
https://github.com/nalexn/ViewInspector/blob/master/guide.md#alert-sheet-and-actionsheet
""")
}
let alert = try alertBuilder.buildAlert()
Expand Down
6 changes: 3 additions & 3 deletions Sources/ViewInspector/SwiftUI/MapAnnotation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public extension ViewType {

@available(iOS 14.0, tvOS 14.0, macOS 11.0, *)
public extension ViewType.MapAnnotation {
enum `Type`: String {
enum ViewType: String {
case pin
case marker
case custom
Expand All @@ -31,11 +31,11 @@ public extension InspectableView where View == ViewType.MapAnnotation {
label: "coordinate", value: content.view, type: CLLocationCoordinate2D.self)
}

var viewType: ViewType.MapAnnotation.`Type` {
var viewType: ViewType.MapAnnotation.ViewType {
let value = try? Inspector.attribute(label: "viewType", value: content.view)
return value
.flatMap { String(describing: $0) }
.flatMap { .init(rawValue: $0) } ?? .custom
.flatMap { ViewType.MapAnnotation.ViewType(rawValue: $0) } ?? .custom
}
}

Expand Down
14 changes: 7 additions & 7 deletions Tests/ViewInspectorTests/InspectionEmissaryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ final class InspectionEmissaryTests: XCTestCase {
}

func testViewModifierOnFunction() throws {
guard #available(iOS 14.0, tvOS 14.0, *) else { return }
var sut = TestViewModifier(flag: false)
let binding = Binding(wrappedValue: false)
var sut = TestViewModifier(flag: binding)
let exp = sut.on(\.didAppear) { view in
XCTAssertFalse(try view.actualView().flag)
try view.hStack().button(1).tap()
Expand Down Expand Up @@ -49,8 +49,8 @@ final class InspectionEmissaryTests: XCTestCase {
}

func testViewModifierInspectAfter() throws {
guard #available(iOS 14.0, tvOS 14.0, *) else { return }
let sut = TestViewModifier(flag: false)
let binding = Binding(wrappedValue: false)
let sut = TestViewModifier(flag: binding)
let exp1 = sut.inspection.inspect { view in
let text = try view.hStack().button(1).labelView().text().string()
XCTAssertEqual(text, "false")
Expand Down Expand Up @@ -90,8 +90,8 @@ final class InspectionEmissaryTests: XCTestCase {
}

func testViewModifierInspectOnReceive() throws {
guard #available(iOS 14.0, tvOS 14.0, *) else { return }
let sut = TestViewModifier(flag: false)
let binding = Binding(wrappedValue: false)
let sut = TestViewModifier(flag: binding)
let exp1 = sut.inspection.inspect { view in
let text = try view.hStack().button(1).labelView().text().string()
XCTAssertEqual(text, "false")
Expand Down Expand Up @@ -152,7 +152,7 @@ private class ExternalState: ObservableObject {
@available(iOS 13.0, macOS 10.15, tvOS 13.0, *)
private struct TestViewModifier: ViewModifier, Inspectable {

@State private(set) var flag: Bool
@Binding var flag: Bool
@EnvironmentObject var envState: ExternalState
let publisher = PassthroughSubject<Bool, Never>()
let inspection = Inspection<Self>()
Expand Down
2 changes: 1 addition & 1 deletion Tests/ViewInspectorTests/SwiftUI/AlertTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class AlertTests: XCTestCase {
XCTAssertThrows(try sut.inspect().emptyView().alert(),
"""
Please refer to the Guide for inspecting the Alert: \
https://github.com/nalexn/ViewInspector/blob/master/guide.md#alert
https://github.com/nalexn/ViewInspector/blob/master/guide.md#alert-sheet-and-actionsheet
""")
}

Expand Down
54 changes: 29 additions & 25 deletions Tests/ViewInspectorTests/SwiftUI/CustomViewModifierTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ final class ModifiedContentTests: XCTestCase {
}

func testMultipleModifiersInspection() throws {
guard #available(iOS 14.0, tvOS 14.0, macOS 11.0, *) else { return }
let binding = Binding(wrappedValue: false)
let view = EmptyView()
.modifier(TestModifier(tag: 1))
.padding()
.modifier(TestModifier2())
.modifier(TestModifier2(value: binding))
.padding()
.modifier(TestModifier(tag: 2))
let sut1 = try view.inspect().emptyView().modifier(TestModifier.self)
Expand All @@ -84,8 +84,8 @@ final class ModifiedContentTests: XCTestCase {
}

func testDirectAsyncInspection() throws {
guard #available(iOS 14.0, tvOS 14.0, macOS 11.0, *) else { return }
var sut = TestModifier2()
let binding = Binding(wrappedValue: false)
var sut = TestModifier2(value: binding)
let exp = XCTestExpectation(description: #function)
sut.didAppear = { rawModifier in
rawModifier.inspect { modifier in
Expand All @@ -102,8 +102,8 @@ final class ModifiedContentTests: XCTestCase {
}

func testOnAsyncInspection() throws {
guard #available(iOS 14.0, tvOS 14.0, macOS 11.0, *) else { return }
var sut = TestModifier2()
let binding = Binding(wrappedValue: false)
var sut = TestModifier2(value: binding)
let exp = sut.on(\.didAppear) { modifier in
XCTAssertEqual(try modifier.hStack().viewModifierContent(1).padding().top, 15)
try modifier.hStack().button(0).tap()
Expand All @@ -125,14 +125,14 @@ final class ModifiedContentTests: XCTestCase {
""")

let sut2 = EmptyView().modifier(TestModifier3()).environmentObject(ExternalState())
let content = try sut2.inspect().emptyView().modifier(TestModifier3.self).viewModifierContent(0)
let content = try sut2.inspect().emptyView().modifier(TestModifier3.self).group().viewModifierContent(0)
XCTAssertEqual(content.pathToRoot,
"emptyView().modifier(TestModifier3.self).viewModifierContent(0)")
let text = try sut2.inspect().emptyView().modifier(TestModifier3.self).text(1)
"emptyView().modifier(TestModifier3.self).group().viewModifierContent(0)")
let text = try sut2.inspect().emptyView().modifier(TestModifier3.self).group().text(1)
XCTAssertEqual(text.pathToRoot,
"emptyView().modifier(TestModifier3.self).text(1)")
"emptyView().modifier(TestModifier3.self).group().text(1)")
XCTAssertEqual(try sut2.inspect().find(text: "obj1").pathToRoot,
"emptyView().modifier(TestModifier3.self).text(1)")
"emptyView().modifier(TestModifier3.self).group().text(1)")
}

func testApplyingInnerModifiersToTheContent() throws {
Expand Down Expand Up @@ -170,7 +170,7 @@ private struct TestModifier: ViewModifier, Inspectable {
@available(iOS 13.0, macOS 10.15, tvOS 13.0, *)
private struct TestModifier2: ViewModifier, Inspectable {

@State var value: Bool = false
@Binding var value: Bool
var didAppear: ((Self) -> Void)?

func body(content: Self.Content) -> some View {
Expand All @@ -189,8 +189,10 @@ private struct TestModifier3: ViewModifier, Inspectable {
@EnvironmentObject var viewModel: ExternalState

func body(content: Self.Content) -> some View {
content
Text(viewModel.value)
Group {
content
Text(viewModel.value)
}
}
}

Expand All @@ -205,17 +207,19 @@ private struct TestModifier4: ViewModifier, Inspectable {
let injection: ExternalState

func body(content: Self.Content) -> some View {
EmptyView()
if injection.value == "obj1" {
AnyView(content)
.environment(\.allowsTightening, true)
.hidden()
} else {
HStack {
content
.padding(5)
.environmentObject(injection)
}.offset()
Group {
EmptyView()
if injection.value == "obj1" {
AnyView(content)
.environment(\.allowsTightening, true)
.hidden()
} else {
HStack {
content
.padding(5)
.environmentObject(injection)
}.offset()
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ViewInspector.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Pod::Spec.new do |s|

s.name = "ViewInspector"
s.version = "0.8.0"
s.version = "0.8.1"
s.summary = "ViewInspector is a library for unit testing SwiftUI views."
s.homepage = "https://github.com/nalexn/ViewInspector"
s.license = { :type => "MIT", :file => "LICENSE" }
Expand Down

0 comments on commit a9b0d2a

Please sign in to comment.