Skip to content

Commit 24dd4ac

Browse files
committed
test: add e2e test
1 parent 7648075 commit 24dd4ac

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Resolve Route FullPath
2+
3+
## Includes Query And Hash
4+
5+
- Search Query: {{ JSON.stringify(resolveRoute('/?query=1')) }}
6+
- Hash: {{ JSON.stringify(resolveRoute('/#hash')) }}
7+
- Search Query And Hash: {{ JSON.stringify(resolveRoute('/?query=1#hash')) }}
8+
- Permalink And Search Query: {{ JSON.stringify(resolveRoute('/routes/permalinks/ascii-non-ascii.md?query=1')) }}
9+
10+
<script setup>
11+
import { resolveRoute } from 'vuepress/client'
12+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { expect, test } from '@playwright/test'
2+
3+
const testCases = [
4+
{
5+
path: '/?query=1',
6+
notFound: false,
7+
},
8+
{
9+
path: '/#hash',
10+
notFound: false,
11+
},
12+
{
13+
path: '/?query=1#hash',
14+
notFound: false,
15+
},
16+
{
17+
path: encodeURI('/永久链接-ascii-中文/?query=1'),
18+
notFound: false,
19+
},
20+
]
21+
22+
test('should resolve routes when including both the query and hash', async ({
23+
page,
24+
}) => {
25+
const listItemsLocator = await page
26+
.locator('.e2e-theme-content #includes-query-and-hash + ul > li')
27+
.all()
28+
29+
for (const [index, li] of listItemsLocator.entries()) {
30+
const textContent = await li.textContent()
31+
const resolvedRoute = JSON.parse(/: (\{.*\})\s*$/.exec(textContent!)![1])
32+
expect(resolvedRoute.path).toEqual(testCases[index].path)
33+
expect(resolvedRoute.notFound).toEqual(testCases[index].notFound)
34+
}
35+
})

0 commit comments

Comments
 (0)