|
1 | 1 | import { expect, Page, test } from "@playwright/test"; |
2 | 2 | import { getUrl } from "../src/utils"; |
3 | 3 |
|
| 4 | +declare const process: { platform: string }; |
| 5 | + |
4 | 6 | const testPages = { |
5 | 7 | 'posts': 'table.html', |
6 | 8 | 'posts2': 'default.html', |
@@ -64,6 +66,63 @@ Object.entries(testPages).forEach(([postDir, pageName]) => { |
64 | 66 | await page.goto(`./blog/simple-blog/_site/${pageName}`); |
65 | 67 | await checkCategoryLink(page, '免疫', pageName, 'Welcome To My Blog'); |
66 | 68 | }); |
| 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 | + }); |
67 | 126 | } |
68 | 127 | }); |
69 | 128 |
|
|
0 commit comments