Skip to content

Commit

Permalink
chore: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed May 27, 2024
1 parent c3655b1 commit 3b6c811
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 82 deletions.
24 changes: 16 additions & 8 deletions e2e/docs/router/navigate-by-link.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
## Markdown Links with html

- [Home with query](/?home=true)
- [Home with query and hash](/?home=true#home)
- [404 with hash](/404.html#404)
- [404 with hash and query](/404.html#404?notFound=true)

## Markdown Links with md
## Markdown Links

- [Home](/README.md)
- [404](/404.md)
- [Home with query](/README.md?home=true)
- [Home with query and hash](/README.md?home=true#home)
- [404 with hash](/404.md#404)
- [404 with hash and query](/404.md#404?notFound=true)

## HTML Links

<a :href="$withBase('/')" class="home">Home</a>
<a :href="$withBase('/404.html')" class="not-found">404</a>
<a :href="$withBase('/?home=true')" class="home-with-query">Home</a>
<a :href="$withBase('/?home=true#home')" class="home-with-query-and-hash">Home</a>
<a :href="$withBase('/404.html#404')" class="not-found-with-hash">404</a>
<a :href="$withBase('/404.html#404?notFound=true')" class="not-found-with-hash-and-query">404</a>

## Markdown Links with html paths

- [Home](/)
- [404](/404.html)
- [Home with query](/?home=true)
- [Home with query and hash](/?home=true#home)
- [404 with hash](/404.html#404)
- [404 with hash and query](/404.html#404?notFound=true)

> Non-recommended usage. HTML paths could not be prepended with `base` correctly.
11 changes: 11 additions & 0 deletions e2e/docs/router/navigate-by-router.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<button id="home" @click="goHome">Home</button>
<button id="not-found" @click="go404">404</button>

<button id="home-with-query" @click="goHomeWithQuery">Home</button>
<button id="home-with-query-and-hash" @click="goHomeWithQueryAndHash">Home</button>
<button id="not-found-with-hash" @click="go404WithHash">404</button>
Expand All @@ -8,6 +11,14 @@ import { useRouter } from 'vuepress/client';

const router = useRouter();

const goHome = () => {
router.push('/');
}

const go404 = () => {
router.push('/404.html');
}

const goHomeWithQuery = () => {
router.push('/?home=true');
}
Expand Down
132 changes: 58 additions & 74 deletions e2e/tests/router/navigate-by-link.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,110 +5,94 @@ test.beforeEach(async ({ page }) => {
await page.goto('router/navigate-by-link.html')
})

test.describe('should preserve query', () => {
test('markdown links with html suffix', async ({ page }) => {
const homeAnchor = page
.locator('#markdown-links-with-html + ul > li > a')
.nth(0)
if (BASE === '/') {
await homeAnchor.click()
await expect(page).toHaveURL('/?home=true')
await expect(page.locator('#home-h2')).toHaveText('Home H2')
} else {
expect(await homeAnchor.getAttribute('target')).toBe('_blank')
}
test.describe('markdown links', () => {
test('should navigate to home correctly', async ({ page }) => {
await page.locator('#markdown-links + ul > li > a').nth(0).click()
await expect(page).toHaveURL(`${BASE}`)
await expect(page.locator('#home-h2')).toHaveText('Home H2')
})

test('should navigate to 404 page correctly', async ({ page }) => {
await page.locator('#markdown-links + ul > li > a').nth(1).click()
await expect(page).toHaveURL(`${BASE}404.html`)
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
})

test('markdown links with md suffix', async ({ page }) => {
await page.locator('#markdown-links-with-md + ul > li > a').nth(0).click()
test('should preserve query', async ({ page }) => {
await page.locator('#markdown-links + ul > li > a').nth(2).click()
await expect(page).toHaveURL(`${BASE}?home=true`)
await expect(page.locator('#home-h2')).toHaveText('Home H2')
})

test('html links', async ({ page }) => {
await page.locator('#html-links + p > a').nth(0).click()
await expect(page).toHaveURL(`${BASE}?home=true`)
test('should preserve query and hash', async ({ page }) => {
await page.locator('#markdown-links + ul > li > a').nth(3).click()
await expect(page).toHaveURL(`${BASE}?home=true#home`)
await expect(page.locator('#home-h2')).toHaveText('Home H2')
})
})

test.describe('should preserve query and hash', () => {
test('markdown links with html suffix', async ({ page }) => {
const homeAnchor = page
.locator('#markdown-links-with-html + ul > li > a')
.nth(1)
if (BASE === '/') {
await homeAnchor.click()
await expect(page).toHaveURL('/?home=true#home')
await expect(page.locator('#home-h2')).toHaveText('Home H2')
} else {
expect(await homeAnchor.getAttribute('target')).toBe('_blank')
}
test('should preserve hash', async ({ page }) => {
await page.locator('#markdown-links + ul > li > a').nth(4).click()
await expect(page).toHaveURL(`${BASE}404.html#404`)
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
})

test('markdown links with md suffix', async ({ page }) => {
await page.locator('#markdown-links-with-md + ul > li > a').nth(1).click()
await expect(page).toHaveURL(`${BASE}?home=true#home`)
test('should preserve hash and query', async ({ page }) => {
await page.locator('#markdown-links + ul > li > a').nth(5).click()
await expect(page).toHaveURL(`${BASE}404.html#404?notFound=true`)
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
})
})

test.describe('html links', () => {
test('should navigate to home correctly', async ({ page }) => {
await page.locator('#html-links + p > a').nth(0).click()
await expect(page).toHaveURL(`${BASE}`)
await expect(page.locator('#home-h2')).toHaveText('Home H2')
})

test('html links', async ({ page }) => {
test('should navigate to 404 page correctly', async ({ page }) => {
await page.locator('#html-links + p > a').nth(1).click()
await expect(page).toHaveURL(`${BASE}?home=true#home`)
await expect(page).toHaveURL(`${BASE}404.html`)
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
})

test('should preserve query', async ({ page }) => {
await page.locator('#html-links + p > a').nth(2).click()
await expect(page).toHaveURL(`${BASE}?home=true`)
await expect(page.locator('#home-h2')).toHaveText('Home H2')
})
})

test.describe('should preserve hash', () => {
test('markdown links with html suffix', async ({ page }) => {
const notFound = page
.locator('#markdown-links-with-html + ul > li > a')
.nth(2)
if (BASE === '/') {
await notFound.click()
await expect(page).toHaveURL('/404.html#404')
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
} else {
expect(await notFound.getAttribute('target')).toBe('_blank')
}
test('should preserve query and hash', async ({ page }) => {
await page.locator('#html-links + p > a').nth(3).click()
await expect(page).toHaveURL(`${BASE}?home=true#home`)
await expect(page.locator('#home-h2')).toHaveText('Home H2')
})

test('markdown links with md suffix', async ({ page }) => {
await page.locator('#markdown-links-with-md + ul > li > a').nth(2).click()
test('should preserve hash', async ({ page }) => {
await page.locator('#html-links + p > a').nth(4).click()
await expect(page).toHaveURL(`${BASE}404.html#404`)
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
})

test('html links', async ({ page }) => {
await page.locator('#html-links + p > a').nth(2).click()
await expect(page).toHaveURL(`${BASE}404.html#404`)
test('should preserve hash and query', async ({ page }) => {
await page.locator('#html-links + p > a').nth(5).click()
await expect(page).toHaveURL(`${BASE}404.html#404?notFound=true`)
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
})
})

test.describe('should preserve hash and query', () => {
test('markdown links with html suffix', async ({ page }) => {
const notFound = page
.locator('#markdown-links-with-html + ul > li > a')
.nth(3)
test.describe('markdown links with html paths', () => {
test('should navigate to home correctly', async ({ page }) => {
const locator = page
.locator('#markdown-links-with-html-paths + ul > li > a')
.nth(0)
if (BASE === '/') {
await notFound.click()
await expect(page).toHaveURL('/404.html#404?notFound=true')
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
await locator.click()
await expect(page).toHaveURL('/')
await expect(page.locator('#home-h2')).toHaveText('Home H2')
} else {
expect(await notFound.getAttribute('target')).toBe('_blank')
await expect(locator).toHaveAttribute('href', '/')
await expect(locator).toHaveAttribute('target', '_blank')
}
})

test('markdown links with md suffix', async ({ page }) => {
await page.locator('#markdown-links-with-md + ul > li > a').nth(3).click()
await expect(page).toHaveURL(`${BASE}404.html#404?notFound=true`)
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
})

test('html links', async ({ page }) => {
await page.locator('#html-links + p > a').nth(3).click()
await expect(page).toHaveURL(`${BASE}404.html#404?notFound=true`)
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
})
})
12 changes: 12 additions & 0 deletions e2e/tests/router/navigate-by-router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ test.beforeEach(async ({ page }) => {
await page.goto('router/navigate-by-router.html')
})

test('should navigate to home correctly', async ({ page }) => {
await page.locator('#home').click()
await expect(page).toHaveURL(`${BASE}`)
await expect(page.locator('#home-h2')).toHaveText('Home H2')
})

test('should navigate to 404 page correctly', async ({ page }) => {
await page.locator('#not-found').click()
await expect(page).toHaveURL(`${BASE}404.html`)
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2')
})

test('should preserve query', async ({ page }) => {
await page.locator('#home-with-query').click()
await expect(page).toHaveURL(`${BASE}?home=true`)
Expand Down

0 comments on commit 3b6c811

Please sign in to comment.