-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
estrada9166
merged 13 commits into
10.0-release
from
alejandro/feat/externalLin-enhancements
Apr 7, 2022
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f8374b0
feat: <ExternalLink /> component enhancements
estrada9166 6b52716
Update test
estrada9166 c27ddcd
Update test
estrada9166 1214ba6
Merge branch '10.0-release' into alejandro/feat/externalLin-enhancements
estrada9166 a52f523
Merge branch '10.0-release' into alejandro/feat/externalLin-enhancements
estrada9166 2128376
Update with feedback
estrada9166 667e317
Merge branch '10.0-release' into alejandro/feat/externalLin-enhancements
estrada9166 bff3e17
Merge branch '10.0-release' into alejandro/feat/externalLin-enhancements
estrada9166 51efc74
Merge branch '10.0-release' into alejandro/feat/externalLin-enhancements
estrada9166 79e4e88
Merge branch '10.0-release' into alejandro/feat/externalLin-enhancements
estrada9166 5c089e8
Update ExternalLink.cy.tsx
estrada9166 33f221e
Merge branch '10.0-release' into alejandro/feat/externalLin-enhancements
estrada9166 832c195
Merge branch '10.0-release' into alejandro/feat/externalLin-enhancements
estrada9166 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
packages/frontend-shared/src/gql-components/ExternalLink.cy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,111 @@ | ||||||||
import ExternalLink from './ExternalLink.vue' | ||||||||
import { ExternalLink_OpenExternalDocument } from '../generated/graphql' | ||||||||
|
||||||||
describe('<ExternalLink />', () => { | ||||||||
beforeEach(() => { | ||||||||
const onClickSpy = cy.spy().as('onClickSpy') | ||||||||
|
||||||||
cy.mount(() => ( | ||||||||
<ExternalLink | ||||||||
href='https://on.cypress.io/ci' | ||||||||
// @ts-ignore - vue @click isn't represented in JSX | ||||||||
onClick={onClickSpy} | ||||||||
> | ||||||||
Click me! | ||||||||
</ExternalLink> | ||||||||
)) | ||||||||
}) | ||||||||
|
||||||||
it('opens external link on click', () => { | ||||||||
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') | ||||||||
}) | ||||||||
|
||||||||
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') | ||||||||
}) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This guy is 1:1 with |
||||||||
|
||||||||
it('opens external link on enter', () => { | ||||||||
const urlStub = cy.stub() | ||||||||
|
||||||||
cy.stubMutationResolver(ExternalLink_OpenExternalDocument, (defineResult, { url }) => { | ||||||||
urlStub(url) | ||||||||
|
||||||||
return defineResult({ | ||||||||
openExternal: true, | ||||||||
}) | ||||||||
}) | ||||||||
|
||||||||
cy.contains('a', 'Click me!') | ||||||||
.focus() | ||||||||
.realPress('Enter') | ||||||||
|
||||||||
cy.wrap(urlStub).should('have.been.calledWith', 'https://on.cypress.io/ci') | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.get('@onClickSpy').should('have.been.calledOnce') | ||||||||
}) | ||||||||
|
||||||||
it('opens external link on click and enter', () => { | ||||||||
const urlStub = cy.stub() | ||||||||
|
||||||||
cy.stubMutationResolver(ExternalLink_OpenExternalDocument, (defineResult, { url }) => { | ||||||||
urlStub(url) | ||||||||
|
||||||||
return defineResult({ | ||||||||
openExternal: true, | ||||||||
}) | ||||||||
}) | ||||||||
|
||||||||
cy.contains('a', 'Click me!') | ||||||||
.click() | ||||||||
.realPress('Enter') | ||||||||
|
||||||||
cy.wrap(urlStub).should('have.been.calledTwice') | ||||||||
cy.get('@onClickSpy').should('have.been.calledTwice') | ||||||||
}) | ||||||||
|
||||||||
it('do not open external link on space bar trigger', () => { | ||||||||
const urlStub = cy.stub() | ||||||||
|
||||||||
cy.stubMutationResolver(ExternalLink_OpenExternalDocument, (defineResult, { url }) => { | ||||||||
urlStub(url) | ||||||||
|
||||||||
return defineResult({ | ||||||||
openExternal: true, | ||||||||
}) | ||||||||
}) | ||||||||
|
||||||||
cy.contains('a', 'Click me!') | ||||||||
.focus() | ||||||||
.realPress('Space') | ||||||||
|
||||||||
cy.wrap(urlStub).should('not.be.called') | ||||||||
cy.get('@onClickSpy').should('not.be.called') | ||||||||
}) | ||||||||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.