|
1 | | -import { expect, test } from "@playwright/test"; |
| 1 | +import { expect, Page, test } from "@playwright/test"; |
2 | 2 | import { getUrl } from "../src/utils"; |
3 | 3 |
|
4 | 4 | const testPages = { |
@@ -28,41 +28,39 @@ Object.entries(testPages).forEach(([postDir, pageName]) => { |
28 | 28 | await expect(page.getByRole('link', { name: 'Welcome To My Blog' })).toBeHidden(); |
29 | 29 | }); |
30 | 30 |
|
| 31 | + const checkCategoryLink = async (page: Page, category: string, pageName: string) => { |
| 32 | + await page.getByText(category, { exact: true }).click(); |
| 33 | + await expect(page).toHaveURL(getUrl(`blog/simple-blog/_site/${pageName}#category=${encodeURIComponent(category)}`)); |
| 34 | + await expect(page.locator(`div.category[data-category="${btoa(encodeURIComponent(category))}"]`)).toHaveClass(/active/); |
| 35 | + }; |
| 36 | + |
31 | 37 | test(`All Categories links are clickable ${postDir} pages`, |
32 | 38 | async ({ page }) => { |
33 | | - const checkCategoryLink = async (category: string, pageName: string) => { |
34 | | - await page.getByRole('link', { name: category }).click(); |
35 | | - await expect(page).toHaveURL(getUrl(`blog/simple-blog/_site/${pageName}#category=${encodeURIComponent(category)}`)); |
36 | | - await expect(page.locator(`div.category[data-category="${btoa(encodeURIComponent(category))}"]`)).toHaveClass(/active/); |
37 | | - }; |
38 | 39 | // Checking link is working |
39 | 40 | await page.goto(`./blog/simple-blog/_site/${postDir}/welcome/`); |
40 | | - await checkCategoryLink('news', pageName); |
| 41 | + await checkCategoryLink(page, 'news', pageName); |
41 | 42 | // Including for special characters |
42 | 43 | await page.getByRole('link', { name: 'Welcome To My Blog' }).click(); |
43 | | - await checkCategoryLink('euros (€)', pageName); |
| 44 | + await checkCategoryLink(page, 'euros (€)', pageName); |
44 | 45 | await page.getByRole('link', { name: 'Welcome To My Blog' }).click(); |
45 | | - await checkCategoryLink('免疫', pageName); |
| 46 | + await checkCategoryLink(page, '免疫', pageName); |
46 | 47 | await page.goto(`./blog/simple-blog/_site/${postDir}/post-with-code/`); |
47 | | - await checkCategoryLink("apos'trophe", pageName); |
| 48 | + await checkCategoryLink(page, "apos'trophe", pageName); |
48 | 49 | // special check for when a page is not loaded from non root path |
49 | 50 | await page.goto(`./blog/simple-blog/_site/${postDir}/welcome/#img-lst`); |
50 | | - await checkCategoryLink('news', pageName); |
| 51 | + await checkCategoryLink(page, 'news', pageName); |
51 | 52 | }); |
52 | 53 |
|
53 | 54 | if (pageName !== 'table.html') { |
54 | 55 | test(`Categories link on listing page works for ${pageName}`, async ({ page }) => { |
55 | | - const checkCategoryLink = async (category: string, pageName: string) => { |
56 | | - await page.goto(`./blog/simple-blog/_site/${pageName}`); |
57 | | - await page.getByText(category, { exact: true }).click(); |
58 | | - await expect(page).toHaveURL(getUrl(`blog/simple-blog/_site/${pageName}#category=${encodeURIComponent(category)}`)); |
59 | | - await expect(page.locator(`div.category[data-category="${btoa(encodeURIComponent(category))}"]`)).toHaveClass(/active/); |
60 | | - }; |
61 | | - await checkCategoryLink('apos\'trophe', pageName); |
| 56 | + await page.goto(`./blog/simple-blog/_site/${pageName}`); |
| 57 | + await checkCategoryLink(page, 'apos\'trophe', pageName); |
62 | 58 | await expect(page.getByRole('link', { name: 'Post With Code' })).toBeVisible(); |
63 | | - await checkCategoryLink('euros (€)', pageName); |
| 59 | + await page.goto(`./blog/simple-blog/_site/${pageName}`); |
| 60 | + await checkCategoryLink(page, 'euros (€)', pageName); |
64 | 61 | await expect(page.getByRole('link', { name: 'Welcome To My Blog' })).toBeVisible(); |
65 | | - await checkCategoryLink('免疫', pageName); |
| 62 | + await page.goto(`./blog/simple-blog/_site/${pageName}`); |
| 63 | + await checkCategoryLink(page, '免疫', pageName); |
66 | 64 | await expect(page.getByRole('link', { name: 'Welcome To My Blog' })).toBeVisible(); |
67 | 65 | }); |
68 | 66 | } |
|
0 commit comments