|
| 1 | +import { test, expect } from '@playwright/test' |
| 2 | + |
| 3 | +test.describe('Blog', () => { |
| 4 | + test('blog index loads with correct title', async ({ page }) => { |
| 5 | + await page.goto('/blog') |
| 6 | + await expect(page).toHaveTitle('Blog — Cmdr') |
| 7 | + }) |
| 8 | + |
| 9 | + test('blog index lists posts with dates', async ({ page }) => { |
| 10 | + await page.goto('/blog') |
| 11 | + const article = page.locator('article').first() |
| 12 | + await expect(article).toBeVisible() |
| 13 | + await expect(article.locator('time')).toBeVisible() |
| 14 | + }) |
| 15 | + |
| 16 | + test('blog index shows excerpt, not full post', async ({ page }) => { |
| 17 | + await page.goto('/blog') |
| 18 | + const article = page.locator('article').first() |
| 19 | + // Excerpt content should be visible |
| 20 | + await expect(article.locator('.blog-content')).toContainText('What to expect') |
| 21 | + // Content after the <!-- more --> marker should not appear |
| 22 | + await expect(article.locator('.blog-content')).not.toContainText('A quick look at Cmdr') |
| 23 | + }) |
| 24 | + |
| 25 | + test('blog index has "Read more" link to full post', async ({ page }) => { |
| 26 | + await page.goto('/blog') |
| 27 | + const readMore = page.locator('.read-more-link').first() |
| 28 | + await expect(readMore).toBeVisible() |
| 29 | + await expect(readMore).toHaveAttribute('href', '/blog/hello-world') |
| 30 | + await readMore.click() |
| 31 | + await expect(page).toHaveURL(/\/blog\/hello-world/) |
| 32 | + await expect(page.locator('h1')).toContainText('Hello, world') |
| 33 | + }) |
| 34 | + |
| 35 | + test('post title links to individual post page', async ({ page }) => { |
| 36 | + await page.goto('/blog') |
| 37 | + const postLink = page.locator('article a[href*="/blog/"]').first() |
| 38 | + await expect(postLink).toBeVisible() |
| 39 | + await postLink.click() |
| 40 | + await expect(page).toHaveURL(/\/blog\/hello-world/) |
| 41 | + await expect(page.locator('h1')).toContainText('Hello, world') |
| 42 | + }) |
| 43 | + |
| 44 | + test('individual post shows full content including sections after excerpt', async ({ page }) => { |
| 45 | + await page.goto('/blog/hello-world') |
| 46 | + // Both excerpt and post-excerpt content should be visible |
| 47 | + await expect(page.locator('.blog-content')).toContainText('What to expect') |
| 48 | + await expect(page.locator('.blog-content')).toContainText('A quick look at Cmdr') |
| 49 | + await expect(page.locator('.blog-content')).toContainText('Built with modern tools') |
| 50 | + }) |
| 51 | + |
| 52 | + test('individual post shows date and description', async ({ page }) => { |
| 53 | + await page.goto('/blog/hello-world') |
| 54 | + await expect(page.locator('main time')).toBeVisible() |
| 55 | + await expect(page.locator('main header p')).toContainText('Welcome to the Cmdr blog') |
| 56 | + }) |
| 57 | + |
| 58 | + test('individual post has correct meta tags', async ({ page }) => { |
| 59 | + await page.goto('/blog/hello-world') |
| 60 | + const ogImage = page.locator('meta[property="og:image"]') |
| 61 | + await expect(ogImage).toHaveAttribute('content', /\/og\/hello-world\.png/) |
| 62 | + const description = page.locator('meta[name="description"]') |
| 63 | + await expect(description).toHaveAttribute('content', /Welcome to the Cmdr blog/) |
| 64 | + const ogTitle = page.locator('meta[property="og:title"]') |
| 65 | + await expect(ogTitle).toHaveAttribute('content', /Hello, world/) |
| 66 | + }) |
| 67 | + |
| 68 | + test('individual post has comments section', async ({ page }) => { |
| 69 | + await page.goto('/blog/hello-world') |
| 70 | + await expect(page.locator('.comments-section')).toBeVisible() |
| 71 | + await expect(page.getByText('Comments')).toBeVisible() |
| 72 | + }) |
| 73 | + |
| 74 | + test('external links open in new tabs', async ({ page }) => { |
| 75 | + await page.goto('/blog/hello-world') |
| 76 | + const externalLinks = page.locator('.blog-content a[target="_blank"]') |
| 77 | + const count = await externalLinks.count() |
| 78 | + expect(count).toBeGreaterThan(0) |
| 79 | + for (let i = 0; i < count; i++) { |
| 80 | + await expect(externalLinks.nth(i)).toHaveAttribute('rel', /noopener/) |
| 81 | + } |
| 82 | + }) |
| 83 | + |
| 84 | + test('RSS feed returns valid XML with post data', async ({ request }) => { |
| 85 | + const response = await request.get('/rss.xml') |
| 86 | + expect(response.status()).toBe(200) |
| 87 | + expect(response.headers()['content-type']).toContain('xml') |
| 88 | + const body = await response.text() |
| 89 | + expect(body).toContain('<title>Cmdr blog</title>') |
| 90 | + expect(body).toContain('Hello, world') |
| 91 | + expect(body).toContain('/blog/hello-world/') |
| 92 | + }) |
| 93 | + |
| 94 | + test('OG image returns PNG', async ({ request }) => { |
| 95 | + const response = await request.get('/og/hello-world.png') |
| 96 | + expect(response.status()).toBe(200) |
| 97 | + expect(response.headers()['content-type']).toContain('png') |
| 98 | + }) |
| 99 | + |
| 100 | + test('navigation has Blog link', async ({ page }) => { |
| 101 | + await page.goto('/') |
| 102 | + const blogLink = page.getByRole('navigation').getByRole('link', { name: 'Blog' }) |
| 103 | + await expect(blogLink).toBeVisible() |
| 104 | + }) |
| 105 | +}) |
0 commit comments