Skip to content

Commit 9ec9739

Browse files
authored
feat: <ExternalLink /> component enhancements (#20903)
* feat: <ExternalLink /> component enhancements * Update test * Update test * Update with feedback * Update ExternalLink.cy.tsx
1 parent 3fe5f50 commit 9ec9739

File tree

3 files changed

+103
-12
lines changed

3 files changed

+103
-12
lines changed

packages/app/src/runs/modals/CreateCloudOrgModal.vue

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
<p class=" mb-16px text-gray-700">
1010
{{ t('runs.connect.modal.createOrg.description') }}
1111
</p>
12-
<div @click="startWaitingOrgToBeCreated()">
13-
<ExternalLink
14-
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"
15-
:href="createOrgUrl"
16-
:include-graphql-port="true"
17-
>
18-
<i-cy-office-building_x16 class="inline-block icon-dark-white" />
19-
{{ t('runs.connect.modal.createOrg.button') }}
20-
</ExternalLink>
21-
</div>
12+
<ExternalLink
13+
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"
14+
:href="createOrgUrl"
15+
:include-graphql-port="true"
16+
@click="startWaitingOrgToBeCreated()"
17+
>
18+
<i-cy-office-building_x16 class="inline-block icon-dark-white" />
19+
{{ t('runs.connect.modal.createOrg.button') }}
20+
</ExternalLink>
2221
</div>
2322
<template #footer>
2423
<div class="flex gap-16px">
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import ExternalLink from './ExternalLink.vue'
2+
import { ExternalLink_OpenExternalDocument } from '../generated/graphql'
3+
4+
describe('<ExternalLink />', () => {
5+
beforeEach(() => {
6+
const onClickSpy = cy.spy().as('onClickSpy')
7+
8+
cy.mount(() => (
9+
<ExternalLink
10+
href='https://on.cypress.io/ci'
11+
// @ts-ignore - vue @click isn't represented in JSX
12+
onClick={onClickSpy}
13+
>
14+
Click me!
15+
</ExternalLink>
16+
))
17+
})
18+
19+
it('opens external link on click', () => {
20+
const urlStub = cy.stub()
21+
22+
cy.stubMutationResolver(ExternalLink_OpenExternalDocument, (defineResult, { url }) => {
23+
urlStub(url)
24+
25+
return defineResult({
26+
openExternal: true,
27+
})
28+
})
29+
30+
cy.contains('a', 'Click me!')
31+
.click()
32+
33+
cy.wrap(urlStub).should('have.been.calledWith', 'https://on.cypress.io/ci')
34+
cy.get('@onClickSpy').should('have.been.calledOnce')
35+
})
36+
37+
it('opens external link on enter', () => {
38+
const urlStub = cy.stub()
39+
40+
cy.stubMutationResolver(ExternalLink_OpenExternalDocument, (defineResult, { url }) => {
41+
urlStub(url)
42+
43+
return defineResult({
44+
openExternal: true,
45+
})
46+
})
47+
48+
cy.contains('a', 'Click me!')
49+
.focus()
50+
.realPress('Enter')
51+
52+
cy.wrap(urlStub).should('have.been.calledWith', 'https://on.cypress.io/ci')
53+
cy.get('@onClickSpy').should('have.been.calledOnce')
54+
})
55+
56+
it('opens external link on click and enter', () => {
57+
const urlStub = cy.stub()
58+
59+
cy.stubMutationResolver(ExternalLink_OpenExternalDocument, (defineResult, { url }) => {
60+
urlStub(url)
61+
62+
return defineResult({
63+
openExternal: true,
64+
})
65+
})
66+
67+
cy.contains('a', 'Click me!')
68+
.click()
69+
.realPress('Enter')
70+
71+
cy.wrap(urlStub).should('have.been.calledTwice')
72+
cy.get('@onClickSpy').should('have.been.calledTwice')
73+
})
74+
75+
it('do not open external link on space bar trigger', () => {
76+
const urlStub = cy.stub()
77+
78+
cy.stubMutationResolver(ExternalLink_OpenExternalDocument, (defineResult, { url }) => {
79+
urlStub(url)
80+
81+
return defineResult({
82+
openExternal: true,
83+
})
84+
})
85+
86+
cy.contains('a', 'Click me!')
87+
.focus()
88+
.realPress('Space')
89+
90+
cy.wrap(urlStub).should('not.be.called')
91+
cy.get('@onClickSpy').should('not.be.called')
92+
})
93+
})

packages/frontend-shared/src/gql-components/ExternalLink.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
data-cy="external"
55
:href="props.href"
66
:use-default-hocus="props.useDefaultHocus"
7-
role="link"
87
@click.prevent="open"
9-
@keypress.space.enter.prevent="open"
8+
@keypress.enter.prevent="open"
109
><slot /></BaseLink>
1110
</template>
1211

0 commit comments

Comments
 (0)