63 lines
4.5 KiB
JavaScript
63 lines
4.5 KiB
JavaScript
const assert = require('node:assert/strict');
|
||
const { chromium } = require('playwright');
|
||
const base = process.env.PD_BROWSER_FIXTURE_URL || 'http://127.0.0.1:5238';
|
||
(async () => {
|
||
const browser = await chromium.launch();
|
||
try {
|
||
for (const pwa of [false, true]) for (const width of [390, 800, 1440]) {
|
||
const context = await browser.newContext({viewport:{width,height:1000}});
|
||
if(pwa) await context.addInitScript(() => Object.defineProperty(navigator, 'standalone', {value:true}));
|
||
const page = await context.newPage();
|
||
for(const theme of ['modern-light','modern-dark','warm-light','warm-dark']) {
|
||
const response = await page.goto(`${base}/manuscript/reader?bookId=12&chapterId=21`);
|
||
assert.equal(response.status(),200);
|
||
assert.match(response.headers()['cache-control'],/no-store/);
|
||
assert.match(response.headers()['x-robots-tag'],/noindex/);
|
||
await page.evaluate(theme => PlotDirectorApplyApplicationTheme(theme), theme);
|
||
await page.locator('.writer3-flow').waitFor(); // The reader alias now uses the measured shared workspace.
|
||
const paragraphs = page.locator('.reader-paragraph');
|
||
assert.equal(await paragraphs.count(),3);
|
||
assert.match(await paragraphs.nth(1).textContent(), /First paragraph: <script>unsafe\(\)<\/script>/);
|
||
assert.equal(await page.locator('.reader-page script').count(),0);
|
||
assert.match(await paragraphs.nth(2).textContent(),/Second paragraph/);
|
||
assert.equal(await page.locator('.reader-page').evaluate(node => getComputedStyle(node).userSelect),'auto');
|
||
const selected = await page.locator('.reader-page').evaluate(node => {
|
||
const range = document.createRange(); range.selectNodeContents(node);
|
||
const selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range); return selection.toString();
|
||
});
|
||
assert.match(selected,/First paragraph/); assert.match(selected,/Second paragraph/);
|
||
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), 'No horizontal overflow');
|
||
const box = await page.locator('.reader-page').boundingBox(); assert.ok(box.width <= 740,'Reading column bounded');
|
||
assert.ok(await page.locator('time').first().getAttribute('datetime') === '2026-11-13T10:12:13Z');
|
||
await page.getByRole('button',{name:'Focus reading',exact:true}).click();
|
||
assert.equal(await page.locator('body').evaluate(n=>n.classList.contains('reader-focused')),true);
|
||
await page.keyboard.press('Escape');
|
||
assert.equal(await page.getByRole('button',{name:'Focus reading',exact:true}).getAttribute('aria-pressed'),'false');
|
||
await page.getByRole('link',{name:'Next chapter →',exact:true}).click();
|
||
await page.waitForURL(/chapterId=22/);
|
||
assert.match(await page.locator('.reader-page').textContent(),/Another chapter only/);
|
||
assert.doesNotMatch(await page.locator('.reader-page').textContent(),/First paragraph/);
|
||
await page.getByLabel('Chapter',{exact:true}).selectOption('23');
|
||
await page.getByRole('button',{name:'Read',exact:true}).click();
|
||
await page.waitForURL(/chapterId=23/);
|
||
assert.match(await page.locator('.reader-empty').textContent(),/No accepted manuscript text/);
|
||
assert.equal(await page.getByRole('link',{name:'Next chapter →',exact:true}).count(),0);
|
||
await page.getByRole('link',{name:'← Previous chapter',exact:true}).click();
|
||
await page.waitForURL(/chapterId=22/);
|
||
}
|
||
await context.addCookies([{name:'fixture-user',value:'5',url:base}]);
|
||
assert.equal((await page.goto(`${base}/manuscript/reader?bookId=12&chapterId=21`)).status(),404);
|
||
await context.clearCookies();
|
||
assert.equal((await page.goto(`${base}/manuscript/reader?bookId=13&chapterId=21`)).status(),404);
|
||
assert.equal((await page.goto(`${base}/manuscript/reader?bookId=12&chapterId=999`)).status(),404);
|
||
const unavailable = await page.goto(`${base}/manuscript/reader?bookId=12&chapterId=21&reader-error=true`);
|
||
assert.equal(unavailable.status(),503);
|
||
assert.equal(await page.getByRole('link',{name:'Retry',exact:true}).count(),1);
|
||
assert.doesNotMatch(await page.locator('body').textContent(),/First paragraph|Synthetic unavailable/);
|
||
const post = await context.request.post(`${base}/manuscript/reader?bookId=12`); assert.equal(post.status(),405);
|
||
await context.close();
|
||
}
|
||
console.log('PASS Manuscript Reader: real Razor/controller, escaped selectable text, chapter navigation, empty state, timestamps, private headers, account isolation, GET-only, focus, 3 widths × 4 themes × browser/PWA');
|
||
} finally { await browser.close(); }
|
||
})().catch(error => { console.error(error);process.exitCode=1; });
|