avh4 / elm-program-test

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

`selectOption` finds too many elements #92

Closed hanneskaeufler closed 4 years ago

hanneskaeufler commented 4 years ago

I wonder if the selectOption helper is missing an all selector-wrapper around the distinct selectors? https://github.com/avh4/elm-program-test/blob/master/src/ProgramTest.elm#L1291

I am getting the following error when trying to fill in a <select>

selectOption "flightType" "" "return" "return flight":
    ▼ Query.fromHtml

        <body>
            <label htmlFor="flightType">

                <select id="flightType">
                    <option value="oneWay">
                        one-way flight
                    </option>
                    <option value="return">
                        return flight
                    </option>
                </select>
            </label>
            <input type="date" value="28.12.2019">
            <input type="date" disabled=true>
        </body>

    ▼ Query.find [ tag "label", attribute "htmlFor" "flightType", text "" ]

        1)

        2)  one-way flight

        3)  return flight

    ✗ Query.find always expects to find 1 element, but it found 3 instead.

    HINT: If you actually expected 3 elements, use Query.findAll instead of Query.find.

Granted I am not having any text inside the label (because this particular select will not get a label, but I guess that's something for another issue).

hanneskaeufler commented 4 years ago

Playing with this a bit longer and reading the comments explaining the id and for parameters are going to be removed from the method, I think I agree with how this is working. We should probably alway use "user facing" identifiers (e.g. text or accessibility labels) to query for elements, and if I want to omit the label I better hide it in css.