Skip to content

Commit 48ecb01

Browse files
committed
test: add tests for multiple category selection in blog
1 parent daa36c8 commit 48ecb01

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

tests/integration/playwright/tests/blog-simple-blog.spec.ts renamed to tests/integration/playwright/tests/blog-categories-selection.spec.ts

Lines changed: 59 additions & 0 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',
@@ -64,6 +66,63 @@ Object.entries(testPages).forEach(([postDir, pageName]) => {
6466
await page.goto(`./blog/simple-blog/_site/${pageName}`);
6567
await checkCategoryLink(page, '免疫', pageName, 'Welcome To My Blog');
6668
});
69+
70+
test(`Multiple category selection with Ctrl+click works for ${pageName}`, async ({ page }) => {
71+
await page.goto(`./blog/simple-blog/_site/${pageName}`);
72+
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+
78+
// Click on "code" category (only Post With Code has this category)
79+
await codeCategory.click();
80+
await expect(codeCategory).toHaveClass(/active/);
81+
await expect(page.getByRole('link', { name: 'Post With Code' })).toBeVisible();
82+
await expect(page.getByRole('link', { name: 'Welcome To My Blog' })).toBeHidden();
83+
84+
// Ctrl+click on "euros (€)" category to add it to selection (only Welcome has this category)
85+
const modifier = process.platform === 'darwin' ? 'Meta' : 'Control';
86+
await page.keyboard.down(modifier);
87+
await eurosCategory.click();
88+
await page.keyboard.up(modifier);
89+
90+
// Both categories should be active
91+
await expect(codeCategory).toHaveClass(/active/);
92+
await expect(eurosCategory).toHaveClass(/active/);
93+
94+
// Both posts should be visible (OR logic: posts matching any selected category)
95+
await expect(page.getByRole('link', { name: 'Post With Code' })).toBeVisible();
96+
await expect(page.getByRole('link', { name: 'Welcome To My Blog' })).toBeVisible();
97+
98+
// URL hash should contain both categories (comma-separated)
99+
const url = page.url();
100+
expect(url).toContain('category=');
101+
expect(url).toContain(encodeURIComponent('code'));
102+
expect(url).toContain(encodeURIComponent('euros (€)'));
103+
});
104+
105+
test(`Deselecting last category with Ctrl+click shows all posts for ${pageName}`, async ({ page }) => {
106+
await page.goto(`./blog/simple-blog/_site/${pageName}`);
107+
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+
112+
// Click on "code" category
113+
await codeCategory.click();
114+
await expect(codeCategory).toHaveClass(/active/);
115+
116+
// Ctrl+click on "code" again to deselect it
117+
const modifier = process.platform === 'darwin' ? 'Meta' : 'Control';
118+
await page.keyboard.down(modifier);
119+
await codeCategory.click();
120+
await page.keyboard.up(modifier);
121+
122+
// No category should be active (default state), all posts visible
123+
await expect(page.getByRole('link', { name: 'Post With Code' })).toBeVisible();
124+
await expect(page.getByRole('link', { name: 'Welcome To My Blog' })).toBeVisible();
125+
});
67126
}
68127
});
69128

0 commit comments

Comments
 (0)