Skip to content

Conversation

@nunntom
Copy link
Contributor

@nunntom nunntom commented Jul 29, 2022

Hi @avh4. While I was on a roll I decided to have a look at #158, because I'm also running into this issue where I am using icons in links with an aria-label.

See what you think.

Closes #158

  • ran tests locally with npm test
  • updated CHANGELOG.md if appropriate

-- there is a click handler
-- first make sure the handler properly respects "Open in new tab", etc
if respondsTo ctrlClick link || respondsTo metaClick link then
if respondsTo normalClick then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having a little bit of trouble convincing myself this refactoring is correct now that repondsTo doesn't take the found link element as an input. I guess it's that repondsTo is re-running the original query, just modified to do the simulate as the last step of each branch?

Apart from being a bit confusing to read, it makes me a little nervous about the performance if we're re-doing that work, since ComplexQuery can be quite slow (especially when a query fails).

Here's one possible thought: maybe we could extract a new function from simulateComplexQuery/assertComplexQuery:

runComplexQuery :
    String
    -> (ComplexQuery (Query.Single msg) -> ComplexQuery a)
    -> (Program model msg effect (SimulatedSub msg) -> TestState model msg effect -> a ->  Result Failure (TestState model msg effect))
    -> ProgramTest model msg effect
    -> ProgramTest model msg effect

simulateComplexQuery functionName complexQuery =
    runComplexQuery functionName complexQuery <| \program state msg -> TestState.update msg program state

assertComplexQuery functionName complexQuery =
    runComplexQuery functionName complexQuery <| _ state _ -> state

And then here we could use runComplexQuery with the findLinkQuery to get the single, and a function that will take the single and use it to "try clicking", and then we wouldn't have to re-find the single in each call of respondsTo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Not sure what I was thinking implementing it that way. I think it was running the query five times! I actually later came up with something along the lines of your suggestion independently. I've now implemented runComplexQuery (with a slight change of argument order) and pushed.

assertComplexQuery is not being used now. Not sure if it's worth keeping it around.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there have been many times on this project where I've implemented something, and then when I show it to someone they ask why I did it so complicated 😄

It's fine to leave assertComplexQuery for now, especially since I haven't finished reviewing if there are more functions that should be ported over to using ComplexQuery internally.

findLinkQuery =
[ ( "<a> with text"
, ComplexQuery.find (Just "find link")
[ "link" ]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, this argument is a list of html tags that will be kept expanded when the ComplexQuery error renderer tries to condense down the HTML out. So this should be [ "a" ], not "link".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I was wondering what this did.

Comment on lines +57 to +66
, test "can verify a link with aria-label" <|
\() ->
linkProgram
|> ProgramTest.clickLink "Aria" "https://example.com/link"
|> ProgramTest.expectPageChange "https://example.com/link"
, test "can verify a link with img and alt text" <|
\() ->
linkProgram
|> ProgramTest.clickLink "Alt Text" "https://example.com/link"
|> ProgramTest.expectPageChange "https://example.com/link"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@nunntom nunntom requested a review from avh4 August 1, 2022 19:23
@avh4
Copy link
Owner

avh4 commented Aug 2, 2022

(I'll get to this tomorrow if I don't have time for it today.)

@avh4
Copy link
Owner

avh4 commented Aug 4, 2022

Looks great, thank you!!

@avh4 avh4 merged commit b54e240 into avh4:develop Aug 4, 2022
@avh4 avh4 added this to the 3.6.4 milestone Aug 4, 2022
@avh4 avh4 added the merged-but-not-released Will be fixed in the next release label Aug 4, 2022
@avh4 avh4 removed the merged-but-not-released Will be fixed in the next release label Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants