10 lines
5.3 KiB
JavaScript
10 lines
5.3 KiB
JavaScript
const{chromium}=require('playwright'),fs=require('fs'),assert=require('node:assert/strict');
|
|
(async()=>{const browser=await chromium.launch();try{const page=await browser.newPage({viewport:{width:1200,height:800}});let date='1983-11-19',reads=0;await page.route('**/Writing/Context/Calendar/State*',r=>{reads++;return r.fulfill({json:{books:[],scenes:[{bookID:1,bookLabel:'Book 1',chapterID:1,chapterNumber:1,chapterTitle:'One',sceneID:1,sceneNumber:1,title:'First',summary:'Saved summary <safe>',date},{bookID:1,bookLabel:'Book 1',chapterID:1,chapterNumber:1,chapterTitle:'One',sceneID:2,sceneNumber:2,title:'Second',date},{bookID:2,bookLabel:'Book 2',chapterID:2,chapterNumber:1,chapterTitle:'Two',sceneID:3,sceneNumber:1,title:'Other book',date},...Array.from({length:12},(_,i)=>({bookID:1,bookLabel:'Book 1',chapterID:10+i,chapterNumber:10+i,chapterTitle:'Busy date',sceneID:10+i,sceneNumber:1,title:'Busy scene',date:'1983-11-21'}))]}});});await page.route('https://calendar.test/',r=>r.fulfill({body:'<html></html>',contentType:'text/html'}));await page.goto('https://calendar.test');
|
|
const partial=fs.readFileSync('PlotLine/Views/Writing/_ContextCalendar.cshtml','utf8').split('\n').slice(2).join('\n');await page.setContent('<div class="context-pane-content" style="height:650px;container-type:inline-size" data-context-pane="0">'+partial+'</div>');await page.addStyleTag({content:fs.readFileSync('PlotLine/wwwroot/css/context-calendar.css','utf8')});for(const file of ['context-calendar-model.js','context-calendar.js'])await page.addScriptTag({path:'PlotLine/wwwroot/js/'+file});await page.evaluate(()=>{window.node=document.querySelector('[data-context-calendar]');window.life=PlotDirectorContextLifecycles.calendar;life.mount(node,{position:{bookId:1,chapterId:1,sceneId:1}});});await page.locator('[data-calendar-date="1983-11-19"]').waitFor();assert.equal(await page.locator('[data-calendar-date="1983-11-19"] .context-calendar-chapter').textContent(),'Ch 1');assert.equal(await page.locator('[data-calendar-date="1983-11-19"] small').count(),0);
|
|
await page.selectOption('[data-calendar-books]','all');assert.equal(await page.locator('[data-calendar-date="1983-11-19"] .context-calendar-chapter:visible').count(),2);assert.equal(await page.locator('[data-calendar-date="1983-11-19"] .context-calendar-more:visible').count(),0);
|
|
await page.locator('[data-calendar-date="1983-11-19"] .context-calendar-chapter').first().click();assert.equal(await page.locator('[data-calendar-details]>details').first().getAttribute('open'),'');await page.locator('[data-calendar-details] details details summary').first().click();assert.equal(await page.locator('.context-calendar-scene-summary').first().textContent(),'Saved summary <safe>');assert.equal(await page.locator('.context-calendar-scene-summary script').count(),0);
|
|
await page.locator('[data-calendar-from]').fill('1983-11-01');await page.locator('[data-calendar-from]').dispatchEvent('change');assert.equal(await page.locator('[data-calendar-elapsed]').textContent(),'18 days · 2 weeks, 4 days');const busy=page.locator('[data-calendar-date="1983-11-21"]');await page.waitForFunction(()=>!document.querySelector('[data-calendar-date="1983-11-21"] .context-calendar-more').hidden);const visible=await busy.locator('.context-calendar-chapter:visible').count();assert(visible>0&&visible<12);assert.equal(await busy.locator('.context-calendar-more').textContent(),'+'+(12-visible));await busy.locator('.context-calendar-more').click();assert.match(await page.locator('[data-calendar-details]').textContent(),/12 chapters · 12 scenes/);
|
|
await page.locator('[data-calendar-date="1983-11-20"] .context-calendar-day-number').click();await page.evaluate(()=>life.onPosition(node,{bookId:1,chapterId:2,sceneId:99}));assert.equal(await page.locator('[data-calendar-month]').inputValue(),'1983-11');assert.equal(await page.locator('[data-calendar-date="1983-11-20"]').getAttribute('data-selected'),'true');
|
|
await page.locator('[data-calendar-month]').fill('2020-08');await page.locator('[data-calendar-month]').dispatchEvent('change');assert.equal(await page.locator('[data-calendar-grid] [data-calendar-date]').count(),42);assert((await page.locator('[data-calendar-grid]').boundingBox()).height>300);await page.evaluate(()=>life.onPosition(node,{bookId:1,chapterId:1,sceneId:1}));assert.equal(await page.locator('[data-calendar-month]').inputValue(),'2020-08');assert.equal(await page.locator('[data-calendar-from]').inputValue(),'1983-11-01');date='1984-01-01';await page.evaluate(()=>life.onInvalidation(node));await page.waitForFunction(()=>document.querySelector('[data-calendar-status]').textContent.includes('1984'));assert.equal(await page.locator('[data-calendar-month]').inputValue(),'2020-08');await page.locator('[data-calendar-return]').click();assert.equal(await page.locator('[data-calendar-month]').inputValue(),'1984-01');assert.equal(await page.locator('[data-calendar-date="1984-01-01"]').getAttribute('aria-current'),'date');assert(reads>=2);
|
|
await page.evaluate(()=>{life.dispose(node);life.mount(node,{position:{bookId:1,chapterId:1,sceneId:1}});});await page.locator('[data-calendar-date="1984-01-01"]').waitFor();console.log('PASS Calendar lifecycle: deduplication, all-books collision, local hold, undated position, six-row geometry, saved refresh preserves browsing, Return to Scene and remount');}finally{await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;});
|