Skip to content

Commit eaf1ff7

Browse files
committed
test: implement multiple category selection in blog tests
1 parent 92e3008 commit eaf1ff7

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

tests/integration/playwright/tests/blog-categories-selection.spec.ts

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

4+
declare const process: { platform: string };
5+
46
const testPages = {
57
'posts': 'table.html',
68
'posts2': 'default.html',
@@ -68,21 +70,26 @@ Object.entries(testPages).forEach(([postDir, pageName]) => {
6870
test(`Multiple category selection with Ctrl+click works for ${pageName}`, async ({ page }) => {
6971
await page.goto(`./blog/simple-blog/_site/${pageName}`);
7072

73+
// Target category sidebar specifically (not post card categories)
74+
const categorySidebar = page.locator('.quarto-listing-category');
75+
const codeCategory = categorySidebar.locator(`div.category[data-category="${btoa(encodeURIComponent('code'))}"]`);
76+
const eurosCategory = categorySidebar.locator(`div.category[data-category="${btoa(encodeURIComponent('euros (€)'))}"]`);
77+
7178
// Click on "code" category (only Post With Code has this category)
72-
await page.getByText('code', { exact: true }).click();
73-
await expect(page.locator(`div.category[data-category="${btoa(encodeURIComponent('code'))}"]`)).toHaveClass(/active/);
79+
await codeCategory.click();
80+
await expect(codeCategory).toHaveClass(/active/);
7481
await expect(page.getByRole('link', { name: 'Post With Code' })).toBeVisible();
7582
await expect(page.getByRole('link', { name: 'Welcome To My Blog' })).toBeHidden();
7683

7784
// Ctrl+click on "euros (€)" category to add it to selection (only Welcome has this category)
7885
const modifier = process.platform === 'darwin' ? 'Meta' : 'Control';
7986
await page.keyboard.down(modifier);
80-
await page.getByText('euros (€)', { exact: true }).click();
87+
await eurosCategory.click();
8188
await page.keyboard.up(modifier);
8289

8390
// Both categories should be active
84-
await expect(page.locator(`div.category[data-category="${btoa(encodeURIComponent('code'))}"]`)).toHaveClass(/active/);
85-
await expect(page.locator(`div.category[data-category="${btoa(encodeURIComponent('euros (€)'))}"]`)).toHaveClass(/active/);
91+
await expect(codeCategory).toHaveClass(/active/);
92+
await expect(eurosCategory).toHaveClass(/active/);
8693

8794
// Both posts should be visible (OR logic: posts matching any selected category)
8895
await expect(page.getByRole('link', { name: 'Post With Code' })).toBeVisible();
@@ -98,14 +105,18 @@ Object.entries(testPages).forEach(([postDir, pageName]) => {
98105
test(`Deselecting last category with Ctrl+click shows all posts for ${pageName}`, async ({ page }) => {
99106
await page.goto(`./blog/simple-blog/_site/${pageName}`);
100107

108+
// Target category sidebar specifically
109+
const categorySidebar = page.locator('.quarto-listing-category');
110+
const codeCategory = categorySidebar.locator(`div.category[data-category="${btoa(encodeURIComponent('code'))}"]`);
111+
101112
// Click on "code" category
102-
await page.getByText('code', { exact: true }).click();
103-
await expect(page.locator(`div.category[data-category="${btoa(encodeURIComponent('code'))}"]`)).toHaveClass(/active/);
113+
await codeCategory.click();
114+
await expect(codeCategory).toHaveClass(/active/);
104115

105116
// Ctrl+click on "code" again to deselect it
106117
const modifier = process.platform === 'darwin' ? 'Meta' : 'Control';
107118
await page.keyboard.down(modifier);
108-
await page.getByText('code', { exact: true }).click();
119+
await codeCategory.click();
109120
await page.keyboard.up(modifier);
110121

111122
// No category should be active (default state), all posts visible

0 commit comments

Comments
 (0)