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

feat: <ExternalLink /> component enhancements #20903

Merged
merged 13 commits into from Apr 7, 2022

Conversation

estrada9166
Copy link
Member

@estrada9166 estrada9166 commented Apr 4, 2022

User facing changelog

Additional details

How has the user experience changed?

Prevent opening external links whit the spacebar

PR Tasks

  • Have tests been added/updated?
  • Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • Has a PR for user-facing changes been opened in cypress-documentation?
  • Have API changes been updated in the type definitions?
  • Have new configuration options been added to the cypress.schema.json?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 4, 2022

Thanks for taking the time to open a PR!

@cypress
Copy link

cypress bot commented Apr 4, 2022



Test summary

17812 0 217 0Flakiness 0


Run details

Project cypress
Status Passed
Commit 832c195
Started Apr 7, 2022 12:22 AM
Ended Apr 7, 2022 12:34 AM
Duration 12:11 💡
OS Linux Debian - 10.10
Browser Multiple

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@estrada9166 estrada9166 marked this pull request as ready for review April 5, 2022 02:44
Copy link
Contributor

@marktnoonan marktnoonan left a comment

Choose a reason for hiding this comment

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

Nice, we did not need to re-emit the events after all. Thank you for adding the tests! I have a few change requests and suggestions, nothing big.

@@ -3,6 +3,7 @@
<a
:href="props.href"
:class="classes"
@keypress.space.enter.prevent="open"
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't look like it's needed, may have been left in PR accidentally? I took it out and everything was fine.

.focus()
.realPress('Enter')

cy.wrap(urlStub).should('have.been.calledWith', 'https://on.cypress.io/ci')
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to confirm the onClickSpy was called here?

Suggested change
cy.wrap(urlStub).should('have.been.calledWith', 'https://on.cypress.io/ci')
cy.wrap(urlStub).should('have.been.calledWith', 'https://on.cypress.io/ci')
cy.get('@onClickSpy').should('have.been.calledOnce')

Comment on lines 84 to 89
cy.get('[data-cy="external"]')
.click()

cy.get('[data-cy="external"]')
.focus()
.realPress('Enter')
Copy link
Contributor

Choose a reason for hiding this comment

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

Side note, the need to use realPress here is a sign that we should look into doing something like #19726 for links as well. Feel like cy.type('{enter}') should work fine here, but it doesn't. I'll look into that separately and probably open an issue.

Also I think we can shorten this up a little if we want:

Suggested change
cy.get('[data-cy="external"]')
.click()
cy.get('[data-cy="external"]')
.focus()
.realPress('Enter')
cy.get('[data-cy="external"]')
.click()
.realPress('Enter')

})
})

cy.get('[data-cy="external"]')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
cy.get('[data-cy="external"]')
cy.contains('a', 'Click me!')

A couple of reasons for this suggestion:

  • confirm accessibility of component in general (should be a link)
  • confirm the slot content you added in the beforeEach renders in the expected place

class="border rounded mx-auto outline-none py-11px px-16px border-indigo-500 bg-indigo-500 text-white inline-block hocus-default max-h-60px"
:href="createOrgUrl"
:include-graphql-port="true"
@click="startWaitingOrgToBeCreated()"
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool - this is the click that made me suspect we needed to emit the event, I assumed the extra div I saw here was a workaround for this component swallowing the click event, looks like it wasn't but still better to have this here and let this part of the UI be keyboard-accessible.

Copy link
Contributor

@marktnoonan marktnoonan left a comment

Choose a reason for hiding this comment

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

Looks good!

@emilyrohrbough
Copy link
Member

@estrada9166 why do we want to change the behavior of the ExternalLink component to not behave like a link and open when the space key is pressed?

@marktnoonan
Copy link
Contributor

@estrada9166 why do we want to change the behavior of the ExternalLink component to not behave like a link and open when the space key is pressed?

Regular links only open with the enter key, the space behavior we added originally here is not standard - so it would be unexpected behavior if a user whose keyboard is focused on a link hits spacebar to do its default thing (usually scroll the page) and we open the link.

Comment on lines 37 to 53
it('opens external link on click and triggers onClick function', () => {
const urlStub = cy.stub()

cy.stubMutationResolver(ExternalLink_OpenExternalDocument, (defineResult, { url }) => {
urlStub(url)

return defineResult({
openExternal: true,
})
})

cy.contains('a', 'Click me!')
.click()

cy.wrap(urlStub).should('have.been.calledWith', 'https://on.cypress.io/ci')
cy.get('@onClickSpy').should('have.been.calledOnce')
})
Copy link
Member

Choose a reason for hiding this comment

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

This guy is 1:1 with 'opens external link on click'

Copy link
Member

@emilyrohrbough emilyrohrbough left a comment

Choose a reason for hiding this comment

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

LGTM - just needs the duplicate test removed.

@estrada9166 estrada9166 merged commit 9ec9739 into 10.0-release Apr 7, 2022
@estrada9166 estrada9166 deleted the alejandro/feat/externalLin-enhancements branch April 7, 2022 00:38
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.

None yet

3 participants