Skip to content

Commit

Permalink
feat: <ExternalLink /> component enhancements (#20903)
Browse files Browse the repository at this point in the history
* feat: <ExternalLink /> component enhancements

* Update test

* Update test

* Update with feedback

* Update ExternalLink.cy.tsx
  • Loading branch information
estrada9166 committed Apr 7, 2022
1 parent 3fe5f50 commit 9ec9739
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 12 deletions.
19 changes: 9 additions & 10 deletions packages/app/src/runs/modals/CreateCloudOrgModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
<p class=" mb-16px text-gray-700">
{{ t('runs.connect.modal.createOrg.description') }}
</p>
<div @click="startWaitingOrgToBeCreated()">
<ExternalLink
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"
>
<i-cy-office-building_x16 class="inline-block icon-dark-white" />
{{ t('runs.connect.modal.createOrg.button') }}
</ExternalLink>
</div>
<ExternalLink
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()"
>
<i-cy-office-building_x16 class="inline-block icon-dark-white" />
{{ t('runs.connect.modal.createOrg.button') }}
</ExternalLink>
</div>
<template #footer>
<div class="flex gap-16px">
Expand Down
93 changes: 93 additions & 0 deletions packages/frontend-shared/src/gql-components/ExternalLink.cy.tsx
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')
})
})
3 changes: 1 addition & 2 deletions packages/frontend-shared/src/gql-components/ExternalLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
data-cy="external"
:href="props.href"
:use-default-hocus="props.useDefaultHocus"
role="link"
@click.prevent="open"
@keypress.space.enter.prevent="open"
@keypress.enter.prevent="open"
><slot /></BaseLink>
</template>

Expand Down

3 comments on commit 9ec9739

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 9ec9739 Apr 7, 2022

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:

npm install https://cdn.cypress.io/beta/npm/10.0.0/linux-x64/10.0-release-9ec973987792e4573b98bc88b51357c2bbe72523/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 9ec9739 Apr 7, 2022

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:

npm install https://cdn.cypress.io/beta/npm/10.0.0/darwin-x64/10.0-release-9ec973987792e4573b98bc88b51357c2bbe72523/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 9ec9739 Apr 7, 2022

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:

npm install https://cdn.cypress.io/beta/npm/10.0.0/win32-x64/10.0-release-9ec973987792e4573b98bc88b51357c2bbe72523/cypress.tgz

Please sign in to comment.