PlotDirector/PlotLine.Tests/Browser/pwa-desktop-dev.cjs
Nick Beckley e48889ac05 Complete desktop workspaces, context menus and plot health
Commit the pending application, help and browser regression work. Pin the patched PKCS dependency for the production release.
2026-10-31 09:27:04 +00:00

160 lines
12 KiB
JavaScript

// Operational smoke test: dedicated Dev identity only. No traces, login screenshots or credential output.
const { chromium } = require('playwright');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const assert = require('node:assert/strict');
const base = 'https://dev.plotdirector.com';
const contextChecks = require('./pwa-context-dev-checks.cjs');
let stage = 'setup';
async function ready(page) {
await page.locator('[data-pwa-context-host]:not([hidden])').waitFor({ state: 'attached' });
await page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))));
}
async function openGroup(page, name) {
await ready(page);
const menu = page.locator(`.pd-context-group[aria-label="${name}"] > details[data-compact="true"]`);
if (await menu.count() && await menu.getAttribute('open') === null) await menu.locator(':scope > summary').click();
}
async function oneRibbon(page) {
await ready(page);
assert(await page.evaluate(() => {
const panel = document.querySelector('.pd-ribbon-panel:not([hidden])');
const host = document.querySelector('[data-pwa-context-host]');
return host.parentElement === panel && !document.querySelector('[data-pwa-context-title]') &&
host.getBoundingClientRect().height === 0 && panel.getBoundingClientRect().height <= 86 && panel.scrollWidth <= panel.clientWidth + 1;
}));
}
(async () => {
const file = process.argv[2];
if (!file?.startsWith('/tmp/pd-dev-browser-')) throw Error('Private Dev identity file required');
const identity = JSON.parse(fs.readFileSync(file, 'utf8'));
assert.equal(identity.Database, 'PlotDirector_Development');
assert(identity.Email.startsWith('pwa-browser-') && identity.Email.endsWith('@example.invalid'));
assert(identity.ProjectID && identity.BookID);
const profile = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-dev-desktop-'));
const context = await chromium.launchPersistentContext(profile, { headless: false, viewport: { width: 1440, height: 1000 } });
await context.grantPermissions(['clipboard-read','clipboard-write'],{origin:base});
const cdp = await context.browser().newBrowserCDPSession();
const manifestId = base + '/Projects';
try {
stage = 'normal authenticated Dev login';
const tab = context.pages()[0];
await tab.goto(base + '/Account/Login');
await tab.locator('[name=Email]').fill(identity.Email);
await tab.locator('[name=Password]').fill(identity.Password);
await tab.locator('form button[type=submit]').click();
await tab.waitForURL(base + '/Projects');
const q = `projectId=${identity.ProjectID}`;
const routes = [
`/Projects/Details/${identity.ProjectID}`, `/Books/Details/${identity.BookID}`,
`/Timeline?${q}&bookId=${identity.BookID}`, `/PlotLineWorkspace?${q}&bookId=${identity.BookID}`,
`/StoryBible?${q}`, `/Characters?${q}`, `/Locations?${q}`, `/StoryAssets?${q}`, `/FloorPlans?${q}`,
`/Names?${q}`, `/Scenarios?${q}`, `/ContinuityExplorer?${q}`, `/ProjectMetrics?${q}`, `/Analytics?${q}`,
`/Warnings?${q}`, `/Archives?${q}`, `/StoryPoint?${q}`, `/ProjectCollaborators?${q}`, `/ProjectRestorePoints?${q}`,
`/StoryCalendar?${q}`, `/PlotThreads?${q}`, `/PlotLines?${q}`, `/Writer?${q}`, '/Writer/WritingPlans', '/Writer/SchedulePreview',
`/Projects/Edit/${identity.ProjectID}`, `/Books/Edit/${identity.BookID}`, `/Chapters/Create?bookId=${identity.BookID}`,
`/Characters/Create?${q}`, `/Locations/Create?${q}`, `/StoryAssets/Create?${q}`, `/PlotThreads/Create?${q}`, `/PlotLines/Create?${q}`,
`/Timeline/Settings?${q}`, `/Dynamics/Story?${q}`, '/Imports', '/FeatureRequests', '/FeatureRequests/Roadmap', '/FeatureRequests/Create', '/help', '/ManageAccount', '/ManageAccount/Subscription'
];
for (const route of routes) {
stage = 'browser ' + route.split('?')[0];
const response = await tab.goto(base + route);
assert.equal(response.status(), 200);
await contextChecks.checkMode(tab, false);
assert(!tab.url().includes('/Account/'));
if (await tab.locator('main .breadcrumb-trail').count()) assert(await tab.locator('main .breadcrumb-trail').first().isVisible());
assert(await tab.locator('main h1').first().isVisible());
assert(await tab.locator('[data-pwa-context-host]').isHidden());
}
stage = 'real Dev PWA installation';
await tab.goto(base + '/Projects');
await cdp.send('PWA.install', { manifestId, installUrlOrBundleUrl: base + '/Projects' });
await cdp.send('PWA.changeAppUserSettings', { manifestId, displayMode: 'standalone' });
const opened = context.waitForEvent('page');
await cdp.send('PWA.launch', { manifestId, url: base + routes[0] });
const app = await opened; await app.waitForLoadState();
assert(await app.evaluate(() => matchMedia('(display-mode: standalone)').matches));
await require('./pwa-first-paint.cjs')(app, tab, { url: base + '/StoryBible?' + q });
for (const route of routes) {
stage = 'installed ' + route.split('?')[0];
const response = await app.goto(base + route);
assert.equal(response.status(), 200);
if (await app.locator('#ribbon-surface').isHidden()) await app.locator('[data-ribbon-tab=story]').click();
await oneRibbon(app);
await contextChecks.checkMode(app,true);
if (await app.locator('main [data-pwa-header]').count()) assert(await app.locator('main [data-pwa-header]').first().isHidden());
if (await app.locator('main [data-pwa-task]').count()) assert(await app.locator('main [data-pwa-task] h1').first().isVisible());
if (await app.locator('main .breadcrumb-trail:not([data-pwa-context])').count()) assert(await app.locator('main .breadcrumb-trail:not([data-pwa-context])').first().isHidden());
const ids = await app.locator('.pd-ribbon-panel:not([hidden]) .pd-ribbon-command[data-command-identity]').evaluateAll(nodes => nodes.map(node => node.dataset.commandIdentity));
assert.equal(ids.length, new Set(ids).size);
assert(await app.evaluate(() => document.documentElement.scrollWidth <= innerWidth));
if (await app.locator('main h1 [data-help-url]').count()) assert.equal(await app.locator('.pd-context-help').count(), 1);
const pathname = route.split('?')[0];
if (/^\/(Projects\/Details|Books\/Details|Timeline$|PlotLineWorkspace$|StoryBible$|StoryCalendar$|PlotThreads$|StoryPoint$|Characters$|Locations$|ProjectMetrics$|Analytics$|Warnings$|Archives$)/.test(pathname)) {
await app.setViewportSize({ width: 1920, height: 1000 }); await oneRibbon(app);
const name = pathname.split('/').filter(Boolean).slice(0,2).join('-');
await app.screenshot({ path: `/tmp/pwa-completion-dev-${name}.png` });
}
}
stage = 'deployed Story Bible search/jump/help behavior';
await app.goto(base + `/StoryBible?${q}`);
if (await app.locator('#ribbon-surface').isHidden()) await app.locator('[data-ribbon-tab=tools]').click();
const search = app.locator('.pd-context-search input');
await search.fill('beth');
assert.equal(await app.locator('.pd-context-search .pd-context-submit').count(), 0);
await Promise.all([app.waitForURL(url => url.searchParams.get('q') === 'beth'), search.press('Enter')]);
await app.locator('.pd-context-search input').fill('beth integrated');
await Promise.all([app.waitForURL(url => url.searchParams.get('q') === 'beth integrated'), app.locator('.pd-context-search-submit').click()]);
await openGroup(app, 'Jump to');
await app.locator('[data-pwa-context-controls] a[href="#revision"]').click();
assert.equal(await app.evaluate(() => document.activeElement.id), 'revision');
await app.locator('.pd-context-help').click();
await app.waitForFunction(() => document.querySelector('[data-help-layout]')?.classList.contains('help-open'));
await app.waitForFunction(() => /Story Bible/i.test(document.querySelector('[data-help-drawer-heading]')?.textContent || ''));
await app.locator('[data-help-close]').click();
for (const theme of await app.locator('[data-app-theme-choice]').evaluateAll(nodes => nodes.map(node => node.dataset.appThemeChoice))) {
await app.evaluate(theme => { const root = document.documentElement; root.dataset.appTheme = theme; root.dataset.theme = root.dataset.bsTheme = theme.endsWith('-dark') ? 'dark' : 'light'; window.dispatchEvent(new Event('plotdirector:theme-changed')); }, theme);
await app.setViewportSize({ width: 2560, height: 1000 }); await oneRibbon(app);
await app.screenshot({ path: `/tmp/pwa-completion-story-bible-${theme}.png` });
}
stage = 'deployed Timeline scope';
await app.goto(base + `/Timeline?${q}`);
if (await app.locator('#ribbon-surface').isHidden()) await app.locator('[data-ribbon-tab=story]').click();
await app.locator('[data-pwa-context-controls] select').selectOption(String(identity.BookID));
await Promise.all([app.waitForURL(url => (url.searchParams.get('BookID') || url.searchParams.get('bookId')) === String(identity.BookID)), app.locator('[data-pwa-context-controls] button', { hasText: 'View' }).click()]);
stage = 'deployed archive cancellation';
await app.goto(base + `/Books/Details/${identity.BookID}`);
if (await app.locator('#ribbon-surface').isHidden()) await app.locator('[data-ribbon-tab=book]').click();
await openGroup(app, 'Manage');
await app.locator('[data-pwa-context-controls]').getByRole('button', { name: 'Archive Book', exact: true }).click();
await app.locator('#plotlineConfirmModal').waitFor({ state: 'visible' });
await app.locator('#plotlineConfirmModal button[data-bs-dismiss]').first().click();
await app.locator('#plotlineConfirmModal').waitFor({ state: 'hidden' });
assert.equal(new URL(app.url()).pathname, `/Books/Details/${identity.BookID}`);
for (const theme of await app.locator('[data-app-theme-choice]').evaluateAll(nodes => nodes.map(node => node.dataset.appThemeChoice))) {
await app.evaluate(theme => { const root = document.documentElement; root.dataset.appTheme = theme; root.dataset.theme = root.dataset.bsTheme = theme.endsWith('-dark') ? 'dark' : 'light'; window.dispatchEvent(new Event('plotdirector:theme-changed')); }, theme);
for (const width of [2560, 900]) {
await app.setViewportSize({ width, height: 1000 }); await oneRibbon(app);
assert(await app.evaluate(() => document.documentElement.scrollWidth <= innerWidth));
await app.screenshot({ path: `/tmp/pwa-ribbon-dev-book-${theme}-${width}.png` });
}
}
for (const [name, route] of [['timeline', `/Timeline?${q}&bookId=${identity.BookID}`], ['plot-lines', `/PlotLineWorkspace?${q}`], ['story-bible', `/StoryBible?${q}`], ['project', `/Projects/Details/${identity.ProjectID}`]]) {
await app.goto(base + route);
if (await app.locator('#ribbon-surface').isHidden()) await app.locator('[data-ribbon-tab][aria-selected=true]').click();
for (const width of [2560, 1920, 900]) {
await app.setViewportSize({ width, height: 1000 }); await oneRibbon(app);
await app.screenshot({ path: `/tmp/pwa-ribbon-dev-${name}-${width}.png` });
}
}
stage = 'live contextual object verification';
if (identity.SceneIDs?.length) await contextChecks.checkObjects(app, base, identity);
console.log('PASS authenticated Dev browser + real installed PWA: ' + routes.length + ' routes; deployed search, jump, correct Help drawer, Timeline scope, archive cancellation, one ribbon with no title strip at 2560/1920/900, all six themes; no human login or existing manuscript changes.');
} finally {
await cdp.send('PWA.uninstall', { manifestId }).catch(() => {});
await context.close(); fs.rmSync(profile, { recursive: true, force: true });
}
})().catch(() => { console.error('FAIL Dev PWA smoke at ' + stage + '; credentials withheld.'); process.exitCode = 1; });