c862827ac2
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vgmzx8VTTTmCskSpQtsLTr
57 lines
2.8 KiB
JavaScript
57 lines
2.8 KiB
JavaScript
// @ts-check
|
||
// Tests: H2–H5 — Between-trips highlights mode
|
||
// These tests temporarily set travelling: false in user/config/site.yaml,
|
||
// run the assertions, then restore the original value.
|
||
// Requires demo data with featured entries: run `make demo-load` first.
|
||
const { test, expect } = require('@playwright/test');
|
||
const fs = require('fs');
|
||
const path = require('path');
|
||
|
||
const SITE_YAML_PATH = path.join(__dirname, '../../user/config/site.yaml');
|
||
|
||
test.describe('Between-trips highlights mode', () => {
|
||
let originalSiteYaml;
|
||
|
||
test.beforeAll(async () => {
|
||
originalSiteYaml = fs.readFileSync(SITE_YAML_PATH, 'utf8');
|
||
const patched = originalSiteYaml.replace(/^travelling:\s*true/m, 'travelling: false');
|
||
fs.writeFileSync(SITE_YAML_PATH, patched);
|
||
// Brief pause for Grav to re-read config on next request
|
||
await new Promise(r => setTimeout(r, 400));
|
||
});
|
||
|
||
test.afterAll(async () => {
|
||
fs.writeFileSync(SITE_YAML_PATH, originalSiteYaml);
|
||
});
|
||
|
||
// ── H2: Highlights grid is visible ──────────────────────────────────────────
|
||
test('H2: homepage shows highlights grid when not travelling', async ({ page }) => {
|
||
await page.goto('/');
|
||
await expect(page.locator('.home-highlights-grid')).toBeVisible({ timeout: 10000 });
|
||
});
|
||
|
||
// ── H3: Highlight cards contain trip link ────────────────────────────────────
|
||
test('H3: highlight cards have a View-trip link', async ({ page }) => {
|
||
await page.goto('/');
|
||
await expect(page.locator('.home-highlight-card').first()).toBeVisible({ timeout: 10000 });
|
||
await expect(page.locator('.home-highlight-trip-link').first()).toBeVisible();
|
||
});
|
||
|
||
// ── H4: Between-trips home map renders without JS errors ────────────────────
|
||
test('H4: home map renders in between-trips mode without JS errors', async ({ page }) => {
|
||
const errors = [];
|
||
page.on('pageerror', e => errors.push(e.message));
|
||
await page.goto('/');
|
||
await expect(page.locator('#home-map canvas.maplibregl-canvas')).toBeVisible({ timeout: 10000 });
|
||
expect(errors, 'No JS errors').toHaveLength(0);
|
||
});
|
||
|
||
// ── H5: CTA links to /trips ──────────────────────────────────────────────────
|
||
test('H5: "Explore all past trips" CTA links to /trips', async ({ page }) => {
|
||
await page.goto('/');
|
||
const cta = page.locator('.home-highlights-cta');
|
||
await expect(cta).toBeVisible({ timeout: 10000 });
|
||
await expect(cta).toHaveAttribute('href', /\/trips/);
|
||
});
|
||
});
|