PlotDirector/PlotLine.Tests/Browser/public-site-capture.cjs

69 lines
4.2 KiB
JavaScript

// Start --toolbar-browser-host first. Captures real compiled views with fictional, database-free data.
// Run from repository root: node PlotLine.Tests/Browser/public-site-capture.cjs
const { chromium } = require('playwright');
const fs = require('node:fs');
const path = require('node:path');
const base = 'http://127.0.0.1:5238';
const output = path.resolve(__dirname, '../../PlotLine/wwwroot/images/public');
(async () => {
fs.mkdirSync(output, { recursive: true });
const browser = await chromium.launch();
try {
const context = await browser.newContext({ viewport: { width: 1440, height: 960 }, reducedMotion: 'reduce' });
await context.addInitScript(() => Object.defineProperty(navigator, 'standalone', { value: true }));
await context.addCookies([{ name: "fixture-user", value: "5", domain: "127.0.0.1", path: "/" }]);
const page = await context.newPage();
await page.route(/\/(Scenes|Warnings)\/Scene\w+Editor\?/, async route => {
const name = new URL(route.request().url()).pathname.split('/').pop();
const editors = { SceneNotesEditor: 'notes', SceneKnowledgeEditor: 'knowledge', SceneContinuityEditor: 'warnings' };
const response = await page.request.get(base + '/fixture?page=scene-edit&editor=' + editors[name]);
if (response.status() !== 200) throw new Error('Editor fixture failed: ' + name);
await route.fulfill({ response });
});
async function capture(name, url, prepare) {
const response = await page.goto(base + url);
if (response.status() !== 200) throw new Error('Capture failed: ' + url);
await page.evaluate(() => document.fonts.ready);
if (prepare) await prepare();
await page.screenshot({ path: path.join(output, name + '.jpg'), type: 'jpeg', quality: 88 });
console.log('Captured real view: ' + name);
}
async function sceneArea(area) {
// Desktop shell moves source controls into its existing ribbon.
const command = page.locator(`[data-scene-area-command="${area}"]:visible`);
if (await command.count()) await command.click();
else {
const group = page.locator('.pd-context-group[aria-label="Edit Scene"]');
const details = group.locator('details[data-compact="true"]');
if (await details.count() && await details.getAttribute('open') === null) await details.locator('summary').click();
await group.locator('button.pd-context-command').filter({ hasText: new RegExp('^' + area + '$', 'i') }).click();
}
}
await capture('scene', '/fixture?page=scene-edit');
await capture('writing', '/fixture?page=scene-edit', async () => {
await sceneArea('writer');
await page.locator('[data-scene-editor="notes"]:visible').first().click();
await page.locator('[data-scene-editor-body] textarea').first().waitFor();
});
await capture('workspace', '/fixture?page=dashboard');
await capture('calendar', '/fixture?marketing=true');
await capture('characters', '/fixture?record=Characters');
await capture('continuity', '/fixture?page=scene-edit', async () => { await sceneArea('continuity'); });
await capture('knowledge', '/fixture?page=scene-edit', async () => {
await sceneArea('people');
await page.locator('[data-scene-editor="knowledge"]:visible').click();
await page.locator('[data-scene-editor-body] h4').first().waitFor();
});
await capture('import', '/fixture?desktop=ManuscriptImport');
await page.setViewportSize({ width: 1920, height: 900 });
await capture('plot-lines', '/plot-map-fixture?marketing=true', async () => {
await page.locator('#plot-map-zoom').selectOption('180');
await page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))));
});
await page.setViewportSize({ width: 1440, height: 960 });
await capture('insights', '/plot-map-fixture?healthDetail=true&marketing=true');
} finally {
await browser.close();
}
})().catch(error => { console.error(error); process.exitCode = 1; });