|
| 1 | +import { expect, test } from '@playwright/test' |
| 2 | +import { BASE } from '../../utils/env' |
| 3 | + |
| 4 | +test.beforeEach(async ({ page }) => { |
| 5 | + await page.goto('router/navigate-by-link.html') |
| 6 | +}) |
| 7 | + |
| 8 | +test.describe('markdown links', () => { |
| 9 | + test('should navigate to home correctly', async ({ page }) => { |
| 10 | + await page.locator('#markdown-links + ul > li > a').nth(0).click() |
| 11 | + await expect(page).toHaveURL(`${BASE}`) |
| 12 | + await expect(page.locator('#home-h2')).toHaveText('Home H2') |
| 13 | + }) |
| 14 | + |
| 15 | + test('should navigate to 404 page correctly', async ({ page }) => { |
| 16 | + await page.locator('#markdown-links + ul > li > a').nth(1).click() |
| 17 | + await expect(page).toHaveURL(`${BASE}404.html`) |
| 18 | + await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2') |
| 19 | + }) |
| 20 | + |
| 21 | + test('should preserve query', async ({ page }) => { |
| 22 | + await page.locator('#markdown-links + ul > li > a').nth(2).click() |
| 23 | + await expect(page).toHaveURL(`${BASE}?home=true`) |
| 24 | + await expect(page.locator('#home-h2')).toHaveText('Home H2') |
| 25 | + }) |
| 26 | + |
| 27 | + test('should preserve query and hash', async ({ page }) => { |
| 28 | + await page.locator('#markdown-links + ul > li > a').nth(3).click() |
| 29 | + await expect(page).toHaveURL(`${BASE}?home=true#home`) |
| 30 | + await expect(page.locator('#home-h2')).toHaveText('Home H2') |
| 31 | + }) |
| 32 | + |
| 33 | + test('should preserve hash', async ({ page }) => { |
| 34 | + await page.locator('#markdown-links + ul > li > a').nth(4).click() |
| 35 | + await expect(page).toHaveURL(`${BASE}404.html#404`) |
| 36 | + await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2') |
| 37 | + }) |
| 38 | + |
| 39 | + test('should preserve hash and query', async ({ page }) => { |
| 40 | + await page.locator('#markdown-links + ul > li > a').nth(5).click() |
| 41 | + await expect(page).toHaveURL(`${BASE}404.html#404?notFound=true`) |
| 42 | + await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2') |
| 43 | + }) |
| 44 | +}) |
| 45 | + |
| 46 | +test.describe('html links', () => { |
| 47 | + test('should navigate to home correctly', async ({ page }) => { |
| 48 | + await page.locator('#html-links + p > a').nth(0).click() |
| 49 | + await expect(page).toHaveURL(`${BASE}`) |
| 50 | + await expect(page.locator('#home-h2')).toHaveText('Home H2') |
| 51 | + }) |
| 52 | + |
| 53 | + test('should navigate to 404 page correctly', async ({ page }) => { |
| 54 | + await page.locator('#html-links + p > a').nth(1).click() |
| 55 | + await expect(page).toHaveURL(`${BASE}404.html`) |
| 56 | + await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2') |
| 57 | + }) |
| 58 | + |
| 59 | + test('should preserve query', async ({ page }) => { |
| 60 | + await page.locator('#html-links + p > a').nth(2).click() |
| 61 | + await expect(page).toHaveURL(`${BASE}?home=true`) |
| 62 | + await expect(page.locator('#home-h2')).toHaveText('Home H2') |
| 63 | + }) |
| 64 | + |
| 65 | + test('should preserve query and hash', async ({ page }) => { |
| 66 | + await page.locator('#html-links + p > a').nth(3).click() |
| 67 | + await expect(page).toHaveURL(`${BASE}?home=true#home`) |
| 68 | + await expect(page.locator('#home-h2')).toHaveText('Home H2') |
| 69 | + }) |
| 70 | + |
| 71 | + test('should preserve hash', async ({ page }) => { |
| 72 | + await page.locator('#html-links + p > a').nth(4).click() |
| 73 | + await expect(page).toHaveURL(`${BASE}404.html#404`) |
| 74 | + await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2') |
| 75 | + }) |
| 76 | + |
| 77 | + test('should preserve hash and query', async ({ page }) => { |
| 78 | + await page.locator('#html-links + p > a').nth(5).click() |
| 79 | + await expect(page).toHaveURL(`${BASE}404.html#404?notFound=true`) |
| 80 | + await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2') |
| 81 | + }) |
| 82 | +}) |
| 83 | + |
| 84 | +test.describe('markdown links with html paths', () => { |
| 85 | + test('should navigate to home correctly', async ({ page }) => { |
| 86 | + const locator = page |
| 87 | + .locator('#markdown-links-with-html-paths + ul > li > a') |
| 88 | + .nth(0) |
| 89 | + if (BASE === '/') { |
| 90 | + await locator.click() |
| 91 | + await expect(page).toHaveURL('/') |
| 92 | + await expect(page.locator('#home-h2')).toHaveText('Home H2') |
| 93 | + } else { |
| 94 | + await expect(locator).toHaveAttribute('href', '/') |
| 95 | + await expect(locator).toHaveAttribute('target', '_blank') |
| 96 | + } |
| 97 | + }) |
| 98 | +}) |
0 commit comments