Skip to content

Commit

Permalink
Finalize 0.9.5 release
Browse files Browse the repository at this point in the history
  • Loading branch information
nalexn authored Jan 15, 2023
2 parents 724c7e3 + f8d9033 commit 4effbd9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Sources/ViewInspector/ViewSearch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,10 @@ private extension UnwrappedView {
func recursionAbsenceCheck() -> Bool {
guard content.isCustomView else { return true }
let typeRef = type(of: content.view)
var isDirectParent = true
return (try? findParent(condition: { parent in
return typeRef == type(of: parent.content.view) && parent.parentView != nil
defer { isDirectParent = false }
return typeRef == type(of: parent.content.view) && !isDirectParent
}, skipFound: 0)) == nil
}
}
Expand Down
40 changes: 32 additions & 8 deletions Tests/ViewInspectorTests/SwiftUI/NavigationLinkTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@ final class NavigationLinkTests: XCTestCase {
func testSearchWithBindings() throws {
let selection = Binding<String?>(wrappedValue: nil)
let sut = try TestViewBinding(selection: selection).inspect()
XCTAssertNoThrow(try sut.find(text: "GoTo 1"))
XCTAssertNoThrow(try sut.find(text: "GoTo 2"))
let notFoundError = "Search did not find a match"
XCTAssertThrows(try sut.find(text: "Screen 1"), notFoundError)
XCTAssertThrows(try sut.find(text: "Screen 2"), notFoundError)
try sut.navigationView().navigationLink(0).activate()
XCTAssertNoThrow(try sut.find(text: "GoTo 1"))
XCTAssertNoThrow(try sut.find(text: "GoTo 2"))
XCTAssertNoThrow(try sut.find(text: "Screen 1"))
XCTAssertThrows(try sut.find(text: "Screen 2"), notFoundError)
try sut.navigationView().navigationLink(1).activate()
Expand Down Expand Up @@ -196,12 +200,17 @@ final class NavigationLinkTests: XCTestCase {
"Search did not find a match")
XCTAssertThrows(try sut.find(ViewType.Text.self, traversal: .depthFirst, where: { _ in false }),
"Search did not find a match")
XCTAssertEqual(
try sut.find(text: "B to A").pathToRoot,
"""
view(TestRecursiveLinksView.self).navigationView().view(ViewAtoB.self)\
.navigationLink().view(ViewBtoA.self).navigationLink().labelView().text()
""")
XCTAssertNoThrow(try sut.find(text: "B to A"))
}

func testRecursiveGenericReferenceView() throws {
let view = TestRecursiveGenericView
.init(view: TestRecursiveGenericView
.init(view: TestRecursiveGenericView
.init(view: Text("test"))))
let container = "view(TestRecursiveGenericView<EmptyView>.self)."
XCTAssertEqual(try view.inspect().find(text: "test").pathToRoot,
container + container + container + "text()")
}
}

Expand Down Expand Up @@ -259,19 +268,34 @@ extension TestViewState {
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 7.0, *)
private struct TestRecursiveLinksView: View {

struct NavLabel: View {
let text: String
var body: some View {
Text(text)
}
}

struct ViewAtoB: View {
var body: some View {
NavigationLink(destination: ViewBtoA()) { Text("A to B") }
NavigationLink(destination: ViewBtoA()) { NavLabel(text: "A to B") }
}
}

struct ViewBtoA: View {
var body: some View {
NavigationLink(destination: ViewAtoB()) { Text("B to A") }
NavigationLink(destination: ViewAtoB()) { NavLabel(text: "B to A") }
}
}

var body: some View {
NavigationView { ViewAtoB() }
}
}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 7.0, *)
private struct TestRecursiveGenericView<T: View>: View {
let view: T
var body: some View {
view
}
}
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.9.4"
s.version = "0.9.5"
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 4effbd9

Please sign in to comment.