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

Selector.oneOf #49

Open
rtfeldman opened this issue Feb 3, 2018 · 3 comments
Open

Selector.oneOf #49

rtfeldman opened this issue Feb 3, 2018 · 3 comments

Comments

@rtfeldman
Copy link
Collaborator

@avh4 proposed:

some way to write a query that will find the button when given a, and the input when given b:

a = div [] [ button [] [ text "Click me" ] ]
b = div [] [ input [ type_ "button", value "Click me" ] ]

The use case would be writing a reusable function to detect equivalent UI elements—e.g. a fancyButton function that queries for buttons with either the class smallFancyButton or largeFancyButton.

He proposed two potential APIs. One was:

Query.find
    [ Selector.oneOf
        [ [ tag "button", text "Click me" ]
        , [ tag "input", attribute "type" "button", attribute "value" "Click me" ]
        ]
    ]

The other potential API he proposed was:

case Query.toResult <| Query.find [ tag "button", text "Click me" ] of
    Err _ ->
        Query.find [ tag "input", attribute "type" "button", attribute "value" "Click me" ]
    Ok single ->
        single

The oneOf API seems like a good choice to me.

@avh4
Copy link

avh4 commented Feb 4, 2018

Rather than oneOf, it should probably have a better name to indicate that the first match will be the one that's used.

A downside of the oneOf approach is that we have to define how it would look in error messages (including the case of nested oneOfs). The toResult approach would leave that up to the caller to define how unmatched queries are handled.

@rtfeldman
Copy link
Collaborator Author

Rather than oneOf, it should probably have a better name to indicate that the first match will be the one that's used.

Hm, should that matter? It seems to me that if the test author is relying on that ordering, this function is not the right tool for the job!

@rtfeldman
Copy link
Collaborator Author

rtfeldman commented Feb 5, 2018

A downside of the oneOf approach is that we have to define how it would look in error messages (including the case of nested oneOfs). The toResult approach would leave that up to the caller to define how unmatched queries are handled.

To me, this is a point in favor of oneOf.

The way I see it, if we take the time to make nice error messages for oneOf, we can save many people the time it would take to handcraft their own error messages for toResult on a case-by-case basis. That adds up to a lot of saved time for a lot of people!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants