avh4 / elm-program-test

Test Elm programs
https://elm-program-test.netlify.com/
MIT License
93 stars 28 forks source link

clickButton should be able to click something with only an image in it #108

Closed avh4 closed 2 years ago

avh4 commented 4 years ago

Here's the existing code that should be able to just work with clickbutton "Close"

|> ProgramTest.simulateDomEvent
    (Query.find
        [ tag "button"
        , containing
            [ tag "img"
            , attribute (Attributes.alt "Close")
            ]
        ]
    )
    Test.Html.Event.click

... though first, is the HTML that corresponds to actually accessible? Or should the HTML actually have a different way of adding the "Close" text?

r-k-b commented 4 years ago

We've run into a similar issue, where we've got existing Cypress tests that, following [their best practice guides,](https://docs.cypress.io/guides/references/best-practices.html#:~:text=cy.get('[data-cy=submit]').click()) have data-cy="..." attributes on the elements. We'd like to reuse those in elm-program-test.

(specifically, one of our use cases is rows in a table, which don't work great with <button> or <a> ... hmm, adding role=button might be enough? 🤔 )

avh4 commented 2 years ago

In 3.6.0, buttons like the following are now clickable with clickButton "Button Label":

<button>
    <img src="..." alt="Button Label" />
</button>