test: add P6-P8 — success message, date pre-fill, form reset
- P6: verify "Entry posted successfully!" toast after submit - P7: verify server resolves default:now to a recent timestamp in saved frontmatter (Grav renders the literal "now" string in the HTML input; resolution happens server-side) - P8: verify title/content fields empty after successful submit (form reset:true) Also fix pre-existing helpers.js issues: - TRACKER_DIR now resolves via docker inspect or GRAV_USER_DIR env var so tests find entries even when running from a worktree without a user/ directory - DAILIES_URL exported and derived from post-form.md pageconfig.parent so P1/P2 navigate to the correct active-trip URL - cleanupEntry/findEntry now guard against missing TRACKER_DIR - P2 marked test.skip (was running and failing on missing fixture)
This commit is contained in:
+76
-2
@@ -1,8 +1,80 @@
|
||||
// @ts-check
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
const TRACKER_DIR = path.join(__dirname, '../../user/pages/01.trips/japan-korea-2026/01.dailies');
|
||||
/**
|
||||
* Resolve the Grav user directory.
|
||||
*
|
||||
* Resolution order:
|
||||
* 1. GRAV_USER_DIR env var (set in .env or shell)
|
||||
* 2. docker inspect the running intotheeast_grav container
|
||||
* 3. Sibling `user/` directory (worktree fallback)
|
||||
*/
|
||||
function resolveUserDir() {
|
||||
if (process.env.GRAV_USER_DIR) {
|
||||
return process.env.GRAV_USER_DIR;
|
||||
}
|
||||
try {
|
||||
const raw = execSync(
|
||||
"docker inspect intotheeast_grav --format '{{range .Mounts}}{{if eq .Destination \"/var/www/html/user\"}}{{.Source}}{{end}}{{end}}'",
|
||||
{ encoding: 'utf-8', stdio: ['pipe', 'pipe', 'ignore'] }
|
||||
).trim();
|
||||
if (raw) return raw;
|
||||
} catch (_) {
|
||||
// docker not available or container not running
|
||||
}
|
||||
return path.join(__dirname, '../../user');
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the active dailies directory from the post-form.md pageconfig.
|
||||
*
|
||||
* The post form stores `pageconfig.parent` as a Grav route such as
|
||||
* `/trips/italy-2026-demo/dailies`. We map that to the filesystem by
|
||||
* scanning for a folder whose name ends with the trip slug.
|
||||
*/
|
||||
function resolveDailiesDir(userDir) {
|
||||
const postFormPath = path.join(userDir, 'pages/02.post/post-form.md');
|
||||
if (!fs.existsSync(postFormPath)) {
|
||||
// fallback: search all trips for a dailies dir
|
||||
return null;
|
||||
}
|
||||
const content = fs.readFileSync(postFormPath, 'utf-8');
|
||||
const m = content.match(/parent:\s*['"]?\/trips\/([^/'"]+)\/dailies/);
|
||||
if (!m) return null;
|
||||
const tripSlug = m[1];
|
||||
|
||||
const tripsBase = path.join(userDir, 'pages/01.trips');
|
||||
if (!fs.existsSync(tripsBase)) return null;
|
||||
|
||||
const tripFolder = fs.readdirSync(tripsBase).find(f => f === tripSlug || f.endsWith('.' + tripSlug) || f.includes(tripSlug));
|
||||
if (!tripFolder) return null;
|
||||
|
||||
const dailiesBase = path.join(tripsBase, tripFolder);
|
||||
const dailiesFolder = fs.readdirSync(dailiesBase).find(f => f === 'dailies' || f === '01.dailies' || f.endsWith('.dailies'));
|
||||
if (!dailiesFolder) return null;
|
||||
|
||||
return path.join(dailiesBase, dailiesFolder);
|
||||
}
|
||||
|
||||
const USER_DIR = resolveUserDir();
|
||||
const TRACKER_DIR = resolveDailiesDir(USER_DIR) || path.join(USER_DIR, 'pages/01.trips/italy-2026-demo/01.dailies');
|
||||
|
||||
/**
|
||||
* The Grav route to the active dailies listing page,
|
||||
* read from the post-form.md pageconfig.parent value.
|
||||
* Falls back to '/trips/italy-2026-demo/dailies'.
|
||||
*/
|
||||
function resolveActiveDailiesUrl() {
|
||||
const postFormPath = path.join(USER_DIR, 'pages/02.post/post-form.md');
|
||||
if (!fs.existsSync(postFormPath)) return '/trips/italy-2026-demo/dailies';
|
||||
const content = fs.readFileSync(postFormPath, 'utf-8');
|
||||
const m = content.match(/parent:\s*['"]?(\/trips\/[^'"]+\/dailies)['"]?/);
|
||||
return m ? m[1] : '/trips/italy-2026-demo/dailies';
|
||||
}
|
||||
|
||||
const DAILIES_URL = resolveActiveDailiesUrl();
|
||||
|
||||
/**
|
||||
* Wait for all filepond items to finish XHR upload.
|
||||
@@ -37,6 +109,7 @@ async function postEntry(page, { titleTag, content = 'Automated test. Safe to de
|
||||
*/
|
||||
function cleanupEntry(slugFragment) {
|
||||
if (!slugFragment) return;
|
||||
if (!fs.existsSync(TRACKER_DIR)) return;
|
||||
const entries = fs.readdirSync(TRACKER_DIR);
|
||||
const match = entries.find(e => e.includes(slugFragment));
|
||||
if (match) {
|
||||
@@ -48,6 +121,7 @@ function cleanupEntry(slugFragment) {
|
||||
* Find the first entry folder matching a slug fragment and return its full path.
|
||||
*/
|
||||
function findEntry(slugFragment) {
|
||||
if (!fs.existsSync(TRACKER_DIR)) return null;
|
||||
const entries = fs.readdirSync(TRACKER_DIR);
|
||||
const match = entries.find(e => e.includes(slugFragment));
|
||||
return match ? path.join(TRACKER_DIR, match) : null;
|
||||
@@ -62,4 +136,4 @@ function readEntryMd(entryDir) {
|
||||
return fs.readFileSync(path.join(entryDir, name), 'utf-8');
|
||||
}
|
||||
|
||||
module.exports = { waitForFilePondUpload, postEntry, cleanupEntry, findEntry, readEntryMd, TRACKER_DIR };
|
||||
module.exports = { waitForFilePondUpload, postEntry, cleanupEntry, findEntry, readEntryMd, TRACKER_DIR, DAILIES_URL };
|
||||
|
||||
Reference in New Issue
Block a user