Refactor architecture into eight components and consolidate reliability work
Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts. Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation. Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
This commit is contained in:
1 parent
9dd425f765
commit
d5d21b7841
302 files changed
+20037
-3492
No files matched your search
@@ -0,0 +1,26 @@
|
||||
const {test} = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const {destination, resolvePath} = require('../../../static/js/browser-address.js');
|
||||
|
||||
test('absolute, relative and virtual paths use the browser route', () => {
|
||||
assert.equal(destination('/docs/new').href, '/v/browser/docs/new');
|
||||
assert.equal(destination('child', '/docs').href, '/v/browser/docs/child');
|
||||
assert.equal(destination('cd ../new', '/docs/old').path, '/docs/new');
|
||||
assert.equal(destination('cd', '/docs').path, '/');
|
||||
assert.equal(destination('cd ../../../../', '/docs').path, '/');
|
||||
assert.equal(destination('./a//b/./c/..', '/docs').path, '/docs/a/b');
|
||||
});
|
||||
test('editor and viewer commands preserve names and avoid adapter-route ambiguity', () => {
|
||||
assert.equal(destination('vi plain/example', '/').href, '/e/-/plain/example');
|
||||
assert.equal(destination('view', '/docs/page').href, '/docs/page');
|
||||
assert.equal(destination('vi file name', '/docs').href, '/e/-/docs/file%20name');
|
||||
assert.equal(destination('vi 日記 #1?%25', '/docs').href, '/e/-/docs/%E6%97%A5%E8%A8%98%20%231%3F%2525');
|
||||
assert.equal(destination('/cd', '/docs').path, '/cd');
|
||||
assert.equal(destination('view a;rm -rf', '/').href, '/a%3Brm%20-rf');
|
||||
});
|
||||
test('schemes, network paths and controls are not accepted', () => {
|
||||
for (const value of ['https://outside.test', '//outside.test', 'javascript:alert(1)', 'file:///etc/passwd', 'a\\b', '/a\n/b', '/a\u0000b']) {
|
||||
assert.throws(() => resolvePath(value), /invalid_path/);
|
||||
}
|
||||
assert.equal(destination('view /%2f%2fevil.test').href, '/%252f%252fevil.test');
|
||||
});
|
||||
+7
@@ -44,6 +44,13 @@ window.addEventListener('load', async () => {
|
||||
checkLabels('.city-generated-street-label');
|
||||
activate(document.querySelector('.city-street-tile'));
|
||||
await wait(() => document.querySelector('.city-undefined-page-label'));
|
||||
const entrance = document.querySelector('.city-spot-point-label');
|
||||
if (!entrance || /undefined|未定義|未分類/i.test(entrance.textContent)) throw new Error('Internal placeholder label is visible');
|
||||
activate(document.querySelector('.city-spot-entry'));
|
||||
await wait(() => document.querySelector('.city-spot-monument'));
|
||||
if (document.querySelector('[data-city-trail] [aria-current="location"]')?.textContent !== entrance.querySelector('title')?.textContent) throw new Error('Spot breadcrumb differs from display title');
|
||||
activate(document.querySelector('[data-city-level="street"]'));
|
||||
await wait(() => document.querySelector('.city-undefined-page-label'));
|
||||
checkLabels('.city-generated-street-label,.city-undefined-page-label');
|
||||
toggleLabels(false);
|
||||
if (getComputedStyle(document.querySelector('.city-undefined-page-label')).display !== 'none')
|
||||
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
(async () => {
|
||||
const assert=(ok,message)=>{if(!ok)throw Error(message)};
|
||||
const wait=async test=>{for(let n=0;n<160;n++){if(test())return;await new Promise(r=>setTimeout(r,25))}throw Error('Timed out: '+test)};
|
||||
const frame=document.createElement('iframe');frame.style='width:100%;height:930px;border:0';document.body.append(frame);
|
||||
const load=path=>new Promise(resolve=>{frame.onload=resolve;frame.src=path});
|
||||
const key=(d,target,key,extras={})=>target.dispatchEvent(new frame.contentWindow.KeyboardEvent('keydown',{key,bubbles:true,cancelable:true,...extras}));
|
||||
try {
|
||||
await load('/');let d=frame.contentDocument;
|
||||
assert(!d.querySelector('[data-command-bar]'),'Home has command interception');
|
||||
await load('/v/browser/notes');d=frame.contentDocument;
|
||||
let bar=d.querySelector('[data-command-bar]'),input=bar.querySelector('input');
|
||||
assert(!bar.hidden && bar.parentElement===d.body,'Command bar not at body level');
|
||||
assert(d.querySelector('.topbar [data-browser-address]'),'Address not integrated with topbar');
|
||||
assert(!!d.querySelector('[data-browser-address]').getClientRects().length === (innerWidth>1100),'Responsive address visibility');
|
||||
key(d,d.body,'c');assert(input===d.activeElement&&input.value==='c','Type-to-command lost first character');
|
||||
input.value='cd al';input.dispatchEvent(new Event('input',{bubbles:true}));key(d,input,'Tab');
|
||||
await wait(()=>input.value==='cd alpha');key(d,input,'Tab');assert(input.value==='cd alpine','Tab did not cycle');
|
||||
key(d,input,'Tab',{shiftKey:true});assert(input.value==='cd alpha','Shift Tab did not cycle back');
|
||||
key(d,input,'Escape');assert(!bar.hidden&&input.value==='','Browser Escape must clear, not remove bar');
|
||||
input.focus();input.value='cd /not-committed';input.dispatchEvent(new frame.contentWindow.CompositionEvent('compositionstart',{bubbles:true}));bar.requestSubmit();assert(frame.contentWindow.location.pathname==='/v/browser/notes','IME confirmation navigated');input.dispatchEvent(new frame.contentWindow.CompositionEvent('compositionend',{bubbles:true}));input.value='';
|
||||
const other=d.createElement('input');d.body.append(other);other.focus();key(d,other,'x');assert(input.value===''&&d.activeElement===other,'Other input intercepted');other.remove();
|
||||
const modal=d.createElement('dialog');d.body.append(modal);modal.showModal();key(d,d.body,'x');assert(input.value==='','Modal intercepted');modal.close();modal.remove();
|
||||
const fetchBefore=frame.contentWindow.fetch;
|
||||
let release;
|
||||
frame.contentWindow.fetch=()=>new Promise(resolve=>{release=resolve});
|
||||
input.focus();input.value='vi stale';input.dispatchEvent(new Event('input',{bubbles:true}));key(d,input,'Tab');
|
||||
key(d,input,'Escape');release(new Response(JSON.stringify({entries:[{name:'stale',kind:'file'}]}),{headers:{'Content-Type':'application/json'}}));
|
||||
await new Promise(r=>setTimeout(r,30));assert(input.value===''&&bar.querySelector('[role=listbox]').hidden,'Stale completion reopened list');frame.contentWindow.fetch=fetchBefore;
|
||||
input.focus();input.value='cd /日本';input.dispatchEvent(new Event('input',{bubbles:true}));key(d,input,'Tab');await wait(()=>input.value==='cd /日本語 #?/');
|
||||
key(d,input,'Tab');await wait(()=>input.value==='cd /日本語 #?/child');
|
||||
input.value='cd /notes';input.dispatchEvent(new Event('input',{bubbles:true}));
|
||||
await new Promise(resolve=>{frame.onload=resolve;bar.requestSubmit()});assert(frame.contentWindow.location.pathname==='/v/browser/notes','Command navigation failed');
|
||||
await load('/notes');d=frame.contentDocument;bar=d.querySelector('[data-command-bar]');input=bar.querySelector('input');
|
||||
assert(bar.hidden,'Viewer command bar initially open');key(d,d.body,'g');assert(!bar.hidden&&d.activeElement===input&&input.value==='','g activation failed');
|
||||
key(d,input,'Escape');assert(bar.hidden,'Viewer Escape failed');
|
||||
const code=d.querySelector('.page-html pre code');
|
||||
await wait(()=>code?.querySelector('.pw-syntax-keyword'));
|
||||
assert(!code.querySelector('script')&&code.textContent.includes('<script>literal<'+'/script>'),'Highlight interpreted HTML');
|
||||
const original=code.textContent,keyword=code.querySelector('.pw-syntax-keyword');
|
||||
const theme=d.querySelector('[data-theme-select]');
|
||||
const change=async value=>{theme.value=value;theme.dispatchEvent(new frame.contentWindow.Event('change',{bubbles:true}));await wait(()=>!theme.disabled);await new Promise(r=>setTimeout(r,60))};
|
||||
await change('index-white');const light=frame.contentWindow.getComputedStyle(keyword).color;
|
||||
await change('nanoha-dark');assert(light!==frame.contentWindow.getComputedStyle(keyword).color,'Viewer syntax did not follow theme');
|
||||
assert(code.textContent===original,'Theme changed code text');
|
||||
const viewerTarget=d.createElement('div');d.body.append(viewerTarget);
|
||||
const viewer=frame.contentWindow.PagesWikiEditor.createViewer(viewerTarget,'def sample():\n return "value"','python');
|
||||
await wait(()=>viewerTarget.querySelector('.pw-syntax-keyword'));
|
||||
assert(frame.contentWindow.getComputedStyle(viewerTarget.querySelector('.pw-syntax-keyword')).color===frame.contentWindow.getComputedStyle(keyword).color,'File viewer and code block palettes differ');viewer.destroy();viewerTarget.remove();
|
||||
for(const option of theme.options){if(!option.value)continue;await change(option.value);assert(frame.contentWindow.getComputedStyle(keyword).color!=='rgba(0, 0, 0, 0)','Invisible theme token');assert(code.textContent===original,'Theme altered code');}
|
||||
const late=d.createElement('pre'), lateCode=d.createElement('code');lateCode.className='language-js';lateCode.textContent='const number = 42;';late.append(lateCode);code.closest('.page-html').append(late);late.scrollIntoView();await wait(()=>lateCode.querySelector('.pw-syntax-keyword'));
|
||||
const large=d.createElement('code');large.className='language-python';large.textContent='return 1;'.repeat(5000);const largePre=d.createElement('pre');largePre.append(large);code.closest('.page-html').append(largePre);largePre.scrollIntoView();await new Promise(r=>setTimeout(r,80));assert(!large.querySelector('span'),'Unbounded large block parsed');largePre.remove();late.remove();
|
||||
await load('/e/-/editor-fixture?edittype=markdown');d=frame.contentDocument;
|
||||
await wait(()=>frame.contentWindow.PagesWikiCodeMirror);
|
||||
const editor=frame.contentWindow.PagesWikiCodeMirror;editor.focus();key(d,editor.contentDOM,'g');assert(d.querySelector('[data-command-bar]').hidden,'Vim g intercepted');
|
||||
editor.dispatch({changes:{from:0,to:editor.state.doc.length,insert:'```python\ndef sample():\n return "value"\n```'}});
|
||||
await wait(()=>d.querySelector('.cm-content .pw-syntax-keyword'));
|
||||
// End on the browser UI for visual review.
|
||||
await load('/v/browser/notes');d=frame.contentDocument;bar=d.querySelector('[data-command-bar]');input=bar.querySelector('input');
|
||||
if(innerWidth<800){assert(d.documentElement.scrollWidth<=frame.clientWidth+1,'Browser overflows mobile');frame.contentWindow.toggleSidebar();assert(d.querySelector('.browser-sidebar').getClientRects().length,'Mobile sidebar cannot open');frame.contentWindow.toggleSidebar();}
|
||||
input.focus();input.value='view al';input.dispatchEvent(new Event('input',{bubbles:true}));key(d,input,'Tab');await wait(()=>input.value==='view alpha');
|
||||
document.body.dataset.vimReady='1';
|
||||
} catch(error){const out=document.createElement('pre');out.id='error';out.textContent=error.stack;document.body.append(out)}
|
||||
})();
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
(async () => {
|
||||
const assert=(ok,message)=>{if(!ok)throw Error(message)};
|
||||
const delay=ms=>new Promise(r=>setTimeout(r,ms));
|
||||
const wait=async fn=>{for(let i=0;i<150;i++){if(fn())return;await delay(25)}throw Error('Editor condition timed out')};
|
||||
try {
|
||||
const frame=document.createElement('iframe');frame.style='width:100%;height:930px;border:0';document.body.append(frame);
|
||||
await new Promise(resolve=>{frame.onload=resolve;frame.src='/e/-/editor-fixture?edittype=html'});
|
||||
const w=frame.contentWindow,d=frame.contentDocument;
|
||||
await wait(()=>w.PagesWikiCodeMirror&&d.querySelector('#preview h1'));
|
||||
const e=w.PagesEditor, cm=w.PagesWikiCodeMirror, realFetch=w.fetch;
|
||||
e.paused=true;
|
||||
assert(e.owner,'Owner namespace missing');
|
||||
assert(e.baseRevision,'Base revision missing');
|
||||
// Real CodeMirror updates must mark dirty and store an authoring draft.
|
||||
cm.dispatch({changes:{from:0,to:cm.state.doc.length,insert:'<h1>Local</h1><p>one two three</p>'}});
|
||||
assert(e.dirty,'CodeMirror did not mark dirty');e.persist();
|
||||
const key=e.keyPrefix()+e.tab;
|
||||
assert(JSON.parse(w.localStorage.getItem(key)).text.includes('Local'),'Missing local draft');
|
||||
w.fetch=async()=>{throw Error('offline fixture')};
|
||||
assert(await e.saveNow()===false&&e.paused,'Offline save was not paused');
|
||||
assert(e.text().includes('Local')&&w.localStorage.getItem(key),'Offline save lost text');
|
||||
w.fetch=async()=>new w.Response('expired',{status:401});
|
||||
assert(await e.saveNow()===false&&d.querySelector('#editor-save-status').dataset.state==='auth','Expiry undetected');
|
||||
w.fetch=realFetch;
|
||||
assert(await e.saveNow(),'Manual retry failed');assert(!w.localStorage.getItem(key),'Saved draft not cleared');
|
||||
// Another transaction changes the same title: manual review, never overwrite.
|
||||
const base=e.baseRevision;
|
||||
const remote=await e.post('/_/api/v1/revisions/save',{object_uuid:e.value('object-uuid'),body:'<h1>Remote</h1><p>one two three</p>',lang:'und',content_type:'text/html',base_revision_uuid:base,editor_principal_uuid:e.owner});
|
||||
e.paused=true;e.setText('<h1>Mine</h1><p>one two three</p>');
|
||||
assert(await e.saveNow()===false,'Stale edit silently saved');
|
||||
assert(d.querySelector('#editor-dialog textarea[readonly]'),'Conflict comparison missing');
|
||||
assert((await e.state()).revision_uuid===remote.revision_uuid,'Remote overwritten');
|
||||
const areas=d.querySelectorAll('#editor-dialog textarea');areas[areas.length-1].value='<h1>Resolved</h1><p>one two three</p>';
|
||||
d.querySelector('#editor-dialog footer button:last-child').click();await wait(()=>!d.querySelector('#editor-dialog'));
|
||||
assert(await e.saveNow(),'Conflict resolution not saved');
|
||||
// A save response can be lost; retry acknowledges the already saved head.
|
||||
e.paused=true;e.setText('<h1>Acknowledged</h1>');
|
||||
let lost=false;
|
||||
w.fetch=async(url,opts)=>{const response=await realFetch(url,opts);if(String(url).includes('revisions/save')&&!lost){lost=true;throw Error('lost response')}return response};
|
||||
assert(!await e.saveNow(),'Lost response incorrectly successful');
|
||||
w.fetch=realFetch;await e.saveNow();assert(!e.dirty,'Retry did not acknowledge saved head');
|
||||
// Preserve newly typed text while converting / saving an older snapshot.
|
||||
e.paused=true;e.setText('# Markdown','markdown');
|
||||
let release,entered=false;
|
||||
w.fetch=async(url,opts)=>{if(String(url).includes('render/markdown')&&!JSON.parse(opts.body).projection){entered=true;await new Promise(r=>release=r)}return realFetch(url,opts)};
|
||||
const pending=e.saveNow();await wait(()=>entered);
|
||||
e.setText('# Newer');release();await pending;w.fetch=realFetch;
|
||||
assert(e.dirty&&e.text()==='# Newer','Typing during save was lost');e.paused=true;clearTimeout(e.autosaveTimer);
|
||||
assert(await e.saveNow(),'Newer text save failed');
|
||||
// Format changes preserve preview visibility and complete a safe conversion.
|
||||
w.setEditorPreviewVisible(false);e.paused=true;
|
||||
await e.switchFormat('html');await e.switchFormat('markdown');
|
||||
assert(d.querySelector('#preview').hidden,'Format switch changed preview state');
|
||||
assert(e.text().includes('Newer'),'Format switch lost source');
|
||||
// Recover a draft into a new tab key and remove only that recovered snapshot.
|
||||
e.persist();const oldKey=e.keyPrefix()+e.tab;e.tab=w.crypto.randomUUID();
|
||||
e.offerRecovery();d.querySelector('#editor-dialog footer button:nth-child(2)').click();
|
||||
await wait(()=>!d.querySelector('#editor-dialog'));
|
||||
assert(w.localStorage.getItem(e.keyPrefix()+e.tab),'Recovery not stored');
|
||||
assert(!w.localStorage.getItem(oldKey),'Recovered draft would reappear after save');
|
||||
// Restore is staged locally, then creates a new revision on confirmation.
|
||||
const beforeRestore=(await e.state()).revision_uuid;
|
||||
await e.historyDialog();
|
||||
const revisions=d.querySelector('#editor-dialog select');revisions.selectedIndex=revisions.options.length-1;
|
||||
d.querySelector('#editor-dialog footer button:last-child').click();await wait(()=>!d.querySelector('#editor-dialog'));
|
||||
assert((await e.state()).revision_uuid===beforeRestore,'Restore wrote before confirmation');
|
||||
assert(e.text().includes('Base'),'Old revision not loaded');assert(await e.saveNow(),'Restore save failed');
|
||||
assert(e.baseRevision!==beforeRestore,'Restore did not append revision');
|
||||
// Separate ranges automatically merge, then repeat CAS against the new head.
|
||||
e.paused=true;e.setText('<p>left middle right</p>','html');assert(await e.saveNow(),'Merge base save failed');
|
||||
await e.post('/_/api/v1/revisions/save',{object_uuid:e.value('object-uuid'),body:'<p>left middle RIGHT</p>',lang:'und',content_type:'text/html',base_revision_uuid:e.baseRevision,editor_principal_uuid:e.owner});
|
||||
e.paused=true;e.setText('<p>LEFT middle right</p>');await e.saveNow();
|
||||
await wait(()=>!e.dirty);
|
||||
assert((await e.state()).body==='<p>LEFT middle RIGHT</p>','Automatic merge lost a side');
|
||||
// Protected HTML survives an actual Markdown edit and canonical save.
|
||||
const html='<figure data-custom="retained"><img src="/photo" alt="Photo"><figcaption>Caption</figcaption></figure>';
|
||||
e.paused=true;e.setText(html,'html');await e.switchFormat('markdown');
|
||||
assert(e.text().includes('{=html}'),'Lossy HTML was not protected');
|
||||
e.setText(e.text().replace('Caption','Edited caption'));
|
||||
assert(await e.saveNow(),'Protected HTML save failed');
|
||||
assert((await e.state()).body===html.replace('Caption','Edited caption'),'Protected HTML attributes or structure changed');
|
||||
// Conversion failure must never save raw Markdown as HTML.
|
||||
e.paused=true;e.setText('# Conversion failure');
|
||||
const head=e.baseRevision;
|
||||
w.fetch=async(url,opts)=>String(url).includes('render/markdown')?new w.Response('failed',{status:503}):realFetch(url,opts);
|
||||
assert(!await e.saveNow(),'Conversion failure saved anyway');w.fetch=realFetch;
|
||||
assert((await e.state()).revision_uuid===head,'Conversion failure created revision');
|
||||
// Fork uses a new empty head for the target language; original stays intact.
|
||||
e.languageDialog();d.querySelector('#editor-dialog input').value='en';
|
||||
d.querySelector('#editor-dialog footer button:last-child').click();await wait(()=>!d.querySelector('#editor-dialog'));
|
||||
assert(e.value('page-language')==='en'&&e.baseRevision==='','Language fork did not reset head');
|
||||
assert(await e.saveNow(),'Language fork save failed');
|
||||
assert((await e.state({lang:'und'})).revision_uuid===head,'Fork changed source language');
|
||||
// Mobile always starts in insert mode, regardless of desktop preference.
|
||||
const originalMedia=w.matchMedia;w.matchMedia=q=>q==='(pointer: coarse) and (hover: none)'?{matches:true}:originalMedia(q);
|
||||
w.PagesWikiCodeMirror.destroy();w.PagesWikiCodeMirror=w.PagesWikiEditor.create(e.mount,'{{child}}','markdown',{keymap:'vim',autocomplete:true});
|
||||
assert(d.querySelector('#editor-vim-mode').textContent==='INSERT','Mobile Vim not disabled');
|
||||
const mobile=w.PagesWikiCodeMirror;mobile.dispatch({selection:{anchor:7}});mobile.focus();
|
||||
mobile.contentDOM.dispatchEvent(new w.KeyboardEvent('keydown',{key:' ',code:'Space',ctrlKey:true,bubbles:true}));
|
||||
await wait(()=>d.querySelector('.cm-tooltip-autocomplete li'));
|
||||
await delay(100);
|
||||
mobile.contentDOM.dispatchEvent(new w.KeyboardEvent('keydown',{key:'Enter',code:'Enter',bubbles:true}));
|
||||
assert(mobile.state.doc.toString()==='{{children}}','Macro completion duplicated brackets: '+mobile.state.doc);
|
||||
// Escape must not enter Vim normal mode on mobile.
|
||||
mobile.contentDOM.dispatchEvent(new w.KeyboardEvent('keydown',{key:'Escape',bubbles:true}));
|
||||
assert(d.querySelector('#editor-vim-mode').textContent==='INSERT','Mobile Vim mode active');
|
||||
w.matchMedia=originalMedia;
|
||||
e.paused=true;clearTimeout(e.autosaveTimer);clearInterval(e.stateTimer);
|
||||
e.tools();
|
||||
const style=w.getComputedStyle(d.querySelector('#editor-dialog'));
|
||||
assert(style.color!==style.backgroundColor&&style.backgroundColor!=='rgba(0, 0, 0, 0)','Dialog not themed');
|
||||
document.body.dataset.vimReady='true';
|
||||
} catch(error) {const box=document.createElement('div');box.id='error';box.textContent=error.stack||error.message;document.body.prepend(box)}
|
||||
})();
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
(async () => {
|
||||
const assert = (ok, message) => { if (!ok) throw Error(message); };
|
||||
const wait = async check => { for (let n=0;n<150;n++) { if(check()) return; await new Promise(r=>setTimeout(r,25)); } throw Error('Timed out: '+check); };
|
||||
const frame = document.createElement('iframe'); frame.style='width:100%;height:950px;border:0'; document.body.append(frame);
|
||||
try {
|
||||
await new Promise(resolve => { frame.onload=resolve; frame.src='/e/-/editor-fixture?edittype=html'; });
|
||||
const w=frame.contentWindow, d=frame.contentDocument;
|
||||
await wait(() => w.PagesWikiCodeMirror);
|
||||
const editor=w.PagesWikiCodeMirror, e=w.PagesEditor;
|
||||
e.paused=true;
|
||||
const before=editor.state.doc.toString();
|
||||
const select=d.querySelector('[data-theme-select]');
|
||||
const change=async id=>{
|
||||
select.value=id; select.dispatchEvent(new w.Event('change',{bubbles:true}));
|
||||
await wait(()=>!select.disabled);
|
||||
await new Promise(r=>setTimeout(r,80));
|
||||
assert(!d.querySelector('[data-theme-status]').textContent,'Theme loading error');
|
||||
};
|
||||
await change('light');
|
||||
assert(w.getComputedStyle(editor.dom).backgroundColor==='rgb(247, 247, 247)','Light theme editor remained dark');
|
||||
assert(w.getComputedStyle(editor.contentDOM).color==='rgb(32, 32, 32)','Light editor text is not dark');
|
||||
const token=[...d.querySelectorAll('.cm-line span')].find(el=>el.textContent==='h1');
|
||||
assert(token && w.getComputedStyle(token).color!==w.getComputedStyle(editor.contentDOM).color,'Semantic syntax colors missing');
|
||||
editor.focus(); await new Promise(r=>setTimeout(r,100));
|
||||
const cursor=d.querySelector('.cm-fat-cursor,.cm-cursor');
|
||||
assert(cursor && parseFloat(w.getComputedStyle(cursor).borderBottomWidth)>=2,'Underline cursor missing');
|
||||
const vimKey=(key,code,keyCode,shiftKey=false)=>editor.contentDOM.dispatchEvent(new w.KeyboardEvent('keydown',{key,code,keyCode,shiftKey,bubbles:true,cancelable:true}));
|
||||
vimKey('v','KeyV',86);assert(d.body.dataset.editorMode==='visual','Vim visual state not tracked');
|
||||
vimKey('Escape','Escape',27);assert(d.body.dataset.editorMode==='normal','Vim normal state not tracked');
|
||||
vimKey('A','KeyA',65,true);assert(d.body.dataset.editorMode==='insert','Vim A insertion not tracked');
|
||||
vimKey('Escape','Escape',27);
|
||||
vimKey('R','KeyR',82,true);assert(d.body.dataset.editorMode==='replace','Vim replace state not tracked');
|
||||
vimKey('Escape','Escape',27);
|
||||
assert(d.cookie.includes('pageswiki_theme=light'),'Theme choice not retained');
|
||||
assert(w.PagesWikiCodeMirror===editor && editor.state.doc.toString()===before,'Theme switch replaced editor or lost content');
|
||||
await change('nanoha-dark');
|
||||
assert(w.getComputedStyle(editor.dom).backgroundColor!=='rgb(247, 247, 247)','Dark theme did not apply');
|
||||
await change('index-white');
|
||||
w.setEditorPreviewVisible(true);
|
||||
await e.renderPreview();
|
||||
const article=d.createElement('div'); article.style='width:300px';
|
||||
const pre=d.createElement('pre'), code=d.createElement('code'); code.textContent='x'.repeat(500); pre.append(code); article.append(pre); d.querySelector('#preview').append(article);
|
||||
const ancestry=[]; for(let el=pre;el;el=el.parentElement) ancestry.push(el.tagName+'#'+el.id+':'+w.getComputedStyle(el).display+':'+el.clientWidth);
|
||||
assert(pre.clientWidth>0 && pre.clientWidth<=300 && pre.scrollWidth>pre.clientWidth,'Code block dimensions: '+pre.clientWidth+'/'+pre.scrollWidth+' '+ancestry.join(' > '));
|
||||
assert(w.getComputedStyle(pre).borderInlineStartWidth==='3px','Code block styling missing');
|
||||
// PlainText follows the same save/draft machinery but never renders markup.
|
||||
const plainFrame=d.createElement('iframe'); d.body.append(plainFrame);
|
||||
await new Promise(resolve=>{plainFrame.onload=resolve;plainFrame.src='/e/-/plain-test.txt?edittype=plain';});
|
||||
const pw=plainFrame.contentWindow,pd=plainFrame.contentDocument;
|
||||
await wait(()=>pw.PagesWikiCodeMirror);
|
||||
const pe=pw.PagesEditor; pe.paused=true;
|
||||
const literal='<img src=x onerror="alert(1)">\n# Literal\n{{children}}';
|
||||
pe.setText(literal); await pe.renderPreview();
|
||||
assert(pd.querySelector('#preview').textContent===literal && !pd.querySelector('#preview img'),'PlainText preview interpreted markup');
|
||||
assert(await pe.saveNow(),'PlainText save failed');
|
||||
const state=await pe.state();assert(state.body===literal && state.content_type==='text/plain; charset=utf-8','PlainText canonical data changed');
|
||||
await pe.switchFormat('html');assert(pe.format()==='plain','PlainText silently switched to HTML');
|
||||
plainFrame.remove();
|
||||
document.body.dataset.vimReady='1';
|
||||
} catch(error) { const out=document.createElement('pre'); out.id='error';out.textContent=error.stack;document.body.append(out); }
|
||||
})();
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
(async () => {
|
||||
const assert = (ok, message) => { if (!ok) throw Error(message); };
|
||||
const frame = document.createElement('iframe');
|
||||
frame.style = 'width:100%;height:900px'; document.body.append(frame);
|
||||
const load = path => new Promise(resolve => { frame.onload = resolve; frame.src = path; });
|
||||
const navigate = action => new Promise(resolve => { frame.onload = resolve; action(); });
|
||||
const key = (target, key, options = {}) => target.dispatchEvent(new frame.contentWindow.KeyboardEvent('keydown', {key, bubbles:true, cancelable:true, ...options}));
|
||||
try {
|
||||
await load('/');
|
||||
let d = frame.contentDocument;
|
||||
const input = d.querySelector('[data-home-type-search]');
|
||||
assert(input, 'Home search input missing');
|
||||
key(d.body, 'x');
|
||||
assert(d.activeElement === input && input.value === 'x', 'First key lost');
|
||||
input.blur(); key(d.body, 'l', {ctrlKey:true});
|
||||
assert(input.value === 'x', 'Browser shortcut captured');
|
||||
const other = d.createElement('input'); d.body.append(other); other.focus(); key(other, 'z');
|
||||
assert(input.value === 'x' && d.activeElement === other, 'Other input captured'); other.remove();
|
||||
const dialog = d.createElement('dialog'); d.body.append(dialog); dialog.showModal(); key(d.body, 'z');
|
||||
assert(input.value === 'x', 'Modal typing captured'); dialog.close(); dialog.remove();
|
||||
input.blur(); key(d.body, 'Process', {keyCode:229});
|
||||
assert(d.activeElement === input && input.value === 'x', 'IME focus failed');
|
||||
if (d.querySelector('[data-home-pager]')) {
|
||||
input.blur(); d.querySelector('[data-home-page-target="bookmarks"]').click();
|
||||
d.activeElement.blur(); key(d.body, 'y');
|
||||
assert(d.querySelector('[data-home-pager]').dataset.homePage === 'search' && input.value === 'xy', 'Bookmark page did not return to search');
|
||||
}
|
||||
|
||||
await load('/v/browser/'); d = frame.contentDocument;
|
||||
assert(d.querySelector('[data-browser-address] input').value === '/', 'Root address missing');
|
||||
d.querySelector('[data-browser-create="cd"]').click();
|
||||
let create = d.querySelector('[data-browser-create-dialog]');
|
||||
assert(create.open, 'Folder dialog did not open');
|
||||
create.querySelector('[name=path]').value = '新規 #?';
|
||||
await navigate(() => create.querySelector('form').requestSubmit()); d = frame.contentDocument;
|
||||
assert(d.querySelector('[data-browser-address]').dataset.path === '/新規 #?', 'Virtual folder path corrupted');
|
||||
assert(d.querySelector('.browser-empty'), 'Virtual folder empty state missing');
|
||||
let address = d.querySelector('[data-browser-address]');
|
||||
address.querySelector('input').value = '//evil.example'; address.requestSubmit();
|
||||
assert(d.querySelector('#browser-address-error').textContent, 'Unsafe URL accepted');
|
||||
await navigate(() => d.querySelector('[data-browser-up]').click()); d = frame.contentDocument;
|
||||
assert(d.querySelector('[data-browser-address]').dataset.path === '/', 'Parent navigation failed');
|
||||
d.querySelector('[data-browser-create="vi"]').click();
|
||||
create = d.querySelector('[data-browser-create-dialog]'); create.querySelector('[name=path]').value = 'new-document';
|
||||
await navigate(() => create.querySelector('form').requestSubmit()); d = frame.contentDocument;
|
||||
assert(d.querySelector('#editor') && frame.contentWindow.location.pathname === '/e/-/new-document', 'New document editor did not open');
|
||||
await load('/v/browser/'); d = frame.contentDocument;
|
||||
d.querySelector('[data-browser-create="vi"]').click();
|
||||
create = d.querySelector('[data-browser-create-dialog]'); create.querySelector('[name=path]').value = 'notes.txt';
|
||||
create.querySelector('[name=format]').value = 'plain';
|
||||
await navigate(() => create.querySelector('form').requestSubmit()); d = frame.contentDocument;
|
||||
assert(d.querySelector('#edit-type').value==='plain' && d.querySelector('#page-content-type').value==='text/plain; charset=utf-8', 'PlainText creation lost format');
|
||||
document.body.dataset.vimReady = '1';
|
||||
} catch (error) {
|
||||
const output = document.createElement('pre'); output.id = 'error'; output.textContent = error.stack; document.body.append(output);
|
||||
}
|
||||
})();
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
(async () => {
|
||||
const assert = (ok, message) => { if (!ok) throw Error(message); };
|
||||
const frame = document.createElement('iframe');
|
||||
frame.style = 'display:block;width:100%;height:880px;border:0'; document.body.append(frame);
|
||||
const load = path => new Promise(resolve => { frame.onload = resolve; frame.src = path; });
|
||||
try {
|
||||
await load('/u/admin/_/edit');
|
||||
let d = frame.contentDocument;
|
||||
let form = d.querySelector('[name=contact_version]').form;
|
||||
assert(form.querySelector('[name=contact_visibility]').value === 'private', 'Default is not private');
|
||||
assert(!form.querySelector('[name=contact_confirm_public]').checked, 'Consent was preselected');
|
||||
const field = form.querySelector('[name=phone]');
|
||||
assert(field.type === 'tel', 'Phone keyboard hint missing');
|
||||
field.value = '+81 (90) 1234-5678';
|
||||
await new Promise(resolve => { frame.onload = resolve; form.requestSubmit(); });
|
||||
d = frame.contentDocument;
|
||||
assert(frame.contentWindow.location.search === '?contact=saved', 'Save did not redirect back');
|
||||
assert(d.querySelector('[name=phone]').value === '+81 (90) 1234-5678', 'Phone display was not retained');
|
||||
await load('/u/admin'); d = frame.contentDocument;
|
||||
assert(d.querySelector('.profile-phone a').getAttribute('href') === 'tel:+819012345678', 'tel link malformed');
|
||||
await load('/u/admin/_/edit#contact'); d = frame.contentDocument;
|
||||
form = d.querySelector('[name=contact_version]').form;
|
||||
for (const el of form.querySelectorAll('input:not([type=hidden]),select,button')) {
|
||||
const r = el.getBoundingClientRect();
|
||||
assert(r.left >= 0 && r.right <= frame.clientWidth + 1, 'Contact control overflows viewport');
|
||||
}
|
||||
d.querySelector('#contact').scrollIntoView();
|
||||
document.body.dataset.vimReady = '1';
|
||||
} catch (error) {
|
||||
const out = document.createElement('pre'); out.id = 'error'; out.textContent = error.stack; document.body.append(out);
|
||||
}
|
||||
})();
|
||||
+7
-3
@@ -30,7 +30,11 @@ window.addEventListener('load', async () => {
|
||||
assert(!city.querySelector('.children-entry,[data-child-path]'), 'City result is exposed to file operations');
|
||||
assert(city.querySelector('[data-city-search-kind] .search-result-name mark'), 'City name highlight missing');
|
||||
assert(city.querySelector('.search-result-path')?.getAttribute('href')?.startsWith('/'), 'City boundary Path link missing');
|
||||
assert(city.querySelector('.search-result-name')?.getAttribute('href')?.startsWith('/v/city/'), 'City details link missing');
|
||||
for (const hit of city.querySelectorAll('[data-city-search-kind]')) {
|
||||
const href = hit.querySelector('.search-result-name')?.getAttribute('href');
|
||||
assert(href?.startsWith('/') && !href.startsWith('/v/city/'), 'Search links to City settings');
|
||||
assert(href === hit.querySelector('.search-result-path')?.getAttribute('href'), 'City title and Path destinations differ');
|
||||
}
|
||||
assert(!city.querySelector('script,[onload],[onerror]'), 'City source HTML became executable markup');
|
||||
}
|
||||
for (const mode of ['list', 'detail', 'icon']) {
|
||||
@@ -41,7 +45,7 @@ window.addEventListener('load', async () => {
|
||||
assert(getComputedStyle(panel).display !== 'none', 'Selected mode is hidden: ' + mode);
|
||||
assert(panel.querySelector('.search-result-name')?.textContent.includes('nebula'), 'Page name missing');
|
||||
assert(panel.querySelector('.search-result-path')?.textContent.includes('/docs/nebula guide?#%'), 'Full Path missing');
|
||||
assert(panel.querySelector('.search-result-excerpt mark')?.textContent === 'NEBULA', 'Context highlight missing');
|
||||
assert([...panel.querySelectorAll('.search-result-excerpt mark')].some(mark => mark.textContent.toLowerCase() === 'nebula'), 'Context highlight missing');
|
||||
assert(panel.querySelector('[data-match-source="body"]'), 'Match source missing');
|
||||
assert(panel.querySelector('.search-result-name').closest('a').getAttribute('href').includes('%3F%23%25'), 'Path URL was not encoded');
|
||||
if (city) assert(getComputedStyle(city).display !== 'none', 'View switching hid City results: ' + mode);
|
||||
@@ -58,7 +62,7 @@ window.addEventListener('load', async () => {
|
||||
assert(!cityRow.classList.contains('children-selected'), 'City result became a selectable file');
|
||||
}
|
||||
options.open = true;
|
||||
assert(document.documentElement.scrollWidth <= innerWidth, 'Search introduces horizontal page scrolling');
|
||||
assert(document.documentElement.scrollWidth <= innerWidth, 'Search introduces horizontal page scrolling: ' + [...document.querySelectorAll('body *')].filter(el => el.getBoundingClientRect().right > innerWidth + 1).slice(0,8).map(el => el.tagName + '.' + el.className + ':' + Math.round(el.getBoundingClientRect().right)).join(', '));
|
||||
document.body.dataset.vimReady = '1';
|
||||
console.log('Vim initialized');
|
||||
} catch (error) {
|
||||
|
||||
Reference in new issue
Block a user