feat(tasks): add keyboard index and productivity dashboard improvements
This commit is contained in:
1 parent
02edb51b8a
commit
667776e43f
44 files changed
+1224
-138
No files matched your search
+23
-1
@@ -8,7 +8,8 @@ window.addEventListener('load',async()=>{const wait=async(fn)=>{for(let i=0;i<12
|
||||
const prefs=await fetch(api+'preferences').then(r=>r.json());const saved=await fetch(api+'preferences',{method:'PUT',headers:{'Content-Type':'application/json'},body:JSON.stringify({...prefs.preferences,notify_due:true,notify_planned:true,reminder_time:'10:35'})});if(!saved.ok)throw Error('Preferences save failed');
|
||||
document.querySelector('#tasks-new').click();await wait(()=>input('page_path'));
|
||||
if(input('notify_due').checked||input('notify_planned').checked)throw Error('Undated task enabled reminders');
|
||||
fill(input('title'),'タスク編集のレイアウト確認');fill(input('notes'),'主要項目を左右に整理。日付と通知をまとめて設定します。');
|
||||
fill(input('title'),'**タスク編集のレイアウト確認**');fill(input('notes'),'主要項目を左右に整理。日付と通知をまとめて設定します。');
|
||||
fill(input('references'),'https://example.test/doc\n/files/資料.pdf');
|
||||
fill(input('planned_on'),'2030-01-01');fill(input('due_on'),'2030-01-02');
|
||||
if(!input('notify_due').checked||!input('notify_planned').checked||input('reminder_time').value!=='10:35')throw Error('Dated defaults missing');
|
||||
input('notify_due').click();fill(input('due_on'),'2030-01-03');if(input('notify_due').checked)throw Error('Explicit reminder choice overwritten');
|
||||
@@ -18,6 +19,9 @@ window.addEventListener('load',async()=>{const wait=async(fn)=>{for(let i=0;i<12
|
||||
if(task.status!=='doing'||task.bucket!=='backlog'||task.complexity!==4||!task.notify_planned||task.notify_due||task.reminder_time!=='10:35')throw Error('Editor fields not persisted');
|
||||
await wait(()=>document.querySelector('[data-task-id="'+task.uuid+'"] [data-action=detail]'));document.querySelector('[data-task-id="'+task.uuid+'"] [data-action=detail]').click();await wait(()=>input('page_path'));
|
||||
if(input('notify_due').checked)throw Error('Defaults changed existing task');
|
||||
if(task.references?.length!==2||input('references').value!=='https://example.test/doc\n/files/資料.pdf')throw Error('Task references lost');
|
||||
const preview=document.querySelector('.task-title-preview');if(!preview?.querySelector('strong')||getComputedStyle(preview).display==='none'||preview.getBoundingClientRect().height<10)throw Error('Markdown title preview missing');
|
||||
const safe=document.createElement('div');PagesTaskPresentation.render(safe,'<img src=x onerror=alert(1)> [bad](javascript:alert) **safe**');if(safe.querySelector('img,a')||!safe.querySelector('strong'))throw Error('Unsafe task Markdown');
|
||||
if(form.querySelector('.task-editor-advanced').open)throw Error('Advanced section should start collapsed');
|
||||
const fields=document.querySelector('#tasks-fields'),rect=dialog.getBoundingClientRect();
|
||||
if(rect.width>innerWidth+1||rect.height>innerHeight+1||fields.scrollWidth>fields.clientWidth+1)throw Error('Editor overflow');
|
||||
@@ -46,6 +50,24 @@ window.addEventListener('load',async()=>{const wait=async(fn)=>{for(let i=0;i<12
|
||||
document.querySelector('#dashboard-controls button[aria-pressed]').click();const width=document.querySelector('[data-widget=tasks] [data-size=width]');width.value='6';width.dispatchEvent(new Event('change'));const height=document.querySelector('[data-widget=tasks] [data-size=height]');height.value='5';height.dispatchEvent(new Event('change'));
|
||||
document.querySelector('[data-widget=tasks] .widget-arrange button').click();document.querySelector('#dashboard-controls button:last-child').click();await wait(()=>document.querySelector('#dashboard-status').textContent.includes('保存しました'));const layout=await fetch('/_/api/v1/extension/organizer.tasks/dashboard').then(r=>r.json());if(layout.widgets[2].id!=='tasks'||layout.widgets[2].width!==6||layout.widgets[2].height!==5||layout.widgets[2].tab!=='done')throw Error('Layout did not persist');
|
||||
if(!document.querySelector('.organizer-nav a[href="/v/plan/contacts"]')||!document.querySelector('.organizer-nav a[aria-current="page"]'))throw Error('Shared navigation missing');
|
||||
const add=document.querySelector('#dashboard-controls select');
|
||||
for(const id of ['commands','tomorrow-schedule']){add.value=id;add.dispatchEvent(new Event('change'));}
|
||||
await wait(()=>document.querySelector('.dashboard-command'));
|
||||
const command=document.querySelector('.dashboard-command'),commandInput=command.querySelector('input'),api='/_/api/v1/extension/organizer.tasks/';
|
||||
const run=async text=>{fill(commandInput,text);command.requestSubmit();await wait(()=>!command.querySelector('button').disabled);if(commandInput.value)throw Error('Command failed: '+command.parentElement.textContent);};
|
||||
await run('add task **Command fixture**');
|
||||
let items=await fetch(api+'items?q=Command%20fixture').then(r=>r.json());const id=items.items[0].uuid;
|
||||
fill(commandInput,'today Command');await wait(()=>document.querySelector('#dashboard-command-tasks option'));if(!document.querySelector('#dashboard-command-tasks option').value.includes(id))throw Error('Command task suggestions missing');
|
||||
await run('today '+id);let item=await fetch(api+'items/'+id).then(r=>r.json());if(item.item.planned_on!==document.querySelector('#organizer-dashboard').dataset.today)throw Error('Today command failed');
|
||||
await run('tomorrow '+id);await run('due '+id+' 2030-12-31');item=await fetch(api+'items/'+id).then(r=>r.json());if(item.item.due_on!=='2030-12-31')throw Error('Due command failed');
|
||||
await wait(()=>document.querySelector('[data-widget=tomorrow] strong'));
|
||||
window.confirm=()=>false;fill(commandInput,'delete '+id);command.requestSubmit();await wait(()=>!command.querySelector('button').disabled);if(!(await fetch(api+'items/'+id)).ok)throw Error('Unconfirmed deletion');
|
||||
window.confirm=()=>true;await run('delete '+id);if((await fetch(api+'items/'+id)).status!==404)throw Error('Deletion failed');
|
||||
const date=new Date(document.querySelector('#organizer-dashboard').dataset.today+'T12:00:00Z');date.setUTCDate(date.getUTCDate()+1);const day=date.toISOString().slice(0,10),calAPI='/_/api/v1/extension/organizer.calendar/';
|
||||
const calendars=await fetch(calAPI+'calendars').then(r=>r.json());const calendar=(calendars.calendars||calendars.items)[0];
|
||||
const response=await fetch(calAPI+'calendars/'+calendar.id+'/events',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({summary:'Tomorrow visual fixture',start:day+'T03:00:00Z',end:day+'T04:00:00Z'})});if(!response.ok)throw Error('Event fixture failed');
|
||||
document.querySelector('#dashboard-controls button').click();await wait(()=>document.querySelector('[data-widget=tomorrow-schedule] .agenda-event'));
|
||||
if(!document.querySelector('[data-widget=tomorrow-schedule]').textContent.includes('Tomorrow visual fixture'))throw Error('Tomorrow schedule missing');
|
||||
}else if(path==='/v/plan/tasks'){
|
||||
const prefs=await fetch('/_/api/v1/extension/organizer.tasks/preferences').then(r=>r.json());await fetch('/_/api/v1/extension/organizer.tasks/preferences',{method:'PUT',headers:{'Content-Type':'application/json'},body:JSON.stringify({...prefs.preferences,due_days:2,estimate_minutes:60})});
|
||||
await wait(()=>document.querySelector('#tasks-quick-title'));fill(document.querySelector('#tasks-quick-title'),'Recording task');document.querySelector('#tasks-capture').requestSubmit();await wait(()=>document.querySelector('[data-action=work]'));document.querySelector('[data-action=work]').click();await wait(()=>document.querySelector('.task-work-bar a').textContent.includes('Recording task'));document.querySelector('.task-work-bar button').click();await wait(()=>document.querySelector('.task-work-bar').hidden);
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
window.addEventListener('load',async()=>{
|
||||
const wait=async fn=>{for(let n=0;n<120;n++){if(fn())return;await new Promise(r=>setTimeout(r,50));}throw Error('Timed out: '+fn);};
|
||||
const assert=(ok,msg)=>{if(!ok)throw Error(msg);},key=(k,ctrl=false)=>document.activeElement.dispatchEvent(new KeyboardEvent('keydown',{key:k,ctrlKey:ctrl,bubbles:true,cancelable:true}));
|
||||
const rows=()=>[...document.querySelectorAll('.task-index-grid tbody tr')],selected=()=>document.querySelector('.task-index-grid tr[aria-selected=true]'),api='/_/api/v1/extension/organizer.tasks/';
|
||||
try{
|
||||
const grid=document.querySelector('.task-index-grid'),form=document.querySelector('.task-index-filter'),filter=form.querySelector('input'),sort=form.querySelector('select');
|
||||
const ready=()=>grid.getAttribute('aria-busy')!=='true';
|
||||
await wait(()=>ready()&&rows().length===3&&document.querySelectorAll('.task-index-projects button').length===4);
|
||||
grid.focus();key('o');assert(document.activeElement===sort,'o did not focus sort');sort.value='title';sort.dispatchEvent(new Event('change'));await wait(ready);key('Escape');
|
||||
rows()[0].click();const first=selected().dataset.task;key('j');assert(selected().dataset.task!==first,'j failed');key('k');assert(selected().dataset.task===first,'k failed');assert(rows()[0].querySelector('strong'),'Markdown subject lost');
|
||||
key('l');assert(document.activeElement===filter,'l did not focus limit');filter.value='~s Beta ~doing';form.requestSubmit();await wait(()=>ready()&&rows().length===1);const beta=selected().dataset.task;
|
||||
filter.focus();key('d');let item=await fetch(api+'items/'+beta).then(r=>r.json());assert(item.item.status==='doing','Shortcut fired while typing');
|
||||
const changed=await fetch(api+'items/'+beta,{method:'PUT',headers:{'Content-Type':'application/json','If-Match':'"'+item.item.version+'"'},body:JSON.stringify({...item.item,notes:'Changed in another client'})});assert(changed.ok,'Concurrent update fixture failed');
|
||||
key('Escape');key('d');await wait(()=>document.querySelector('#tasks-status').textContent.includes('別の画面で更新'));
|
||||
item=await fetch(api+'items/'+beta).then(r=>r.json());assert(item.item.status==='doing'&&item.item.notes==='Changed in another client','Stale completion overwrote another client');
|
||||
form.requestSubmit();await wait(ready);key('d');await wait(()=>ready()&&rows().length===0);item=await fetch(api+'items/'+beta).then(r=>r.json());assert(item.item.status==='done'&&item.item.notes==='Changed in another client','d did not preserve full task data');
|
||||
filter.value='~unknown';form.requestSubmit();await wait(()=>ready()&&document.querySelector('#tasks-status').textContent.includes('不正'));assert(form.querySelector('input').value==='~unknown','Invalid filter lost');
|
||||
filter.value='~active';form.requestSubmit();await wait(()=>ready()&&rows().length===2);grid.focus();key('j',true);await wait(()=>ready()&&rows().length===1);assert(document.querySelector('.task-index-projects [aria-current=true]').dataset.project==='none','Ctrl+j did not switch project');
|
||||
key('k',true);await wait(()=>ready()&&rows().length===2);key('O');await wait(ready);assert(rows()[0].textContent.includes('Gamma'),'Reverse sort failed');
|
||||
grid.focus();key('?');const help=document.querySelector('.task-index-help');assert(help.open,'Help missing');const previous=selected().dataset.task;key('j');assert(selected().dataset.task===previous,'Shortcut fired through modal');help.querySelector('button').click();
|
||||
key('m');await wait(()=>document.querySelector('#tasks-dialog').open&&document.querySelector('#tasks-form [name=page_path]'));key('j');assert(selected().dataset.task===previous,'Shortcut fired through editor');document.querySelector('#tasks-close').click();
|
||||
const projectButton=[...document.querySelectorAll('.task-index-projects button')].find(b=>b.dataset.project&&b.dataset.project!=='none');projectButton.click();await wait(ready);const project=projectButton.dataset.project;grid.focus();key('c');
|
||||
await wait(()=>document.querySelector('#tasks-dialog').open&&document.querySelector('#tasks-form [name=project_uuid]')?.value===project);const title=document.querySelector('#tasks-form [name=title]');title.value='Created from index';title.dispatchEvent(new Event('input',{bubbles:true}));document.querySelector('#tasks-form').requestSubmit();await wait(()=>!document.querySelector('#tasks-dialog').open&&ready()&&rows().some(row=>row.textContent.includes('Created from index')));
|
||||
rows().find(row=>row.textContent.includes('Created from index')).click();const created=selected().dataset.task;key('w');await wait(()=>document.querySelector('#tasks-status').textContent.includes('関連Wikiページはありません'));
|
||||
key('s');await wait(()=>document.querySelector('#tasks-focus').dataset.state==='running');const session=await fetch(api+'focus').then(r=>r.json());assert(session.item.task_uuid===created,'Pomodoro attached to wrong task');
|
||||
assert(document.documentElement.scrollWidth<=innerWidth+2,'Page overflow');assert(!document.querySelector('#tasks-list input'),'Index must not be an inline form');
|
||||
document.body.dataset.vimReady='true';
|
||||
}catch(e){const p=document.createElement('pre');p.id='error';p.textContent=e.stack;document.body.append(p);}
|
||||
});
|
||||
@@ -44,6 +44,15 @@ try {
|
||||
if (state.ready) { ready = true; break; }
|
||||
await delay(200);
|
||||
}
|
||||
if(ready && process.env.PAGESWIKI_TASK_INDEX_BROWSER==='1'){
|
||||
const evaluate=async expression=>{const r=await call('Runtime.evaluate',{expression,returnByValue:true,awaitPromise:true});if(r.exceptionDetails)throw Error(JSON.stringify(r.exceptionDetails));return r.result.value;};
|
||||
const key=async(key,modifiers=0)=>{await call('Input.dispatchKeyEvent',{type:'keyDown',key,code:'Key'+key.toUpperCase(),modifiers});await call('Input.dispatchKeyEvent',{type:'keyUp',key,code:'Key'+key.toUpperCase(),modifiers});};
|
||||
await evaluate(`document.querySelector('.task-index-projects button').click();new Promise((resolve,reject)=>{let n=0;const id=setInterval(()=>{if(document.querySelector('.task-index-grid').getAttribute('aria-busy')!=='true'){clearInterval(id);document.querySelector('.task-index-grid tbody tr').click();resolve();}else if(++n>100){clearInterval(id);reject(Error('index loading'));}},30);})`);
|
||||
const selected=()=>evaluate(`document.querySelector('.task-index-grid tr[aria-selected=true]').dataset.task`);
|
||||
const before=await selected();await key('j');if(await selected()===before)throw Error('Native j did not move');await key('k');if(await selected()!==before)throw Error('Native k did not move');
|
||||
await key('j',2);if(await evaluate(`document.querySelector('.task-index-projects [aria-current=true]').dataset.project`)!=='none')throw Error('Native Ctrl+j did not switch project');await key('k',2);
|
||||
await evaluate(`new Promise(resolve=>{const id=setInterval(()=>{if(document.querySelector('.task-index-grid').getAttribute('aria-busy')!=='true'){clearInterval(id);resolve();}},30)})`);
|
||||
}
|
||||
if(ready && process.env.PAGESWIKI_DASHBOARD_DRAG==='1'){
|
||||
const evaluate=async expression=>{const r=await call('Runtime.evaluate',{expression,returnByValue:true,awaitPromise:true});if(r.exceptionDetails)throw Error(JSON.stringify(r.exceptionDetails));return r.result.value;};
|
||||
const rect=async selector=>evaluate(`(()=>{const n=document.querySelector(${JSON.stringify(selector)});n.scrollIntoView({block:'center',behavior:'instant'});const r=n.getBoundingClientRect();return {x:r.x+r.width/2,y:r.y+r.height/2};})()`);
|
||||
|
||||
Reference in new issue
Block a user