Skip to content

Commit

Permalink
Merge 366c223 into 8b1ab67
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Apr 17, 2024
2 parents 8b1ab67 + 366c223 commit 0f4eed4
Show file tree
Hide file tree
Showing 18 changed files with 802 additions and 166 deletions.
61 changes: 61 additions & 0 deletions e2e/docs/components/auto-link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# AutoLink

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

<div id="external-link">
<AutoLink v-for="item in externalLinksConfig" v-bind="item" />
</div>

<div id="config">
<AutoLink v-bind="{ text: 'text1', link: '/', ariaLabel: 'label' }" />
<AutoLink v-bind="{ text: 'text2', link: 'https://example.com/test/' }" />
</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 externalLinks = [
'//example.com',
'http://example.com',
'https://example.com',
'mailto:example@example.com',
'tel:+1234567890',
]

const externalLinksConfig = externalLinks.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>text2</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>
41 changes: 41 additions & 0 deletions e2e/tests/components/auto-link.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { expect, test } from '@playwright/test'
import { BASE } from '../../utils/env'

test.beforeEach(async ({ page }) => {
await page.goto('components/auto-link.html')
})

test('should render route-link correctly', async ({ page }) => {
for (const el of await page
.locator('.e2e-theme-content #route-link a')
.all()) {
await expect(el).toHaveAttribute('class', /route-link/)
}
})

test('should render external-link correctly', async ({ page }) => {
for (const el of await page
.locator('.e2e-theme-content #external-link a')
.all()) {
await expect(el).toHaveAttribute('class', /external-link/)
}
})

test('should render config correctly', async ({ page }) => {
const locator = page.locator('.e2e-theme-content #config a')

await expect(await locator.nth(0)).toHaveText('text1')
await expect(await locator.nth(0)).toHaveAttribute('href', BASE)
await expect(await locator.nth(0)).toHaveAttribute('aria-label', 'label')

await expect(await locator.nth(1)).toHaveText('text2')
await expect(await locator.nth(1)).toHaveAttribute(
'href',
'https://example.com/test/',
)
await expect(await locator.nth(1)).toHaveAttribute('target', '_blank')
await expect(await locator.nth(1)).toHaveAttribute(
'rel',
'noopener noreferrer',
)
})
53 changes: 53 additions & 0 deletions e2e/tests/components/route-link.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ test('should render active status correctly', async ({ page }) => {
const CONFIGS = [
'route-link route-link-active',
'route-link route-link-active',
'route-link route-link-active',
'route-link route-link-active',
'route-link',
'route-link',
'route-link',
'route-link',
]
Expand All @@ -53,6 +57,8 @@ test('should render class correctly', async ({ page }) => {
const CONFIGS = [
'route-link custom-class',
'route-link route-link-active custom-class',
'route-link custom-class',
'route-link route-link-active custom-class',
]

for (const [index, className] of CONFIGS.entries()) {
Expand Down Expand Up @@ -80,6 +86,22 @@ test('should render attributes correctly', async ({ page }) => {
attrName: 'aria-label',
attrValue: 'test',
},
{
attrName: 'title',
attrValue: 'Title',
},
{
attrName: 'target',
attrValue: '_blank',
},
{
attrName: 'rel',
attrValue: 'noopener',
},
{
attrName: 'aria-label',
attrValue: 'test',
},
]

for (const [index, { attrName, attrValue }] of CONFIGS.entries()) {
Expand All @@ -99,6 +121,14 @@ test('should render slots correctly', async ({ page }) => {
spansCount: 2,
spansText: ['text', 'text2'],
},
{
spansCount: 1,
spansText: ['text'],
},
{
spansCount: 2,
spansText: ['text', 'text2'],
},
]
for (const [index, { spansCount, spansText }] of CONFIGS.entries()) {
const children = await page
Expand All @@ -114,6 +144,12 @@ test('should render slots correctly', async ({ page }) => {

test('should render hash and query correctly', async ({ page }) => {
const CONFIGS = [
`${BASE}#hash`,
`${BASE}?query`,
`${BASE}?query#hash`,
`${BASE}?query=1#hash`,
`${BASE}?query=1&query=2#hash`,
`${BASE}#hash?query=1&query=2`,
`${BASE}#hash`,
`${BASE}?query`,
`${BASE}?query#hash`,
Expand All @@ -134,3 +170,20 @@ test('should render hash and query correctly', async ({ page }) => {
).toHaveAttribute('href', href)
}
})

test('should render relative links correctly', async ({ page }) => {
const CONFIGS = [
BASE,
`${BASE}404.html`,
`${BASE}components/not-exist.html`,
BASE,
`${BASE}404.html`,
`${BASE}components/not-exist.html`,
]

for (const [index, href] of CONFIGS.entries()) {
await expect(
page.locator('.e2e-theme-content #relative + ul > li a').nth(index),
).toHaveAttribute('href', href)
}
})

0 comments on commit 0f4eed4

Please sign in to comment.