Skip to content

Commit f3d6eb3

Browse files
committed
tests - factor out the helper functions for the tests
1 parent 8c16590 commit f3d6eb3

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

tests/integration/playwright/tests/blog-simple-blog.spec.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, test } from "@playwright/test";
1+
import { expect, Page, test } from "@playwright/test";
22
import { getUrl } from "../src/utils";
33

44
const testPages = {
@@ -28,41 +28,39 @@ Object.entries(testPages).forEach(([postDir, pageName]) => {
2828
await expect(page.getByRole('link', { name: 'Welcome To My Blog' })).toBeHidden();
2929
});
3030

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+
3137
test(`All Categories links are clickable ${postDir} pages`,
3238
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-
};
3839
// Checking link is working
3940
await page.goto(`./blog/simple-blog/_site/${postDir}/welcome/`);
40-
await checkCategoryLink('news', pageName);
41+
await checkCategoryLink(page, 'news', pageName);
4142
// Including for special characters
4243
await page.getByRole('link', { name: 'Welcome To My Blog' }).click();
43-
await checkCategoryLink('euros (€)', pageName);
44+
await checkCategoryLink(page, 'euros (€)', pageName);
4445
await page.getByRole('link', { name: 'Welcome To My Blog' }).click();
45-
await checkCategoryLink('免疫', pageName);
46+
await checkCategoryLink(page, '免疫', pageName);
4647
await page.goto(`./blog/simple-blog/_site/${postDir}/post-with-code/`);
47-
await checkCategoryLink("apos'trophe", pageName);
48+
await checkCategoryLink(page, "apos'trophe", pageName);
4849
// special check for when a page is not loaded from non root path
4950
await page.goto(`./blog/simple-blog/_site/${postDir}/welcome/#img-lst`);
50-
await checkCategoryLink('news', pageName);
51+
await checkCategoryLink(page, 'news', pageName);
5152
});
5253

5354
if (pageName !== 'table.html') {
5455
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);
6258
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);
6461
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);
6664
await expect(page.getByRole('link', { name: 'Welcome To My Blog' })).toBeVisible();
6765
});
6866
}

0 commit comments

Comments
 (0)