From c72ad207f9c764ffd406d5dfcbc2c5e3dcdd8694 Mon Sep 17 00:00:00 2001 From: Mister-Hope Date: Fri, 24 May 2024 12:47:27 +0800 Subject: [PATCH] test: add e2e tests --- e2e/docs/router/navigate-by-link.md | 21 +++++- e2e/tests/router/navigate-by-link.spec.ts | 81 ++++++++++++++++++++++- 2 files changed, 98 insertions(+), 4 deletions(-) diff --git a/e2e/docs/router/navigate-by-link.md b/e2e/docs/router/navigate-by-link.md index cf873b4c07..6d28173095 100644 --- a/e2e/docs/router/navigate-by-link.md +++ b/e2e/docs/router/navigate-by-link.md @@ -1 +1,20 @@ - +## 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 + +- [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 + +Home +Home +404 +404 diff --git a/e2e/tests/router/navigate-by-link.spec.ts b/e2e/tests/router/navigate-by-link.spec.ts index dd3436b404..a2076b0dd2 100644 --- a/e2e/tests/router/navigate-by-link.spec.ts +++ b/e2e/tests/router/navigate-by-link.spec.ts @@ -5,7 +5,82 @@ test.beforeEach(async ({ page }) => { await page.goto('router/navigate-by-link.html') }) -test('TODO', async ({ page }) => { - // TODO - await expect(page).toHaveURL(`${BASE}router/navigate-by-link.html`) +test.describe('should preserve query', () => { + test('markdown links with html suffix', async ({ page }) => { + await page.locator('#markdown-links-with-html + ul > li > a').nth(0).click() + await expect(page).toHaveURL(`${BASE}?home=true`) + 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(0).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`) + await expect(page.locator('#home-h2')).toHaveText('Home H2') + }) +}) + +test.describe('should preserve query and hash', () => { + test('markdown links with html suffix', async ({ page }) => { + await page.locator('#markdown-links-with-html + ul > li > a').nth(1).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(1).click() + await expect(page).toHaveURL(`${BASE}?home=true#home`) + await expect(page.locator('#home-h2')).toHaveText('Home H2') + }) + + test('html links', async ({ page }) => { + await page.locator('#html-links + p > a').nth(1).click() + await expect(page).toHaveURL(`${BASE}?home=true#home`) + await expect(page.locator('#home-h2')).toHaveText('Home H2') + }) +}) + +test.describe('should preserve hash', () => { + test('markdown links with html suffix', async ({ page }) => { + await page.locator('#markdown-links-with-html + ul > li > a').nth(2).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(2).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`) + await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2') + }) +}) + +test.describe('should preserve hash and query', () => { + test('markdown links with html suffix', async ({ page }) => { + await page.locator('#markdown-links-with-html + 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('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') + }) })