Branchwell

Jotley / website · jotley.ai / e2e / seo.spec.ts

1import { test, expect } from '@playwright/test';
2import { NextRequest } from 'next/server';
3import { middleware } from '../src/middleware';
4import { SITE_PAGES, SITE_URL, OG_IMAGE_PATH } from '../src/lib/site-metadata';
5
6for (const { path, title, description } of Object.values(SITE_PAGES)) {
7 test(`SEO tags and indexable content for ${path}`, async ({ page }) => {
8 const response = await page.goto(path);
9 expect(response?.status()).toBe(200);
10 await expect(page).toHaveTitle(title);
11 await expect(page.locator('h1')).toHaveCount(1);
12 await expect(page.locator('h1')).toBeVisible();
13 await expect(page.locator('link[rel="canonical"]')).toHaveCount(1);
14 await expect(page.locator('link[rel="canonical"]')).toHaveAttribute('href', new URL(path, SITE_URL).href.replace(/\/$/, ''));
15 await expect(page.locator('meta[name="description"]')).toHaveAttribute('content', description);
16 await expect(page.locator('meta[property="og:title"]')).toHaveAttribute('content', title);
17 await expect(page.locator('meta[property="og:description"]')).toHaveAttribute('content', description);
18 await expect(page.locator('meta[name="twitter:title"]')).toHaveAttribute('content', title);
19 await expect(page.locator('meta[name="twitter:description"]')).toHaveAttribute('content', description);
20 await expect(page.locator('meta[property="og:image"]')).toHaveAttribute('content', /\/og\/jotley-v2\.png$/);
21 await expect(page.locator('meta[name="robots"]')).not.toHaveAttribute('content', /noindex/);
22 });
23}
24
25test('sitemap matches canonical pages and robots allows crawling', async ({ request }) => {
26 const sitemap = await request.get('/sitemap.xml');
27 expect(sitemap.status()).toBe(200);
28 const xml = await sitemap.text();
29 const locations = Array.from(xml.matchAll(/<loc>(.*?)<\/loc>/g), match => match[1].replace(/\/$/, '')).sort();
30 expect(locations).toEqual(Object.values(SITE_PAGES).map(({ path }) => new URL(path, SITE_URL).href.replace(/\/$/, '')).sort());
31 expect(xml).not.toContain('<lastmod>');
32 const robots = await request.get('/robots.txt');
33 expect(robots.status()).toBe(200);
34 expect(await robots.text()).toContain('Allow: /');
35 expect(await robots.text()).toContain(`Sitemap: ${SITE_URL}/sitemap.xml`);
36});
37
38test('home serves valid site name and publisher JSON-LD', async ({ page }) => {
39 await page.goto('/');
40 const schema = JSON.parse(await page.locator('script[type="application/ld+json"]').innerText());
41 expect(schema['@context']).toBe('https://schema.org');
42 const website = schema['@graph'].find((item: { '@type': string }) => item['@type'] === 'WebSite');
43 expect(website.name).toBe('Jotley');
44 expect(website.url).toBe(SITE_URL);
45 expect(website.publisher['@id']).toBe('https://projectatom.ai/#org');
46 expect(schema['@graph'].some((item: { '@id': string }) => item['@id'] === website.publisher['@id'])).toBe(true);
47 const app = schema['@graph'].find((item: { '@type': string }) => item['@type'] === 'SoftwareApplication');
48 expect(app.name).toBe('Jotley');
49 expect(app.offers).toBeUndefined();
50});
51
52test('support serves FAQ JSON-LD that matches the visible questions', async ({ page }) => {
53 await page.goto('/help');
54 const schema = JSON.parse(await page.locator('script[type="application/ld+json"]').innerText());
55 const faq = schema['@graph'].find((item: { '@type': string }) => item['@type'] === 'FAQPage');
56 expect(faq.mainEntity.length).toBeGreaterThan(0);
57 for (const question of faq.mainEntity) {
58 await expect(page.locator('.faq-q', { hasText: question.name })).toHaveCount(1);
59 }
60});
61
62test('llms.txt is served as plain text and names the app', async ({ request }) => {
63 const response = await request.get('/llms.txt');
64 expect(response.status()).toBe(200);
65 expect(response.headers()['content-type']).toContain('text/plain');
66 expect(await response.text()).toContain('# Jotley');
67});
68
69test('utility pages stay out of search and missing pages return 404', async ({ page }) => {
70 for (const path of ['/maintenance', '/metadata-preview']) {
71 await page.goto(path);
72 await expect(page.locator('meta[name="robots"]')).toHaveAttribute('content', /noindex/);
73 await expect(page.locator('link[rel="canonical"]')).toHaveCount(0);
74 }
75 const response = await page.goto('/a-page-that-does-not-exist-seo-check');
76 expect(response?.status()).toBe(404);
77 await expect(page.locator('meta[name="robots"][content*="noindex"]')).toHaveCount(1);
78 await expect(page.locator('link[rel="canonical"]')).toHaveCount(0);
79});
80
81test('OG endpoint serves the same PNG as the social card', async ({ request }) => {
82 const staticImage = await request.get(OG_IMAGE_PATH);
83 const endpoint = await request.get('/api/og');
84 expect(staticImage.status()).toBe(200);
85 expect(endpoint.status()).toBe(200);
86 expect(endpoint.headers()['content-type']).toContain('image/png');
87 expect(await endpoint.body()).toEqual(await staticImage.body());
88});
89
90test('maintenance reports temporary downtime and keeps crawler files accessible', () => {
91 const previous = process.env.NEXT_PUBLIC_MAINTENANCE_MODE;
92 process.env.NEXT_PUBLIC_MAINTENANCE_MODE = 'true';
93 try {
94 const response = middleware(new NextRequest(`${SITE_URL}/`));
95 expect(response.status).toBe(503);
96 expect(response.headers.get('Retry-After')).toBe('3600');
97 for (const path of ['/robots.txt', '/sitemap.xml', '/llms.txt', '/download']) {
98 expect(middleware(new NextRequest(`${SITE_URL}${path}`)).status).toBe(200);
99 }
100 } finally {
101 if (previous === undefined) delete process.env.NEXT_PUBLIC_MAINTENANCE_MODE;
102 else process.env.NEXT_PUBLIC_MAINTENANCE_MODE = previous;
103 }
104});