const { chromium } = require('playwright'); const assert = require('node:assert/strict'); (async () => { const browser = await chromium.launch({ headless: true, executablePath: process.env.CHROMIUM_PATH }); const page = await browser.newPage({ viewport: { width: 1100, height: 760 } }); if (process.env.PLOT_ASSET_ORIGIN) { await page.route(/\/(?:css|js)\/plot-line-workspace\.(?:css|js)(?:\?.*)?$/, async route => { const response = await route.fetch({ url: process.env.PLOT_ASSET_ORIGIN + new URL(route.request().url()).pathname }); await route.fulfill({ response }); }); } const errors = []; page.on('pageerror', e => errors.push(e.message)); await page.route('**/Scenes/SceneThreadsEditor?**', route => route.fulfill({ body: '
' })); await page.goto('http://127.0.0.1:5238/plot-map-fixture'); // Extend the existing three-line fixture to exercise dragging through a long page. await page.evaluate(() => { const filter = document.getElementById('plot-workspace-form'); filter.classList.add('plot-workspace-controls'); filter.style.height = '180px'; document.querySelector('.plot-narrative-map').style.height = '2400px'; const strip = document.querySelector('.plot-scene-strip'); for (let i = 0; i < 20; i++) { const item = document.createElement('button'); item.textContent = 'Manuscript scene ' + i; strip.append(item); } }); await page.locator('[data-map-mode="associate"]').click(); await page.evaluate(() => { document.querySelector('.plot-scene-strip').scrollLeft = 90; window.scrollTo({ top: 900, behavior: 'instant' }); }); const tray = page.locator('#plot-association-strip'); assert.equal(await page.locator('#plot-workspace-form').evaluate(el => getComputedStyle(el).position), 'static'); assert.ok(await page.locator('#plot-workspace-form').evaluate(el => el.getBoundingClientRect().bottom < 0)); assert.ok(Math.abs((await tray.boundingBox()).y - 6) < 2); assert.equal(await page.locator('.plot-scene-strip').evaluate(el => el.scrollLeft), 90); assert.equal(await page.locator('.plot-map-scroll').evaluate(el => el.scrollHeight > el.clientHeight), false); await page.evaluate(() => { window.fixtureDrag = new DataTransfer(); document.querySelector('[data-associate-scene="103"]').dispatchEvent(new DragEvent('dragstart', { bubbles: true, dataTransfer: window.fixtureDrag })); }); const edge = async y => page.evaluate(y => { clearInterval(window.fixtureDragTimer); const emit = () => (document.elementFromPoint(600, y) || document.body).dispatchEvent(new DragEvent('dragover', { bubbles: true, cancelable: true, clientX: 600, clientY: y, dataTransfer: window.fixtureDrag })); emit(); window.fixtureDragTimer = setInterval(emit, 70); }, y); const position = () => page.evaluate(() => scrollY); const start = await position(); await edge(750); await page.waitForTimeout(450); assert.ok(await position() > start + 90, 'Bottom edge should scroll the page downward during the drag'); await edge(400); const middle = await position(); await page.waitForTimeout(160); assert.ok(Math.abs(await position() - middle) < 2, 'Leaving the edge zone must stop scrolling'); const top = Math.round((await tray.boundingBox()).y + (await tray.boundingBox()).height + 8); await edge(top); await page.waitForTimeout(400); assert.ok(await position() < middle - 80, 'Upper usable edge should scroll upward'); await edge(750); await page.waitForTimeout(150); await page.evaluate(() => { clearInterval(window.fixtureDragTimer); document.dispatchEvent(new DragEvent('dragend', { bubbles: true })); }); const ended = await position(); await page.waitForTimeout(180); assert.ok(Math.abs(await position() - ended) < 2, 'Drag end must stop scrolling'); assert.equal(await page.locator('.plot-scene-strip').evaluate(el => el.scrollLeft), 90); // Escape cancels an active scrolling drag, even if dragover events continue briefly. await page.evaluate(() => document.querySelector('[data-associate-scene="103"]').dispatchEvent(new DragEvent('dragstart', { bubbles: true, dataTransfer: window.fixtureDrag }))); await edge(750); await page.waitForTimeout(100); await page.keyboard.press('Escape'); const cancelled = await position(); await page.waitForTimeout(180); assert.ok(Math.abs(await position() - cancelled) < 2); await page.evaluate(() => clearInterval(window.fixtureDragTimer)); // Reach a lower route which starts below the viewport, then drop on the route itself. await page.evaluate(() => { const map = document.querySelector('.plot-narrative-map').getBoundingClientRect(); document.querySelector('.plot-horizontal-route[data-drop-line="3"]').style.top = `${innerHeight + 100 - map.top}px`; document.querySelector('[data-associate-scene="103"]').dispatchEvent(new DragEvent('dragstart', { bubbles: true, dataTransfer: window.fixtureDrag })); }); await edge(750); await page.waitForFunction(() => document.querySelector('.plot-horizontal-route[data-drop-line="3"]').getBoundingClientRect().bottom < innerHeight - 20); await page.evaluate(() => clearInterval(window.fixtureDragTimer)); const lower = page.locator('.plot-horizontal-route[data-drop-line="3"]'); const lowerRect = await lower.boundingBox(); const transfer = await page.evaluateHandle(() => window.fixtureDrag); await lower.dispatchEvent('dragover', { dataTransfer: transfer, clientX: 600, clientY: lowerRect.y + 15 }); assert.ok(await lower.evaluate(el => el.classList.contains('is-drop-target'))); await lower.dispatchEvent('drop', { dataTransfer: transfer, clientX: 600, clientY: lowerRect.y + 15 }); await page.locator('#plot-association-dialog form').waitFor(); assert.equal(await page.locator('#plot-association-dialog [name="PlotLineID"]').inputValue(), '3'); await page.locator('[data-association-close]').click(); await page.locator('[data-map-mode="view"]').dispatchEvent('click'); assert.equal(await tray.isVisible(), false); assert.equal(await page.locator('#plot-workspace-form').evaluate(el => getComputedStyle(el).position), 'sticky'); const card = page.locator('.plot-map-callout button').first(); await card.focus(); const cardRect = await card.boundingBox(); const preview = card.locator('.plot-callout-preview'); const previewRect = await preview.boundingBox(); assert.ok(previewRect.y >= cardRect.y + cardRect.height - 2, 'Focus preview should extend below the card'); assert.ok(Math.abs(previewRect.x - cardRect.x) < 2, 'Preview should align with its originating card'); assert.equal(await preview.evaluate(el => el.scrollHeight > el.clientHeight), false, 'Short previews should not have an internal scrollbar'); await card.hover(); assert.ok(await preview.isVisible()); assert.deepEqual(errors, []); await browser.close(); console.log('PASS: sticky association tray, normal filters, proportional page drag scrolling, stop/cancel, downward hover/focus previews'); })().catch(e => { console.error(e); process.exit(1); });