Skip to content

Commit 4effbd9

Browse files
authored
Finalize 0.9.5 release
2 parents 724c7e3 + f8d9033 commit 4effbd9

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

Sources/ViewInspector/ViewSearch.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,10 @@ private extension UnwrappedView {
493493
func recursionAbsenceCheck() -> Bool {
494494
guard content.isCustomView else { return true }
495495
let typeRef = type(of: content.view)
496+
var isDirectParent = true
496497
return (try? findParent(condition: { parent in
497-
return typeRef == type(of: parent.content.view) && parent.parentView != nil
498+
defer { isDirectParent = false }
499+
return typeRef == type(of: parent.content.view) && !isDirectParent
498500
}, skipFound: 0)) == nil
499501
}
500502
}

Tests/ViewInspectorTests/SwiftUI/NavigationLinkTests.swift

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,14 @@ final class NavigationLinkTests: XCTestCase {
7272
func testSearchWithBindings() throws {
7373
let selection = Binding<String?>(wrappedValue: nil)
7474
let sut = try TestViewBinding(selection: selection).inspect()
75+
XCTAssertNoThrow(try sut.find(text: "GoTo 1"))
76+
XCTAssertNoThrow(try sut.find(text: "GoTo 2"))
7577
let notFoundError = "Search did not find a match"
7678
XCTAssertThrows(try sut.find(text: "Screen 1"), notFoundError)
7779
XCTAssertThrows(try sut.find(text: "Screen 2"), notFoundError)
7880
try sut.navigationView().navigationLink(0).activate()
81+
XCTAssertNoThrow(try sut.find(text: "GoTo 1"))
82+
XCTAssertNoThrow(try sut.find(text: "GoTo 2"))
7983
XCTAssertNoThrow(try sut.find(text: "Screen 1"))
8084
XCTAssertThrows(try sut.find(text: "Screen 2"), notFoundError)
8185
try sut.navigationView().navigationLink(1).activate()
@@ -196,12 +200,17 @@ final class NavigationLinkTests: XCTestCase {
196200
"Search did not find a match")
197201
XCTAssertThrows(try sut.find(ViewType.Text.self, traversal: .depthFirst, where: { _ in false }),
198202
"Search did not find a match")
199-
XCTAssertEqual(
200-
try sut.find(text: "B to A").pathToRoot,
201-
"""
202-
view(TestRecursiveLinksView.self).navigationView().view(ViewAtoB.self)\
203-
.navigationLink().view(ViewBtoA.self).navigationLink().labelView().text()
204-
""")
203+
XCTAssertNoThrow(try sut.find(text: "B to A"))
204+
}
205+
206+
func testRecursiveGenericReferenceView() throws {
207+
let view = TestRecursiveGenericView
208+
.init(view: TestRecursiveGenericView
209+
.init(view: TestRecursiveGenericView
210+
.init(view: Text("test"))))
211+
let container = "view(TestRecursiveGenericView<EmptyView>.self)."
212+
XCTAssertEqual(try view.inspect().find(text: "test").pathToRoot,
213+
container + container + container + "text()")
205214
}
206215
}
207216

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

271+
struct NavLabel: View {
272+
let text: String
273+
var body: some View {
274+
Text(text)
275+
}
276+
}
277+
262278
struct ViewAtoB: View {
263279
var body: some View {
264-
NavigationLink(destination: ViewBtoA()) { Text("A to B") }
280+
NavigationLink(destination: ViewBtoA()) { NavLabel(text: "A to B") }
265281
}
266282
}
267283

268284
struct ViewBtoA: View {
269285
var body: some View {
270-
NavigationLink(destination: ViewAtoB()) { Text("B to A") }
286+
NavigationLink(destination: ViewAtoB()) { NavLabel(text: "B to A") }
271287
}
272288
}
273289

274290
var body: some View {
275291
NavigationView { ViewAtoB() }
276292
}
277293
}
294+
295+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 7.0, *)
296+
private struct TestRecursiveGenericView<T: View>: View {
297+
let view: T
298+
var body: some View {
299+
view
300+
}
301+
}

ViewInspector.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Pod::Spec.new do |s|
33

44
s.name = "ViewInspector"
5-
s.version = "0.9.4"
5+
s.version = "0.9.5"
66
s.summary = "ViewInspector is a library for unit testing SwiftUI views."
77
s.homepage = "https://github.com/nalexn/ViewInspector"
88
s.license = { :type => "MIT", :file => "LICENSE" }

0 commit comments

Comments
 (0)