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

Find fails when view has recursion inside of ForEach #285

Closed
starke0o opened this issue Dec 21, 2023 · 1 comment
Closed

Find fails when view has recursion inside of ForEach #285

starke0o opened this issue Dec 21, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@starke0o
Copy link

Description

When view contains it self inside of a ForEach then find(text:) does not find text and fails with .searchFailure. When i check manually the searched text is found (see testGoToText in sample)

Minimal sample to reproduce

View with recursion inside of ForEach:

struct TreeView: View {
    struct Item: Identifiable {
        var id: Int { name.hashValue }
        
        var name: String
        var childs: [Item] = []
    }
    
    var item: Item
    
    var body: some View {
        VStack {
            Text(item.name)
            
            ForEach(item.childs, id: \.name) {
                TreeView(item: $0)
            }
        }
    }
}

Test case with failing test testFindText

class ViewInspectorFindBugTest: XCTestCase {
    let sut = TreeView(
        item: TreeView.Item(
            name: "Root",
            childs: [
                TreeView.Item(
                    name: "A",
                    childs: [
                        TreeView.Item(name: "A.1"),
                        TreeView.Item(name: "A.2"),
                    ]
                ),
                TreeView.Item(
                    name: "B",
                    childs: [
                        TreeView.Item(name: "B.1"),
                        TreeView.Item(name: "B.2"),
                    ]
                )
            ]
        )
    )
    
    func testFindText() throws {
        XCTAssertNoThrow(try sut.inspect().find(text: "A.2"))
    }
    
    func testGoToText() throws {
        XCTAssertEqual(
            "A.2",
            try sut
                .inspect().vStack().forEach(1)
                .view(TreeView.self, 0).vStack().forEach(1)
                .view(TreeView.self, 1).vStack().text(0).string()
        )
    }
}

Snapshot of testview:
Bildschirmfoto 2023-12-21 um 13 51 43

@nalexn
Copy link
Owner

nalexn commented Dec 25, 2023

Thanks for the report! The fix is pending release

@nalexn nalexn added bug Something isn't working pending release A fixed issue that'll be released in an upcoming update labels Dec 25, 2023
@nalexn nalexn removed the pending release A fixed issue that'll be released in an upcoming update label Jan 21, 2024
@nalexn nalexn closed this as completed Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants