// Real public Razor views and auth forms; isolated host, no database or payment requests. // Start --toolbar-browser-host, then run: node PlotLine.Tests/Browser/public-site.cjs const { chromium } = require('playwright'); const assert = require('node:assert/strict'); const base = 'http://127.0.0.1:5238'; const themes = ['warm-light', 'warm-dark', 'modern-light', 'modern-dark', 'rose-pink', 'baby-blue']; (async () => { const browser = await chromium.launch(); const errors = []; try { for (const standalone of [false, true]) { const context = await browser.newContext({ viewport: { width: 1440, height: 960 }, reducedMotion: 'reduce' }); await context.addInitScript(mode => { Object.defineProperty(navigator, 'standalone', { value: mode }); localStorage.setItem('plotline.theme', 'dark'); localStorage.setItem('plotdirector.applicationTheme', 'rose-pink'); }, standalone); const page = await context.newPage(); page.on('pageerror', e => errors.push(e.message)); for (const theme of themes) { for (const name of ['home', 'tour', 'pricing']) { for (const anonymous of [false, true]) { assert.equal((await page.goto(`${base}/public-fixture/${name}?theme=${theme}&anonymous=${anonymous}`)).status(), 200); assert.equal(await page.locator('html').getAttribute('data-site-theme'), 'public'); assert.equal(await page.locator('html').getAttribute('data-app-theme'), null); assert.equal(await page.locator('html').getAttribute('data-bs-theme'), 'light'); assert.equal(await page.locator('.public-links a').allTextContents().then(a => a.join('|')), 'Home|Tour|Writing Solver|Pricing|Help'); assert.equal(await page.locator('[data-ribbon-shell]').count(), 0); assert.equal(await page.locator('body').evaluate(el => getComputedStyle(el).backgroundColor), 'rgb(252, 243, 229)'); assert.equal(await page.locator('.public-account').innerText().then(s => s.includes('Your workspace')), !anonymous); } } for (const name of ['login', 'register']) { await page.goto(`${base}/public-fixture/${name}?theme=${theme}`); assert.equal(await page.locator('html').getAttribute('data-app-theme'), standalone ? theme : null); assert.equal(await page.locator('html').getAttribute('data-site-theme'), standalone ? null : 'public'); assert(await page.locator('form input[name="__RequestVerificationToken"]').count()); } } // An expired session can still use the last non-sensitive device preference. await page.goto(base + '/public-fixture/login?anonymous=true'); assert.equal(await page.locator('html').getAttribute('data-app-theme'), standalone ? 'rose-pink' : null); // Client validation and the original login form contract still work. await page.locator('button[type="submit"]').click(); assert(await page.locator('[data-valmsg-for="Email"]').innerText()); assert(await page.locator('[data-valmsg-for="Password"]').innerText()); assert.match(await page.locator('form').getAttribute('action'), /Account\/Login$/); await page.locator('[name="Email"]').fill('fictional-author@example.invalid'); await page.locator('[name="Password"]').fill('Fictional-only-passphrase'); await page.locator('[name="Password"]').press('Tab'); await page.waitForFunction(() => !document.querySelector('.field-validation-error')); await page.route('**/Account/Login', route => route.fulfill({ contentType: 'text/html', body: 'Isolated form contract verified' })); const posted = page.waitForRequest(request => request.method() === 'POST' && new URL(request.url()).pathname === '/Account/Login'); await page.locator('button[type="submit"]').click(); const form = new URLSearchParams((await posted).postData()); assert.equal(form.get('Email'), 'fictional-author@example.invalid'); assert(form.get('__RequestVerificationToken')); // ReturnUrl remains an ordinary server form field, untouched by appearance code. assert(form.has('ReturnUrl')); await context.close(); } // First installed login defaults safely when there is no saved preference, including blocked storage. for (const blocked of [false, true]) { const firstVisit = await browser.newContext(); await firstVisit.addInitScript(blocked => { Object.defineProperty(navigator, 'standalone', { value: true }); if (blocked) Object.defineProperty(window, 'localStorage', { get() { throw new Error('Storage unavailable'); } }); }, blocked); const firstPage = await firstVisit.newPage(); firstPage.on('pageerror', e => errors.push(e.message)); await firstPage.goto(base + '/public-fixture/login?anonymous=true'); assert.equal(await firstPage.locator('html').getAttribute('data-app-theme'), 'warm-light'); await firstVisit.close(); } const page = await browser.newPage({ reducedMotion: 'reduce' }); page.on('pageerror', e => errors.push(e.message)); for (const width of [320, 390, 768, 1440]) { await page.setViewportSize({ width, height: 960 }); for (const name of ['home', 'tour', 'pricing', 'login', 'register']) { await page.goto(`${base}/public-fixture/${name}?anonymous=true`); assert(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1), `${name} overflows at ${width}`); assert(await page.locator('h1').isVisible()); await page.locator('img').evaluateAll(nodes => Promise.all(nodes.map(async img => { img.loading = 'eager'; await img.decode().catch(() => {}); }))); const broken = await page.locator('img').evaluateAll(nodes => nodes.filter(img => !img.complete || !img.naturalWidth).map(img => img.src)); assert.deepEqual(broken, [], `${name} screenshots load`); const primary = page.locator('main .marketing-btn--primary').first(); if (await primary.count()) assert(await primary.evaluate(el => getComputedStyle(el).color !== getComputedStyle(el).backgroundColor), 'CTA text readable'); assert.equal(await page.evaluate(() => getComputedStyle(document.documentElement).scrollBehavior), 'auto'); } } // A compact menu and sticky horizontal tour navigation remain operable on phones. await page.setViewportSize({ width: 390, height: 844 }); await page.goto(base + '/public-fixture/tour?anonymous=true'); await page.locator('.navbar-toggler').click(); assert(await page.locator('.public-links a').first().isVisible()); await page.locator('.tour-jump a[href="#plot-lines"]').click(); assert.equal(new URL(page.url()).hash, '#plot-lines'); const top = await page.locator('#plot-lines').evaluate(el => el.getBoundingClientRect().top); assert(top >= 50 && top < 180, 'jump heading clears sticky navigation'); await page.goto(base + '/public-fixture/pricing'); assert.equal(await page.locator('a[href*="billingInterval=Annual"]').count(), 3); assert.equal(await page.locator('a[href*="billingInterval=Monthly"]').count(), 3); assert.equal(await page.locator('.pricing-card').count(), 4); for (const url of ['/', '/features', '/about', '/contact', '/privacy', '/terms', '/help', '/help?q=scene']) { assert.equal((await page.goto(base + url)).status(), 200, url); assert.equal(await page.locator('html').getAttribute('data-site-theme'), 'public'); assert(await page.locator('link[rel="canonical"]').count()); } await page.goto(base + '/help'); await page.locator('[data-help-icon] button').first().click(); const more = page.locator('.popover a.plotline-help-more'); await more.waitFor(); const articlePath = new URL(await more.getAttribute('href'), base).pathname; await more.click(); await page.waitForURL(url => url.pathname === articlePath); assert(await page.locator('.help-markdown-body').isVisible()); assert.deepEqual(errors, []); console.log('PASS public theme isolation: all six themes, browser/standalone, signed in/out; authentication palette and validation; responsive layouts, assets, navigation, checkout links and public SEO.'); } finally { await browser.close(); } })().catch(error => { console.error(error); process.exitCode = 1; });