import { test, expect } from '@playwright/test'; import { NextRequest } from 'next/server'; import { middleware } from '../src/middleware'; import { SITE_PAGES, SITE_URL, OG_IMAGE_PATH } from '../src/lib/site-metadata'; for (const { path, title, description } of Object.values(SITE_PAGES)) { test(`SEO tags and indexable content for ${path}`, async ({ page }) => { const response = await page.goto(path); expect(response?.status()).toBe(200); await expect(page).toHaveTitle(title); await expect(page.locator('h1')).toHaveCount(1); await expect(page.locator('h1')).toBeVisible(); await expect(page.locator('link[rel="canonical"]')).toHaveCount(1); await expect(page.locator('link[rel="canonical"]')).toHaveAttribute('href', new URL(path, SITE_URL).href.replace(/\/$/, '')); await expect(page.locator('meta[name="description"]')).toHaveAttribute('content', description); await expect(page.locator('meta[property="og:title"]')).toHaveAttribute('content', title); await expect(page.locator('meta[property="og:description"]')).toHaveAttribute('content', description); await expect(page.locator('meta[name="twitter:title"]')).toHaveAttribute('content', title); await expect(page.locator('meta[name="twitter:description"]')).toHaveAttribute('content', description); await expect(page.locator('meta[property="og:image"]')).toHaveAttribute('content', /\/og\/jotley-v2\.png$/); await expect(page.locator('meta[name="robots"]')).not.toHaveAttribute('content', /noindex/); }); } test('sitemap matches canonical pages and robots allows crawling', async ({ request }) => { const sitemap = await request.get('/sitemap.xml'); expect(sitemap.status()).toBe(200); const xml = await sitemap.text(); const locations = Array.from(xml.matchAll(/(.*?)<\/loc>/g), match => match[1].replace(/\/$/, '')).sort(); expect(locations).toEqual(Object.values(SITE_PAGES).map(({ path }) => new URL(path, SITE_URL).href.replace(/\/$/, '')).sort()); expect(xml).not.toContain(''); const robots = await request.get('/robots.txt'); expect(robots.status()).toBe(200); expect(await robots.text()).toContain('Allow: /'); expect(await robots.text()).toContain(`Sitemap: ${SITE_URL}/sitemap.xml`); }); test('home serves valid site name and publisher JSON-LD', async ({ page }) => { await page.goto('/'); const schema = JSON.parse(await page.locator('script[type="application/ld+json"]').innerText()); expect(schema['@context']).toBe('https://schema.org'); const website = schema['@graph'].find((item: { '@type': string }) => item['@type'] === 'WebSite'); expect(website.name).toBe('Jotley'); expect(website.url).toBe(SITE_URL); expect(website.publisher['@id']).toBe('https://projectatom.ai/#org'); expect(schema['@graph'].some((item: { '@id': string }) => item['@id'] === website.publisher['@id'])).toBe(true); const app = schema['@graph'].find((item: { '@type': string }) => item['@type'] === 'SoftwareApplication'); expect(app.name).toBe('Jotley'); expect(app.offers).toBeUndefined(); }); test('support serves FAQ JSON-LD that matches the visible questions', async ({ page }) => { await page.goto('/help'); const schema = JSON.parse(await page.locator('script[type="application/ld+json"]').innerText()); const faq = schema['@graph'].find((item: { '@type': string }) => item['@type'] === 'FAQPage'); expect(faq.mainEntity.length).toBeGreaterThan(0); for (const question of faq.mainEntity) { await expect(page.locator('.faq-q', { hasText: question.name })).toHaveCount(1); } }); test('llms.txt is served as plain text and names the app', async ({ request }) => { const response = await request.get('/llms.txt'); expect(response.status()).toBe(200); expect(response.headers()['content-type']).toContain('text/plain'); expect(await response.text()).toContain('# Jotley'); }); test('utility pages stay out of search and missing pages return 404', async ({ page }) => { for (const path of ['/maintenance', '/metadata-preview']) { await page.goto(path); await expect(page.locator('meta[name="robots"]')).toHaveAttribute('content', /noindex/); await expect(page.locator('link[rel="canonical"]')).toHaveCount(0); } const response = await page.goto('/a-page-that-does-not-exist-seo-check'); expect(response?.status()).toBe(404); await expect(page.locator('meta[name="robots"][content*="noindex"]')).toHaveCount(1); await expect(page.locator('link[rel="canonical"]')).toHaveCount(0); }); test('OG endpoint serves the same PNG as the social card', async ({ request }) => { const staticImage = await request.get(OG_IMAGE_PATH); const endpoint = await request.get('/api/og'); expect(staticImage.status()).toBe(200); expect(endpoint.status()).toBe(200); expect(endpoint.headers()['content-type']).toContain('image/png'); expect(await endpoint.body()).toEqual(await staticImage.body()); }); test('maintenance reports temporary downtime and keeps crawler files accessible', () => { const previous = process.env.NEXT_PUBLIC_MAINTENANCE_MODE; process.env.NEXT_PUBLIC_MAINTENANCE_MODE = 'true'; try { const response = middleware(new NextRequest(`${SITE_URL}/`)); expect(response.status).toBe(503); expect(response.headers.get('Retry-After')).toBe('3600'); for (const path of ['/robots.txt', '/sitemap.xml', '/llms.txt', '/download']) { expect(middleware(new NextRequest(`${SITE_URL}${path}`)).status).toBe(200); } } finally { if (previous === undefined) delete process.env.NEXT_PUBLIC_MAINTENANCE_MODE; else process.env.NEXT_PUBLIC_MAINTENANCE_MODE = previous; } });