@@ -72,10 +72,14 @@ final class NavigationLinkTests: XCTestCase {
72
72
func testSearchWithBindings( ) throws {
73
73
let selection = Binding < String ? > ( wrappedValue: nil )
74
74
let sut = try TestViewBinding ( selection: selection) . inspect ( )
75
+ XCTAssertNoThrow ( try sut. find ( text: " GoTo 1 " ) )
76
+ XCTAssertNoThrow ( try sut. find ( text: " GoTo 2 " ) )
75
77
let notFoundError = " Search did not find a match "
76
78
XCTAssertThrows ( try sut. find ( text: " Screen 1 " ) , notFoundError)
77
79
XCTAssertThrows ( try sut. find ( text: " Screen 2 " ) , notFoundError)
78
80
try sut. navigationView ( ) . navigationLink ( 0 ) . activate ( )
81
+ XCTAssertNoThrow ( try sut. find ( text: " GoTo 1 " ) )
82
+ XCTAssertNoThrow ( try sut. find ( text: " GoTo 2 " ) )
79
83
XCTAssertNoThrow ( try sut. find ( text: " Screen 1 " ) )
80
84
XCTAssertThrows ( try sut. find ( text: " Screen 2 " ) , notFoundError)
81
85
try sut. navigationView ( ) . navigationLink ( 1 ) . activate ( )
@@ -196,12 +200,17 @@ final class NavigationLinkTests: XCTestCase {
196
200
" Search did not find a match " )
197
201
XCTAssertThrows ( try sut. find ( ViewType . Text. self, traversal: . depthFirst, where: { _ in false } ) ,
198
202
" 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() " )
205
214
}
206
215
}
207
216
@@ -259,19 +268,34 @@ extension TestViewState {
259
268
@available ( iOS 13 . 0 , macOS 10 . 15 , tvOS 13 . 0 , watchOS 7 . 0 , * )
260
269
private struct TestRecursiveLinksView : View {
261
270
271
+ struct NavLabel : View {
272
+ let text : String
273
+ var body : some View {
274
+ Text ( text)
275
+ }
276
+ }
277
+
262
278
struct ViewAtoB : View {
263
279
var body : some View {
264
- NavigationLink ( destination: ViewBtoA ( ) ) { Text ( " A to B " ) }
280
+ NavigationLink ( destination: ViewBtoA ( ) ) { NavLabel ( text : " A to B " ) }
265
281
}
266
282
}
267
283
268
284
struct ViewBtoA : View {
269
285
var body : some View {
270
- NavigationLink ( destination: ViewAtoB ( ) ) { Text ( " B to A " ) }
286
+ NavigationLink ( destination: ViewAtoB ( ) ) { NavLabel ( text : " B to A " ) }
271
287
}
272
288
}
273
289
274
290
var body : some View {
275
291
NavigationView { ViewAtoB ( ) }
276
292
}
277
293
}
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
+ }
0 commit comments