Skip to content

Commit

Permalink
chore: update e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Dec 29, 2023
1 parent cc44ec9 commit 2d5bac1
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 99 deletions.
38 changes: 0 additions & 38 deletions e2e/docs/router.md

This file was deleted.

13 changes: 13 additions & 0 deletions e2e/docs/routes/get-pages-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## GetPagesPath

<ul>
<li v-for="path in pagesPath">
{{path}}
</li>
</ul>

<script setup>
import { getPagesPath } from 'vuepress/client'

const pagesPath = getPagesPath();
</script>
18 changes: 18 additions & 0 deletions e2e/docs/routes/is-page-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# isPageExist

- /: {{isPageExist('/')}}
- /README.md: {{isPageExist('/README.md')}}
- /index.html: {{isPageExist('/index.html')}}
- /not-exist: {{isPageExist('/not-exist')}}
- /not-exist.html: {{isPageExist('/not-exist.html')}}
- /not-exist.md: {{isPageExist('/not-exist.md')}}
- /routes/non-ascii-paths/中文目录名/中文文件名.md: {{isPageExist('/routes/non-ascii-paths/中文目录名/中文文件名.md')}}
- /routes/non-ascii-paths/中文目录名/中文文件名.html: {{isPageExist('/routes/non-ascii-paths/中文目录名/中文文件名.html')}}
- {{encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名.md')}}: {{isPageExist(encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名.md'))}}
- {{encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名.html')}}: {{isPageExist(encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名.html'))}}
- /zh/: {{isPageExist('/zh/')}}
- /zh: {{isPageExist('/zh')}}

<script setup>
import { isPageExist } from 'vuepress/client'
</script>
9 changes: 9 additions & 0 deletions e2e/docs/routes/resolve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## resolve

- Clean url: {{JSON.stringify(resolve('/page-data/meta'))}}
- HTML: {{JSON.stringify(resolve('/page-data/meta.html'))}}
- Markdown: {{JSON.stringify(resolve('/page-data/meta.md'))}}

<script setup>
import { resolve } from 'vuepress/client'
</script>
61 changes: 0 additions & 61 deletions e2e/tests/router.cy.ts

This file was deleted.

45 changes: 45 additions & 0 deletions e2e/tests/routes/get-pages-path.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
it('getPagesPath', () => {
cy.visit('/routes/get-pages-path.html')

const paths = [
'/',
// '/layouts/custom-layout.html',
// '/layouts/layout.html',
// '/markdown/anchors.html',
// '/markdown/code-blocks.html',
// '/markdown/emoji.html',
// '/markdown/import-code-blocks.html',
// '/markdown/links/bar.html',
// '/markdown/links/baz.html',
// '/markdown/links/foo.html',
// '/markdown/toc.html',
// '/markdown/vue-components.html',
// '/page-data/frontmatter.html',
// '/page-data/headers.html',
// '/page-data/lang.html',
// '/page-data/meta.html',
// '/page-data/permalink.html',
// '/page-data/title-from-frontmatter.html',
// '/page-data/title-from-h1.html',
// '/routes/non-ascii-paths/',
// '/routes/non-ascii-paths/%E4%B8%AD%E6%96%87%E7%9B%AE%E5%BD%95%E5%90%8D/%E4%B8%AD%E6%96%87%E6%96%87%E4%BB%B6%E5%90%8D.html',
// '/routes/get-pages-path.html',
// '/routes/resolve.html',
// '/routes/is-page-exist.html',
// '/zh/',
// '/404.html',
]

const pagePaths: string[] = []

// eslint-disable-next-line cypress/unsafe-to-chain-command
cy.get('.e2e-theme-content ul li')
.each((el) => {
pagePaths.push(el.text())
})
.then(() => {
paths.forEach((path) => {
expect(pagePaths.includes(path)).to.equal(true)
})
})
})
22 changes: 22 additions & 0 deletions e2e/tests/routes/is-page-exisit.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
it('isPageExist', () => {
cy.visit('/routes/is-page-exist.html')

const results = [
'/: true',
'/README.md: true',
'/index.html: true',
'/not-exist: false',
'/not-exist.html: false',
'/not-exist.md: false',
'/routes/non-ascii-paths/中文目录名/中文文件名.md: true',
'/routes/non-ascii-paths/中文目录名/中文文件名.html: true',
`${encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名.md')}: true`,
`${encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名.html')}: true`,
'/zh/: true',
'/zh: false',
]

cy.get('.e2e-theme-content ul li').each((el) => {
expect(results.includes(el.text())).to.equal(true)
})
})
8 changes: 8 additions & 0 deletions e2e/tests/routes/resolve.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
it('resolve', () => {
cy.visit('/routes/resolve.html')
const result = { path: '/page-data/meta.html', meta: { a: 0, b: 2, c: 3 } }

cy.get('.e2e-theme-content ul li').each((el) => {
expect(el.text()).to.contain(JSON.stringify(result))
})
})

0 comments on commit 2d5bac1

Please sign in to comment.