Skip to content

Commit d26921e

Browse files
committed
test: add e2e tests
1 parent 2fa1f5f commit d26921e

File tree

4 files changed

+156
-37
lines changed

4 files changed

+156
-37
lines changed

e2e/docs/router/navigate-by-link.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,23 @@
1212
- [404 with hash](/404.md#404)
1313
- [404 with hash and query](/404.md#404?notFound=true)
1414

15-
## HTML Links
15+
## Markdown Clean Links
16+
17+
- [Home with query](/?home=true)
18+
- [Home with query and hash](/?home=true#home)
19+
- [404 with hash](/404#404)
20+
- [404 with hash and query](/404#404?notFound=true)
21+
22+
## HTML Full Links
1623

1724
<a href="/?home=true" class="home-with-query">Home</a>
1825
<a href="/?home=true#home" class="home-with-query-and-hash">Home</a>
1926
<a href="/404.html#404" class="not-found-with-hash">404</a>
2027
<a href="/404.html#404?notFound=true" class="not-found-with-hash-and-query">404</a>
28+
29+
## HTML Clean Links
30+
31+
<a href="/?home=true" class="home-with-query">Home</a>
32+
<a href="/?home=true#home" class="home-with-query-and-hash">Home</a>
33+
<a href="/404#404" class="not-found-with-hash">404</a>
34+
<a href="/404#404?notFound=true" class="not-found-with-hash-and-query">404</a>

e2e/docs/router/navigate-by-router.md

+37-12
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,51 @@
1-
<button id="home-with-query" @click="goHomeWithQuery">Home</button>
2-
<button id="home-with-query-and-hash" @click="goHomeWithQueryAndHash">Home</button>
3-
<button id="not-found-with-hash" @click="go404WithHash">404</button>
4-
<button id="not-found-with-hash-and-query" @click="go404WithHashAndQuery">404</button>
1+
<div id="full">
2+
<button class="home-with-query" @click="goHomeWithQuery">Home</button>
3+
<button class="home-with-query-and-hash" @click="goHomeWithQueryAndHash">Home</button>
4+
<button class="not-found-with-hash" @click="go404WithHash">404</button>
5+
<button class="not-found-with-hash-and-query" @click="go404WithHashAndQuery">404</button>
6+
</div>
7+
8+
<div id="clean">
9+
<button class="home-with-query" @click="goHomeWithQuery">Home</button>
10+
<button class="home-with-query-and-hash" @click="goHomeWithQueryAndHash">Home</button>
11+
<button class="not-found-with-hash" @click="go404WithHash">404</button>
12+
<button class="not-found-with-hash-and-query" @click="go404WithHashAndQuery">404</button>
13+
</div>
514

615
<script setup lang="ts">
716
import { useRouter } from 'vuepress/client';
817

918
const router = useRouter();
1019

11-
const goHomeWithQuery = () => {
12-
router.push('/?home=true');
20+
const goHomeWithQuery = (event) => {
21+
if (event.currentTarget.parentElement.id === 'full') {
22+
router.push('/index.html?home=true');
23+
} else {
24+
router.push('/?home=true');
25+
}
1326
}
1427

15-
const goHomeWithQueryAndHash = () => {
16-
router.push('/?home=true#home');
28+
const goHomeWithQueryAndHash = (event) => {
29+
if (event.currentTarget.parentElement.id === 'full') {
30+
router.push('/index.html?home=true#home');
31+
} else {
32+
router.push('/?home=true#home');
33+
}
1734
}
1835

19-
const go404WithHash = () => {
20-
router.push('/404.html#404');
36+
const go404WithHash = (event) => {
37+
if (event.currentTarget.parentElement.id === 'full') {
38+
router.push('/404.html#404');
39+
} else {
40+
router.push('/404#404');
41+
}
2142
}
2243

23-
const go404WithHashAndQuery = () => {
24-
router.push('/404.html#404?notFound=true');
44+
const go404WithHashAndQuery = (event) => {
45+
if (event.currentTarget.parentElement.id === 'full') {
46+
router.push('/404.html#404?notFound=true');
47+
} else {
48+
router.push('/404#404?notFound=true');
49+
}
2550
}
2651
</script>

e2e/tests/router/navigate-by-link.spec.ts

+56-8
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,20 @@ test.describe('should preserve query', () => {
1818
await expect(page.locator('#home-h2')).toHaveText('Home H2')
1919
})
2020

21-
test('html links', async ({ page }) => {
22-
await page.locator('#html-links + p > a').nth(0).click()
21+
test('markdown clean links', async ({ page }) => {
22+
await page.locator('#markdown-clean-links + ul > li > a').nth(0).click()
23+
await expect(page).toHaveURL(`${BASE}?home=true`)
24+
await expect(page.locator('#home-h2')).toHaveText('Home H2')
25+
})
26+
27+
test('html full links', async ({ page }) => {
28+
await page.locator('#html-full-links + p > a').nth(0).click()
29+
await expect(page).toHaveURL(`${BASE}?home=true`)
30+
await expect(page.locator('#home-h2')).toHaveText('Home H2')
31+
})
32+
33+
test('html clean links', async ({ page }) => {
34+
await page.locator('#html-clean-links + p > a').nth(0).click()
2335
await expect(page).toHaveURL(`${BASE}?home=true`)
2436
await expect(page.locator('#home-h2')).toHaveText('Home H2')
2537
})
@@ -38,8 +50,20 @@ test.describe('should preserve query and hash', () => {
3850
await expect(page.locator('#home-h2')).toHaveText('Home H2')
3951
})
4052

41-
test('html links', async ({ page }) => {
42-
await page.locator('#html-links + p > a').nth(1).click()
53+
test('markdown clean links', async ({ page }) => {
54+
await page.locator('#markdown-clean-links + ul > li > a').nth(1).click()
55+
await expect(page).toHaveURL(`${BASE}?home=true#home`)
56+
await expect(page.locator('#home-h2')).toHaveText('Home H2')
57+
})
58+
59+
test('html full links', async ({ page }) => {
60+
await page.locator('#html-full-links + p > a').nth(1).click()
61+
await expect(page).toHaveURL(`${BASE}?home=true#home`)
62+
await expect(page.locator('#home-h2')).toHaveText('Home H2')
63+
})
64+
65+
test('html clean links', async ({ page }) => {
66+
await page.locator('#html-clean-links + p > a').nth(1).click()
4367
await expect(page).toHaveURL(`${BASE}?home=true#home`)
4468
await expect(page.locator('#home-h2')).toHaveText('Home H2')
4569
})
@@ -58,8 +82,20 @@ test.describe('should preserve hash', () => {
5882
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
5983
})
6084

61-
test('html links', async ({ page }) => {
62-
await page.locator('#html-links + p > a').nth(2).click()
85+
test('markdown clean links', async ({ page }) => {
86+
await page.locator('#markdown-clean-links + ul > li > a').nth(2).click()
87+
await expect(page).toHaveURL(`${BASE}404.html#404`)
88+
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
89+
})
90+
91+
test('html full links', async ({ page }) => {
92+
await page.locator('#html-full-links + p > a').nth(2).click()
93+
await expect(page).toHaveURL(`${BASE}404.html#404`)
94+
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
95+
})
96+
97+
test('html clean links', async ({ page }) => {
98+
await page.locator('#html-clean-links + p > a').nth(2).click()
6399
await expect(page).toHaveURL(`${BASE}404.html#404`)
64100
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
65101
})
@@ -78,8 +114,20 @@ test.describe('should preserve hash and query', () => {
78114
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
79115
})
80116

81-
test('html links', async ({ page }) => {
82-
await page.locator('#html-links + p > a').nth(3).click()
117+
test('markdown clean links', async ({ page }) => {
118+
await page.locator('#markdown-clean-links + ul > li > a').nth(3).click()
119+
await expect(page).toHaveURL(`${BASE}404.html#404?notFound=true`)
120+
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
121+
})
122+
123+
test('html full links', async ({ page }) => {
124+
await page.locator('#html-full-links + p > a').nth(3).click()
125+
await expect(page).toHaveURL(`${BASE}404.html#404?notFound=true`)
126+
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
127+
})
128+
129+
test('html clean links', async ({ page }) => {
130+
await page.locator('#html-clean-links + p > a').nth(3).click()
83131
await expect(page).toHaveURL(`${BASE}404.html#404?notFound=true`)
84132
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
85133
})

e2e/tests/router/navigate-by-router.spec.ts

+48-16
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,58 @@ test.beforeEach(async ({ page }) => {
55
await page.goto('router/navigate-by-router.html')
66
})
77

8-
test('should preserve query', async ({ page }) => {
9-
await page.locator('#home-with-query').click()
10-
await expect(page).toHaveURL(`${BASE}?home=true`)
11-
await expect(page.locator('#home-h2')).toHaveText('Home H2')
8+
test.describe('should preserve query', () => {
9+
test('full', async ({ page }) => {
10+
await page.locator('#full .home-with-query').click()
11+
await expect(page).toHaveURL(`${BASE}?home=true`)
12+
await expect(page.locator('#home-h2')).toHaveText('Home H2')
13+
})
14+
15+
test('clean', async ({ page }) => {
16+
await page.locator('#clean .home-with-query').click()
17+
await expect(page).toHaveURL(`${BASE}?home=true`)
18+
await expect(page.locator('#home-h2')).toHaveText('Home H2')
19+
})
1220
})
1321

14-
test('should preserve query and hash', async ({ page }) => {
15-
await page.locator('#home-with-query-and-hash').click()
16-
await expect(page).toHaveURL(`${BASE}?home=true#home`)
17-
await expect(page.locator('#home-h2')).toHaveText('Home H2')
22+
test.describe('should preserve query and hash', () => {
23+
test('full', async ({ page }) => {
24+
await page.locator('#full .home-with-query-and-hash').click()
25+
await expect(page).toHaveURL(`${BASE}?home=true#home`)
26+
await expect(page.locator('#home-h2')).toHaveText('Home H2')
27+
})
28+
29+
test('clean', async ({ page }) => {
30+
await page.locator('#clean .home-with-query-and-hash').click()
31+
await expect(page).toHaveURL(`${BASE}?home=true#home`)
32+
await expect(page.locator('#home-h2')).toHaveText('Home H2')
33+
})
1834
})
1935

20-
test('should preserve hash', async ({ page }) => {
21-
await page.locator('#not-found-with-hash').click()
22-
await expect(page).toHaveURL(`${BASE}404.html#404`)
23-
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
36+
test.describe('should preserve hash', () => {
37+
test('full', async ({ page }) => {
38+
await page.locator('#full .not-found-with-hash').click()
39+
await expect(page).toHaveURL(`${BASE}404.html#404`)
40+
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
41+
})
42+
43+
test('clean', async ({ page }) => {
44+
await page.locator('#clean .not-found-with-hash').click()
45+
await expect(page).toHaveURL(`${BASE}404.html#404`)
46+
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
47+
})
2448
})
2549

26-
test('should preserve hash and query', async ({ page }) => {
27-
await page.locator('#not-found-with-hash-and-query').click()
28-
await expect(page).toHaveURL(`${BASE}404.html#404?notFound=true`)
29-
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
50+
test.describe('should preserve hash and query', () => {
51+
test('full', async ({ page }) => {
52+
await page.locator('#full .not-found-with-hash-and-query').click()
53+
await expect(page).toHaveURL(`${BASE}404.html#404?notFound=true`)
54+
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
55+
})
56+
57+
test('clean', async ({ page }) => {
58+
await page.locator('#clean .not-found-with-hash-and-query').click()
59+
await expect(page).toHaveURL(`${BASE}404.html#404?notFound=true`)
60+
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
61+
})
3062
})

0 commit comments

Comments
 (0)