From c862827ac22ad1069513b0f86ae39e137a39fb68 Mon Sep 17 00:00:00 2001 From: Mischa Date: Sun, 21 Jun 2026 01:48:46 +0200 Subject: [PATCH] =?UTF-8?q?test(home):=20add=20H2=E2=80=93H5=20between-tri?= =?UTF-8?q?ps=20highlights=20Playwright=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 Claude-Session: https://claude.ai/code/session_01Vgmzx8VTTTmCskSpQtsLTr --- tests/ui/home-highlights.spec.js | 56 ++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/ui/home-highlights.spec.js diff --git a/tests/ui/home-highlights.spec.js b/tests/ui/home-highlights.spec.js new file mode 100644 index 0000000..9f136c6 --- /dev/null +++ b/tests/ui/home-highlights.spec.js @@ -0,0 +1,56 @@ +// @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/); + }); +});