Skip to content

Commit 98d98db

Browse files
authored
test(client): add test cases for AutoLink (#1555)
1 parent 0777d09 commit 98d98db

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

e2e/docs/components/auto-link.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
<AutoLink :config="{ text: 'text2', link: 'https://example.com/test/' }" />
1414
</div>
1515

16+
<div id="attrs">
17+
<AutoLink class="class" :config="{ text: 'text1', link: '/', ariaLabel: 'label', icon: 'icon1' }" />
18+
<AutoLink id="id" :config="{ text: 'text2', link: 'https://example.com/test/', unknown: 'value' }" />
19+
<AutoLink download="example-test.png" :config="{ text: 'text3', link: 'https://example.com/test.png' }" />
20+
</div>
21+
1622
<script setup lang="ts">
1723
import { AutoLink } from 'vuepress/client'
1824

e2e/tests/components/auto-link.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,32 @@ test('should render config correctly', async ({ page }) => {
3636
await expect(locator.nth(1)).toHaveAttribute('target', '_blank')
3737
await expect(locator.nth(1)).toHaveAttribute('rel', 'noopener noreferrer')
3838
})
39+
40+
test('should append attrs correctly', async ({ page }) => {
41+
const locator = page.locator('.e2e-theme-content #attrs a')
42+
43+
await expect(locator.nth(0)).toHaveText('text1')
44+
await expect(locator.nth(0)).toHaveAttribute('href', BASE)
45+
await expect(locator.nth(0)).toHaveAttribute('aria-label', 'label')
46+
await expect(locator.nth(0)).toHaveAttribute('class', /class/)
47+
await expect(locator.nth(0)).not.toHaveAttribute('icon')
48+
49+
await expect(locator.nth(1)).toHaveText('text2')
50+
await expect(locator.nth(1)).toHaveAttribute(
51+
'href',
52+
'https://example.com/test/',
53+
)
54+
await expect(locator.nth(1)).toHaveAttribute('target', '_blank')
55+
await expect(locator.nth(1)).toHaveAttribute('rel', 'noopener noreferrer')
56+
await expect(locator.nth(1)).toHaveAttribute('id', 'id')
57+
await expect(locator.nth(1)).not.toHaveAttribute('unknown')
58+
59+
await expect(locator.nth(2)).toHaveText('text3')
60+
await expect(locator.nth(2)).toHaveAttribute(
61+
'href',
62+
'https://example.com/test.png',
63+
)
64+
await expect(locator.nth(2)).toHaveAttribute('target', '_blank')
65+
await expect(locator.nth(2)).toHaveAttribute('rel', 'noopener noreferrer')
66+
await expect(locator.nth(2)).toHaveAttribute('download', 'example-test.png')
67+
})

packages/client/src/components/AutoLink.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ export interface AutoLinkConfig {
5151
export const AutoLink = defineComponent({
5252
name: 'AutoLink',
5353

54-
inheritAttrs: false,
55-
5654
props: {
5755
config: {
5856
type: Object as PropType<AutoLinkConfig>,

0 commit comments

Comments
 (0)