-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: <ExternalLink /> component enhancements (#20903)
* feat: <ExternalLink /> component enhancements * Update test * Update test * Update with feedback * Update ExternalLink.cy.tsx
- Loading branch information
1 parent
3fe5f50
commit 9ec9739
Showing
3 changed files
with
103 additions
and
12 deletions.
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
93 changes: 93 additions & 0 deletions
93
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,93 @@ | ||
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 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') | ||
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
9ec9739
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.
Circle has built the
linux x64
version of the Test Runner.Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally:
9ec9739
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.
Circle has built the
darwin x64
version of the Test Runner.Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally:
9ec9739
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.
Circle has built the
win32 x64
version of the Test Runner.Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally: