Skip to content

Commit

Permalink
Merge c7de465 into a33ca46
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Apr 15, 2024
2 parents a33ca46 + c7de465 commit d643daa
Show file tree
Hide file tree
Showing 15 changed files with 691 additions and 130 deletions.
60 changes: 60 additions & 0 deletions e2e/docs/components/auto-link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# AutoLink

<div id="route-link">
<AutoLink v-for="item in routeLinksConfig" :config="item" />
</div>

<div id="anchor-link">
<AutoLink v-for="item in anchorLinksConfig" :config="item" />
</div>

<div id="aria-label">
<AutoLink :config="{ text: 'text', link: '/', ariaLabel: 'label' }" />
</div>

<script setup lang="ts">
import { AutoLink } from 'vuepress/client'

const routeLinks = [
'/',
'/README.md',
'/index.html',
'/non-existent',
'/non-existent.md',
'/non-existent.html',
'/routes/non-ascii-paths/中文目录名/中文文件名',
'/routes/non-ascii-paths/中文目录名/中文文件名.md',
'/routes/non-ascii-paths/中文目录名/中文文件名.html',
'/README.md#hash',
'/README.md?query',
'/README.md?query#hash',
'/#hash',
'/?query',
'/?query#hash',
'#hash',
'?query',
'?query#hash',
'route-link',
'route-link.md',
'route-link.html',
'not-existent',
'not-existent.md',
'not-existent.html',
'../',
'../README.md',
'../404.md',
'../404.html',
]

const routeLinksConfig = routeLinks.map((link) => ({ link, text: 'text' }))

const anchorLinks = [
'//example.com',
'http://example.com',
'https://example.com',
'mailto:example@example.com',
'tel:+1234567890',
]

const anchorLinksConfig = anchorLinks.map((link) => ({ link, text: 'text' }))
</script>
27 changes: 27 additions & 0 deletions e2e/docs/components/route-link.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,37 @@

- <RouteLink to="/README.md" active="">text</RouteLink>
- <RouteLink to="/README.md" active>text</RouteLink>
- <RouteLink to="/" active="">text</RouteLink>
- <RouteLink to="/" active>text</RouteLink>
- <RouteLink to="/README.md" :active="false">text</RouteLink>
- <RouteLink to="/README.md">text</RouteLink>
- <RouteLink to="/" :active="false">text</RouteLink>
- <RouteLink to="/">text</RouteLink>

### Class

- <RouteLink to="/README.md" class="custom-class">text</RouteLink>
- <RouteLink to="/README.md" active class="custom-class">text</RouteLink>
- <RouteLink to="/" class="custom-class">text</RouteLink>
- <RouteLink to="/" active class="custom-class">text</RouteLink>

### Attrs

- <RouteLink to="/README.md" title="Title">text</RouteLink>
- <RouteLink to="/README.md" target="_blank">text</RouteLink>
- <RouteLink to="/README.md" rel="noopener">text</RouteLink>
- <RouteLink to="/README.md" aria-label="test">text</RouteLink>
- <RouteLink to="/" title="Title">text</RouteLink>
- <RouteLink to="/" target="_blank">text</RouteLink>
- <RouteLink to="/" rel="noopener">text</RouteLink>
- <RouteLink to="/" aria-label="test">text</RouteLink>

### Slots

- <RouteLink to="/README.md"><span>text</span></RouteLink>
- <RouteLink to="/README.md"><span>text</span><span>text2</span></RouteLink>
- <RouteLink to="/"><span>text</span></RouteLink>
- <RouteLink to="/"><span>text</span><span>text</span></RouteLink>

### Hash and query

Expand All @@ -56,9 +68,24 @@
- <RouteLink to="/README.md?query=1#hash">text</RouteLink>
- <RouteLink to="/README.md?query=1&query=2#hash">text</RouteLink>
- <RouteLink to="/README.md#hash?query=1&query=2">text</RouteLink>
- <RouteLink to="/#hash">text</RouteLink>
- <RouteLink to="/?query">text</RouteLink>
- <RouteLink to="/?query#hash">text</RouteLink>
- <RouteLink to="/?query=1#hash">text</RouteLink>
- <RouteLink to="/?query=1&query=2#hash">text</RouteLink>
- <RouteLink to="/#hash?query=1&query=2">text</RouteLink>
- <RouteLink to="#hash">text</RouteLink>
- <RouteLink to="?query">text</RouteLink>
- <RouteLink to="?query#hash">text</RouteLink>
- <RouteLink to="?query=1#hash">text</RouteLink>
- <RouteLink to="?query=1&query=2#hash">text</RouteLink>
- <RouteLink to="#hash?query=1&query=2">text</RouteLink>

### Relative

- <RouteLink to="../README.md">text</RouteLink>
- <RouteLink to="../404.md">text</RouteLink>
- <RouteLink to="not-exist.md">text</RouteLink>
- <RouteLink to="../">text</RouteLink>
- <RouteLink to="../404.html">text</RouteLink>
- <RouteLink to="not-exist.html">text</RouteLink>
19 changes: 19 additions & 0 deletions e2e/tests/components/auto-link.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
it('AutoLink', () => {
cy.visit('/components/auto-link.html')

cy.get(`.e2e-theme-content #route-link a`).each((el) => {
cy.wrap(el)
.should('have.attr', 'class')
.and('match', /route-link/)
})

cy.get(`.e2e-theme-content #anchor-link a`).each((el) => {
cy.wrap(el)
.should('have.attr', 'class')
.and('match', /anchor-link/)
})

cy.get(`.e2e-theme-content #aria-label a`).each((el) => {
cy.wrap(el).should('have.attr', 'aria-label').and('eq', 'label')
})
})
126 changes: 126 additions & 0 deletions e2e/tests/components/route-link.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
it('RouteLink', () => {
const E2E_BASE = Cypress.env('E2E_BASE')

cy.visit('/components/route-link.html')

cy.get(`.e2e-theme-content #home-page + ul > li`).each((el) => {
cy.wrap(el).within(() => {
cy.get('a').should('have.attr', 'href', E2E_BASE)
cy.get('a').should('have.text', 'text')
})
})

cy.get(`.e2e-theme-content #non-existent + ul > li`).each((el) => {
cy.wrap(el).within(() => {
cy.get('a').should('have.attr', 'href', `${E2E_BASE}non-existent.html`)
cy.get('a').should('have.text', 'text')
})
})

cy.get(`.e2e-theme-content #non-ascii + ul > li`).each((el) => {
cy.wrap(el).within(() => {
cy.get('a').should(
'have.attr',
'href',
encodeURI(
`${E2E_BASE}routes/non-ascii-paths/中文目录名/中文文件名.html`,
),
)
cy.get('a').should('have.text', 'text')
})
})

cy.get(`.e2e-theme-content #non-ascii-encoded + ul > li`).each((el) => {
cy.wrap(el).within(() => {
cy.get('a').should(
'have.attr',
'href',
encodeURI(
`${E2E_BASE}routes/non-ascii-paths/中文目录名/中文文件名.html`,
),
)
cy.get('a').should('have.text', 'text')
})
})

cy.get(`.e2e-theme-content #active + ul > li`).each((el, index) => {
cy.wrap(el).within(() => {
if (index < 4) {
cy.get('a').should('have.attr', 'class', 'route-link route-link-active')
} else {
cy.get('a').should('have.attr', 'class', 'route-link')
}
cy.get('a').should('have.text', 'text')
})
})

const classResults = [
'route-link custom-class',
'route-link route-link-active custom-class',
]
cy.get(`.e2e-theme-content #class + ul > li`).each((el, index) => {
cy.wrap(el).within(() => {
cy.get('a').should('have.attr', 'class', classResults[index % 2])
cy.get('a').should('have.text', 'text')
})
})

const attrName = ['title', 'target', 'rel', 'aria-label']
const attrValue = ['Title', '_blank', 'noopener', 'test']

cy.get(`.e2e-theme-content #attrs + ul > li`).each((el, index) => {
cy.wrap(el).within(() => {
cy.get('a').should('have.attr', attrName[index % 4], attrValue[index % 4])
})
})

cy.get(`.e2e-theme-content #slots + ul > li`).each((el, index) => {
cy.wrap(el).within(() => {
cy.get('a')
.children()
.should('have.lengthOf', (index % 2) + 1)
.each((el) => {
cy.wrap(el).contains('span', 'text')
})
})
})

const HASH_AND_QUERY_RESULTS = [
`${E2E_BASE}#hash`,
`${E2E_BASE}?query`,
`${E2E_BASE}?query#hash`,
`${E2E_BASE}?query=1#hash`,
`${E2E_BASE}?query=1&query=2#hash`,
`${E2E_BASE}#hash?query=1&query=2`,
`${E2E_BASE}#hash`,
`${E2E_BASE}?query`,
`${E2E_BASE}?query#hash`,
`${E2E_BASE}?query=1#hash`,
`${E2E_BASE}?query=1&query=2#hash`,
`${E2E_BASE}#hash?query=1&query=2`,
`#hash`,
`?query`,
`?query#hash`,
`?query=1#hash`,
`?query=1&query=2#hash`,
`#hash?query=1&query=2`,
]

cy.get(`.e2e-theme-content #hash-and-query + ul > li`).each((el, index) => {
cy.wrap(el).within(() => {
cy.get('a').should('have.attr', 'href', HASH_AND_QUERY_RESULTS[index])
})
})

const RELATIVE_RESULTS = [
E2E_BASE,
`${E2E_BASE}404.html`,
`${E2E_BASE}components/not-exist.html`,
]

cy.get(`.e2e-theme-content #relative + ul > li`).each((el, index) => {
cy.wrap(el).within(() => {
cy.get('a').should('have.attr', 'href', RELATIVE_RESULTS[index % 3])
})
})
})
Loading

0 comments on commit d643daa

Please sign in to comment.