Skip to content

Commit 9503285

Browse files
test: add e2e tests for RouteLink (#1487)
Co-authored-by: Xinyu Liu <[email protected]>
1 parent d4dbcc6 commit 9503285

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed

e2e/docs/components/route-link.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## RouteLink
2+
3+
### Home Page
4+
5+
- <RouteLink to="/">text</RouteLink>
6+
- <RouteLink to="/README.md">text</RouteLink>
7+
- <RouteLink to="/index.html">text</RouteLink>
8+
9+
### Non-Existent
10+
11+
- <RouteLink to="/non-existent">text</RouteLink>
12+
- <RouteLink to="/non-existent.md">text</RouteLink>
13+
- <RouteLink to="/non-existent.html">text</RouteLink>
14+
15+
### Non-ASCII
16+
17+
- <RouteLink to="/routes/non-ascii-paths/中文目录名/中文文件名">text</RouteLink>
18+
- <RouteLink to="/routes/non-ascii-paths/中文目录名/中文文件名.md">text</RouteLink>
19+
- <RouteLink to="/routes/non-ascii-paths/中文目录名/中文文件名.html">text</RouteLink>
20+
21+
### Non-ASCII Encoded
22+
23+
- <RouteLink :to="encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名')">text</RouteLink>
24+
- <RouteLink :to="encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名.md')">text</RouteLink>
25+
- <RouteLink :to="encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名.html')">text</RouteLink>
26+
27+
### Active
28+
29+
- <RouteLink to="/README.md" active="">text</RouteLink>
30+
- <RouteLink to="/README.md" active>text</RouteLink>
31+
- <RouteLink to="/README.md" :active="false">text</RouteLink>
32+
- <RouteLink to="/README.md">text</RouteLink>
33+
34+
### Class
35+
36+
- <RouteLink to="/README.md" class="custom-class">text</RouteLink>
37+
- <RouteLink to="/README.md" active class="custom-class">text</RouteLink>
38+
39+
### Attrs
40+
41+
- <RouteLink to="/README.md" title="Title">text</RouteLink>
42+
- <RouteLink to="/README.md" target="_blank">text</RouteLink>
43+
- <RouteLink to="/README.md" rel="noopener">text</RouteLink>
44+
- <RouteLink to="/README.md" aria-label="test">text</RouteLink>
45+
46+
### Slots
47+
48+
- <RouteLink to="/README.md"><span>text</span></RouteLink>
49+
- <RouteLink to="/README.md"><span>text</span><span>text</span></RouteLink>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
it('RouteLink', () => {
2+
const E2E_BASE = Cypress.env('E2E_BASE')
3+
4+
cy.visit('/components/route-link.html')
5+
6+
cy.get(`.e2e-theme-content #home-page + ul > li`).each((el) => {
7+
cy.wrap(el).within(() => {
8+
cy.get('a').should('have.attr', 'href', E2E_BASE)
9+
cy.get('a').should('have.text', 'text')
10+
})
11+
})
12+
13+
cy.get(`.e2e-theme-content #non-existent + ul > li`).each((el) => {
14+
cy.wrap(el).within(() => {
15+
cy.get('a').should('have.attr', 'href', `${E2E_BASE}non-existent.html`)
16+
cy.get('a').should('have.text', 'text')
17+
})
18+
})
19+
20+
cy.get(`.e2e-theme-content #non-ascii + ul > li`).each((el) => {
21+
cy.wrap(el).within(() => {
22+
cy.get('a').should(
23+
'have.attr',
24+
'href',
25+
encodeURI(
26+
`${E2E_BASE}routes/non-ascii-paths/中文目录名/中文文件名.html`,
27+
),
28+
)
29+
cy.get('a').should('have.text', 'text')
30+
})
31+
})
32+
33+
cy.get(`.e2e-theme-content #non-ascii-encoded + ul > li`).each((el) => {
34+
cy.wrap(el).within(() => {
35+
cy.get('a').should(
36+
'have.attr',
37+
'href',
38+
encodeURI(
39+
`${E2E_BASE}routes/non-ascii-paths/中文目录名/中文文件名.html`,
40+
),
41+
)
42+
cy.get('a').should('have.text', 'text')
43+
})
44+
})
45+
46+
cy.get(`.e2e-theme-content #active + ul > li`).each((el, index) => {
47+
cy.wrap(el).within(() => {
48+
if (index < 2) {
49+
cy.get('a').should('have.attr', 'class', 'route-link route-link-active')
50+
} else {
51+
cy.get('a').should('have.attr', 'class', 'route-link')
52+
}
53+
cy.get('a').should('have.text', 'text')
54+
})
55+
})
56+
57+
const classResults = [
58+
'route-link custom-class',
59+
'route-link route-link-active custom-class',
60+
]
61+
cy.get(`.e2e-theme-content #class + ul > li`).each((el, index) => {
62+
cy.wrap(el).within(() => {
63+
cy.get('a').should('have.attr', 'class', classResults[index])
64+
cy.get('a').should('have.text', 'text')
65+
})
66+
})
67+
68+
const attrName = ['title', 'target', 'rel', 'aria-label']
69+
const attrValue = ['Title', '_blank', 'noopener', 'test']
70+
71+
cy.get(`.e2e-theme-content #attrs + ul > li`).each((el, index) => {
72+
cy.wrap(el).within(() => {
73+
cy.get('a').should('have.attr', attrName[index], attrValue[index])
74+
})
75+
})
76+
77+
cy.get(`.e2e-theme-content #slots + ul > li`).each((el, index) => {
78+
cy.wrap(el).within(() => {
79+
cy.get('a')
80+
.children()
81+
.should('have.lengthOf', index + 1)
82+
.each((el) => {
83+
cy.wrap(el).contains('span', 'text')
84+
})
85+
})
86+
})
87+
})

packages/client/src/components/RouteLink.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,8 @@ export const RouteLink: FunctionalComponent<
8181
}
8282

8383
RouteLink.displayName = 'RouteLink'
84+
RouteLink.props = {
85+
active: Boolean,
86+
activeClass: String,
87+
to: String,
88+
}

0 commit comments

Comments
 (0)