import { expect, test } from '@playwright/test';

const baseUrl = (process.env.E2E_BASE_URL ?? 'https://www.taxbaik.com').replace(/\/$/, '');

test.describe('blog seo', () => {
  test('exposes title description and canonical on blog detail pages', async ({ page }) => {
    await page.goto(`${baseUrl}/blog`);
    const firstPost = page.locator('a[href^="/blog/"]').filter({ hasText: '글 내용 보기' }).first();
    await expect(firstPost).toBeVisible();
    const detailHref = await firstPost.getAttribute('href');
    expect(detailHref).toMatch(/^\/blog\/[a-z0-9-]+$/);
    const detailPath = detailHref ?? '/blog';
    const response = await page.goto(`${baseUrl}${detailPath}`);
    expect(response, 'blog detail response should be returned').toBeTruthy();
    expect(response!.status(), `blog detail response for ${detailPath} should be successful`).toBe(200);

    await expect(page.locator('meta[name="description"]')).toHaveAttribute('content', /.+/);
    await expect(page.locator('link[rel="canonical"]')).toHaveAttribute('href', /\/blog\/[a-z0-9-]+$/);
    await expect(page.getByRole('heading', { level: 1 })).toBeVisible();
  });
});
