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

Better API for inspecting hierarchical lists #188

Open
aaryankotharii opened this issue Sep 1, 2022 · 1 comment
Open

Better API for inspecting hierarchical lists #188

aaryankotharii opened this issue Sep 1, 2022 · 1 comment
Labels
feature request New feature or request

Comments

@aaryankotharii
Copy link

unable to test hierarchical list

UI taken from hackingwithswift

struct Bookmark: Identifiable {
    let id = UUID()
    let name: String
    let icon: String
    var items: [Bookmark]?

    // some example websites
    static let apple = Bookmark(name: "Apple", icon: "1.circle")
    static let bbc = Bookmark(name: "BBC", icon: "square.and.pencil")
    static let swift = Bookmark(name: "Swift", icon: "bolt.fill")
    static let twitter = Bookmark(name: "Twitter", icon: "mic")

    // some example groups
    static let example1 = Bookmark(name: "Favorites", icon: "star", items: [Bookmark.apple, Bookmark.bbc, Bookmark.swift, Bookmark.twitter])
    static let example2 = Bookmark(name: "Recent", icon: "timer", items: [Bookmark.apple, Bookmark.bbc, Bookmark.swift, Bookmark.twitter])
    static let example3 = Bookmark(name: "Recommended", icon: "hand.thumbsup", items: [Bookmark.apple, Bookmark.bbc, Bookmark.swift, Bookmark.twitter])
}

struct ListTest: View, Inspectable {
    let items: [Bookmark] = [.example1, .example2, .example3]

    var body: some View {
        List(items, children: \.items) { row in
            Image(systemName: row.icon)
            Text(row.name)
        }
    }
}

test written

class ListTests: XCTestCase {
    func testListKeyIcon() throws {
        let sut = ListTest()
        let text = try sut.inspect().list().text(0)
    }
}

error
view(ListTest.self).list().text(0) found OutlineGroup<Swift.Array<WalletUITests.Bookmark>, Foundation.UUID, SwiftUI.TupleView<(SwiftUI.Image, SwiftUI.Text)>, SwiftUI.TupleView<(SwiftUI.Image, SwiftUI.Text)>, SwiftUI.DisclosureGroup<SwiftUI.TupleView<(SwiftUI.Image, SwiftUI.Text)>, SwiftUI.OutlineSubgroupChildren>> instead of Text

@nalexn
Copy link
Owner

nalexn commented Sep 10, 2022

Hey, in your specific case you can get to the Text using this chain:

let text = try sut.inspect().list().outlineGroup(0).leaf(Bookmark.example1).text(1)

I do find this quite verbose and unintuitive, I'll explore how to improve the experience of inspecting the hierarchical lists.

@nalexn nalexn added the feature request New feature or request label Sep 10, 2022
@nalexn nalexn changed the title help: inspecting list with children Better API for inspecting hierarchical lists Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants