| 1 | import { test, expect } from './_fixtures'; |
| 2 | |
| 3 | const CODE_BLOCK_PAGE = '/reference/attributes/hx-get'; |
| 4 | |
| 5 | test.describe('Code blocks', () => { |
| 6 | test('code blocks have syntax highlighting', async ({ page }) => { |
| 7 | await page.goto(CODE_BLOCK_PAGE); |
| 8 | |
| 9 | const codeBlock = page.locator('.prose pre code').first(); |
| 10 | await expect(codeBlock).toBeVisible(); |
| 11 | |
| 12 | const spanCount = await codeBlock.locator('span').count(); |
| 13 | expect(spanCount).toBeGreaterThan(0); |
| 14 | }); |
| 15 | |
| 16 | test('code blocks are not empty', async ({ page }) => { |
| 17 | await page.goto(CODE_BLOCK_PAGE); |
| 18 | |
| 19 | const codeBlocks = page.locator('.prose pre code'); |
| 20 | const count = await codeBlocks.count(); |
| 21 | expect(count).toBeGreaterThan(0); |
| 22 | |
| 23 | for (let i = 0; i < Math.min(count, 3); i++) { |
| 24 | const text = await codeBlocks.nth(i).textContent(); |
| 25 | expect(text?.trim().length, `code block ${i} should not be empty`).toBeGreaterThan(0); |
| 26 | } |
| 27 | }); |
| 28 | |
| 29 | test('code blocks survive morph navigation', async ({ page }) => { |
| 30 | await page.goto(CODE_BLOCK_PAGE, { waitUntil: 'networkidle' }); |
| 31 | |
| 32 | const sidebarToggle = page.locator('label[for="sidebar-toggle-mobile"]'); |
| 33 | if (await sidebarToggle.isVisible()) { |
| 34 | await sidebarToggle.click(); |
| 35 | } |
| 36 | await page.locator('#sidebar-nav a[href="/reference/attributes/hx-post"]').click(); |
| 37 | await expect(page).toHaveURL(/hx-post/); |
| 38 | |
| 39 | const codeBlock = page.locator('.prose pre code').first(); |
| 40 | if (await codeBlock.isVisible()) { |
| 41 | const spanCount = await codeBlock.locator('span').count(); |
| 42 | expect(spanCount).toBeGreaterThan(0); |
| 43 | } |
| 44 | }); |
| 45 | }); |