Refine task editor layout and personal reminder defaults
This commit is contained in:
1 parent
8fd0b6ec8b
commit
a6bf3dfe41
14 files changed
+263
-26
No files matched your search
@@ -15,10 +15,19 @@ func TestProductivityChromium(t *testing.T) {
|
||||
if os.Getenv("PAGESWIKI_BROWSER_TEST") != "1" {
|
||||
t.Skip("opt-in Chromium")
|
||||
}
|
||||
for _, view := range []string{"contacts", "settings", "report", "tasks", "home"} {
|
||||
for _, size := range []string{"desktop", "mobile"} {
|
||||
for _, view := range []string{"contacts", "settings", "report", "tasks", "home", "editor"} {
|
||||
sizes := []string{"desktop", "mobile"}
|
||||
if view == "editor" {
|
||||
sizes = append(sizes, "laptop", "mobile-small", "english")
|
||||
}
|
||||
for _, size := range sizes {
|
||||
t.Run(view+"-"+size, func(t *testing.T) {
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
if size == "english" {
|
||||
if err := s.store.SetConfigInDomain(domain, "locale", "en"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
s.mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { s.renderSearchHome(w, r, "search") })
|
||||
item := newTaskRecord("task", "Browser work task")
|
||||
item.Status = "done"
|
||||
@@ -38,7 +47,7 @@ func TestProductivityChromium(t *testing.T) {
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
path := map[string]string{"contacts": "/v/plan/contacts", "settings": "/-/sys/config?panel=organizer", "report": "/v/plan/dashboard", "tasks": "/v/plan/tasks", "home": "/"}[view]
|
||||
path := map[string]string{"contacts": "/v/plan/contacts", "settings": "/-/sys/config?panel=organizer", "report": "/v/plan/dashboard", "tasks": "/v/plan/tasks", "home": "/", "editor": "/v/plan/task/-/new"}[view]
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
if r.Method == "GET" && r.URL.RequestURI() == path {
|
||||
@@ -64,6 +73,12 @@ func TestProductivityChromium(t *testing.T) {
|
||||
if size == "mobile" {
|
||||
width, height = "390", "844"
|
||||
}
|
||||
if size == "laptop" {
|
||||
width, height = "1024", "768"
|
||||
}
|
||||
if size == "mobile-small" {
|
||||
width, height = "320", "568"
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
|
||||
defer cancel()
|
||||
shot := ""
|
||||
|
||||
@@ -34,9 +34,21 @@ func defaultTask(p store.TaskPreferences, now time.Time) store.TaskRecord {
|
||||
*date.target = now.AddDate(0, 0, *date.offset).Format("2006-01-02")
|
||||
}
|
||||
}
|
||||
applyTaskReminderDefaults(&item, p)
|
||||
return item
|
||||
}
|
||||
|
||||
// Undated captures must remain possible, even when reminder defaults are on.
|
||||
// Apply after date overrides, and never apply to updates of existing tasks.
|
||||
func applyTaskReminderDefaults(item *store.TaskRecord, p store.TaskPreferences) {
|
||||
item.NotifyDue = p.NotifyDue && item.DueOn != ""
|
||||
item.NotifyPlanned = p.NotifyPlanned && item.PlannedOn != ""
|
||||
item.ReminderTime = p.ReminderTime
|
||||
if item.ReminderTime == "" {
|
||||
item.ReminderTime = "09:00"
|
||||
}
|
||||
}
|
||||
|
||||
type taskCaptureInput struct {
|
||||
RequestID string `json:"request_id"`
|
||||
Title string `json:"title"`
|
||||
@@ -198,6 +210,7 @@ func (s *Server) handleTaskProductivity(w http.ResponseWriter, r *http.Request,
|
||||
if input.Complexity != nil {
|
||||
item.Complexity = *input.Complexity
|
||||
}
|
||||
applyTaskReminderDefaults(&item, p)
|
||||
raw, _ := json.Marshal(input)
|
||||
hash := sha256.Sum256(raw)
|
||||
item, err = s.store.CaptureTask(r.Context(), domain, actor, input.RequestID, hex.EncodeToString(hash[:]), item)
|
||||
|
||||
@@ -32,6 +32,88 @@ func TestTaskDigestSMTPContent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskReminderPreferencesAndCapture(t *testing.T) {
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
ctx := context.Background()
|
||||
existing, err := s.store.SaveTask(ctx, domain, actor, newTaskRecord("task", "Existing without reminders"), 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w := taskRequest(s, token, "GET", "preferences", nil, "")
|
||||
var result struct {
|
||||
Preferences store.TaskPreferences `json:"preferences"`
|
||||
Defaults store.TaskRecord `json:"defaults"`
|
||||
}
|
||||
if err = json.Unmarshal(w.Body.Bytes(), &result); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.Preferences.NotifyDue || result.Preferences.NotifyPlanned || result.Preferences.ReminderTime != "09:00" {
|
||||
t.Fatal("unexpected initial reminder preferences", result.Preferences)
|
||||
}
|
||||
p := result.Preferences
|
||||
p.NotifyDue, p.NotifyPlanned, p.ReminderTime = true, true, "10:35"
|
||||
w = taskRequest(s, token, "PUT", "preferences", p, "")
|
||||
if w.Code != 200 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
if err = json.Unmarshal(w.Body.Bytes(), &result); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p = result.Preferences
|
||||
for _, clock := range []string{"9:00", "24:00", "10:35:00", "garbage"} {
|
||||
bad := p
|
||||
bad.ReminderTime = clock
|
||||
if w = taskRequest(s, token, "PUT", "preferences", bad, ""); w.Code != 422 {
|
||||
t.Fatal("invalid clock accepted", clock, w.Code)
|
||||
}
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
dates map[string]any
|
||||
due, planned bool
|
||||
}{
|
||||
{"undated", map[string]any{}, false, false},
|
||||
{"dated", map[string]any{"due_on": "2030-01-02", "planned_on": "2030-01-01"}, true, true},
|
||||
{"cleared", map[string]any{"due_on": "", "planned_on": ""}, false, false},
|
||||
} {
|
||||
input := tc.dates
|
||||
input["request_id"] = uuid.NewString()
|
||||
input["title"] = tc.name
|
||||
w = taskRequest(s, token, "POST", "capture", input, "")
|
||||
if w.Code != 201 {
|
||||
t.Fatal(tc.name, w.Code, w.Body)
|
||||
}
|
||||
var response struct {
|
||||
Item store.TaskRecord `json:"item"`
|
||||
}
|
||||
if err = json.Unmarshal(w.Body.Bytes(), &response); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if response.Item.NotifyDue != tc.due || response.Item.NotifyPlanned != tc.planned || response.Item.ReminderTime != "10:35" {
|
||||
t.Fatal("wrong reminder defaults", response.Item)
|
||||
}
|
||||
if tc.due && response.Item.ReminderTimezone == "" {
|
||||
t.Fatal("missing server timezone")
|
||||
}
|
||||
}
|
||||
zero := 0
|
||||
p.PlannedDays = &zero
|
||||
if w = taskRequest(s, token, "PUT", "preferences", p, ""); w.Code != 200 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
w = taskRequest(s, token, "GET", "preferences", nil, "")
|
||||
if err = json.Unmarshal(w.Body.Bytes(), &result); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !result.Defaults.NotifyPlanned || result.Defaults.NotifyDue || result.Defaults.PlannedOn == "" {
|
||||
t.Fatal("dated defaults missing", result.Defaults)
|
||||
}
|
||||
loaded, err := s.store.GetTask(ctx, domain, actor, existing.UUID)
|
||||
if err != nil || loaded.Version != existing.Version || loaded.NotifyDue || loaded.NotifyPlanned {
|
||||
t.Fatal("existing task changed", loaded, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskCaptureDefaultsReplayAndPermissions(t *testing.T) {
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
ctx := context.Background()
|
||||
|
||||
+25
-2
@@ -1,6 +1,29 @@
|
||||
window.addEventListener('load',async()=>{const wait=async(fn)=>{for(let i=0;i<120;i++){if(fn())return;await new Promise(r=>setTimeout(r,100));}throw Error('Timed out: '+fn.toString());};const fill=(n,value)=>{n.value=value;n.dispatchEvent(new Event('input',{bubbles:true}));};try{
|
||||
const path=location.pathname;
|
||||
if(path==='/v/plan/contacts'){
|
||||
if(path==='/v/plan/task/-/new'){
|
||||
const api='/_/api/v1/extension/organizer.tasks/',dialog=document.querySelector('#tasks-dialog'),form=document.querySelector('#tasks-form');
|
||||
const input=name=>form.querySelector('[name="'+name+'"]');
|
||||
await wait(()=>input('page_path'));if(input('notify_due').checked||input('notify_planned').checked)throw Error('Initial defaults not off');
|
||||
document.querySelector('#tasks-close').click();
|
||||
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('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');
|
||||
for(const [key,value] of [['status','doing'],['bucket','backlog'],['complexity','4']]){const radio=form.querySelector('[name="'+key+'"][value="'+value+'"]');if(radio.type!=='radio')throw Error('Not a native radio group');radio.click();if(form.querySelectorAll('[name="'+key+'"]:checked').length!==1)throw Error('Multiple radio choices');}
|
||||
fill(input('estimate_minutes'),'90');form.requestSubmit();await wait(()=>!dialog.open);
|
||||
const items=await fetch(api+'items?q='+encodeURIComponent('レイアウト確認')).then(r=>r.json());const task=items.items[0];
|
||||
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(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');
|
||||
if(innerWidth>=1000){const left=form.querySelector('.task-editor-main').getBoundingClientRect(),right=form.querySelector('.task-editor-plan').getBoundingClientRect();if(right.left<=left.right||Math.abs(right.top-left.top)>2)throw Error('Editor is not two columns');if(fields.scrollHeight>fields.clientHeight+2)throw Error('Desktop editor needs scrolling: '+fields.scrollHeight+'/'+fields.clientHeight);}
|
||||
if(innerWidth<760&&form.querySelector('.task-editor-plan').getBoundingClientRect().top<form.querySelector('.task-editor-main').getBoundingClientRect().bottom)throw Error('Mobile columns overlap');
|
||||
}else if(path==='/v/plan/contacts'){
|
||||
await wait(()=>document.querySelector('#contacts-controls button'));document.querySelector('#contacts-controls button').click();fill(document.querySelector('[name=name]'),'ブラウザ連絡先');fill(document.querySelector('[name=emails]'),'browser@example.invalid');fill(document.querySelector('[name=notes]'),'Non-public notes');document.querySelector('#contact-editor form').requestSubmit();await wait(()=>document.querySelector('#contacts-list button')?.textContent.includes('ブラウザ'));const r=await fetch('/_/api/v1/extension/organizer.contacts/items?q=browser').then(r=>r.json());if(r.items.length!==1)throw Error('Contact save missing');
|
||||
fill(document.querySelector('[name=name]'),'変更後');document.querySelector('#contact-editor form').requestSubmit();await wait(()=>document.querySelector('#contacts-list button')?.textContent.includes('変更後'));
|
||||
await wait(()=>document.querySelector('.contact-history'));document.querySelector('.contact-history').open=true;await wait(()=>document.querySelectorAll('.contact-history-row').length===2);document.querySelectorAll('.contact-history-row')[1].querySelector('button').click();await wait(()=>document.querySelector('.contact-history pre').textContent.includes('ブラウザ連絡先'));
|
||||
@@ -8,7 +31,7 @@ window.addEventListener('load',async()=>{const wait=async(fn)=>{for(let i=0;i<12
|
||||
const exported=await fetch('/_/api/v1/extension/organizer.contacts/export.vcf').then(r=>r.text());if(!exported.includes('ブラウザ連絡先'))throw Error('Export missing');
|
||||
document.querySelector('#tasks-dav-open').click();await wait(()=>document.querySelector('#tasks-dav-dialog').open);const dav=document.querySelector('#tasks-dav-dialog');if(getComputedStyle(dav.querySelector('.dav-compat-toggle')).display!=='none')throw Error('CalDAV-only compatibility visible');fill(dav.querySelector('form>input'),'Browser contact client');dav.querySelector('form').requestSubmit();await wait(()=>!dav.querySelector('section').hidden);const credentials=await fetch('/_/api/v1/caldav-credentials').then(r=>r.json());if(credentials.items.length!==1||credentials.items[0].scope!=='contacts')throw Error('Wrong credential scope');dav.querySelector('tbody button').click();await wait(()=>!dav.querySelector('tbody button'));dav.querySelector('header button').click();
|
||||
}else if(path==='/-/sys/config'){
|
||||
await wait(()=>document.querySelector('[name=due_days]'));fill(document.querySelector('[name=due_days]'),'2');document.querySelector('.productivity-settings').requestSubmit();await wait(()=>document.querySelector('#productivity-status').textContent.includes('保存'));const d=await fetch('/_/api/v1/extension/organizer.tasks/preferences').then(r=>r.json());if(d.preferences.due_days!==2)throw Error('Preferences missing');
|
||||
await wait(()=>document.querySelector('[name=due_days]'));fill(document.querySelector('[name=due_days]'),'2');document.querySelector('[name=notify_due]').click();document.querySelector('[name=notify_planned]').click();fill(document.querySelector('[name=reminder_time]'),'08:45');document.querySelector('.productivity-settings').requestSubmit();await wait(()=>document.querySelector('#productivity-status').textContent.includes('保存'));const d=await fetch('/_/api/v1/extension/organizer.tasks/preferences').then(r=>r.json());if(d.preferences.due_days!==2||!d.preferences.notify_due||!d.preferences.notify_planned||d.preferences.reminder_time!=='08:45'||!d.defaults.notify_due||d.defaults.notify_planned)throw Error('Preferences missing');
|
||||
}else if(path==='/v/plan/dashboard'){
|
||||
await wait(()=>document.querySelectorAll('.productivity-day').length>300);if(!document.querySelector('.productivity-day[data-level="2"]'))throw Error('Seven-point completion missing');
|
||||
if(document.querySelectorAll('[data-widget]').length!==6)throw Error('Widget registry missing');
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
window.addEventListener('load', async () => {
|
||||
const $=id=>document.getElementById('tasks-'+id);
|
||||
const wait=async fn=>{for(let i=0;i<100;i++){if(fn())return;await new Promise(r=>setTimeout(r,50));}throw Error('Timed out: '+fn);};
|
||||
const value=(name,text)=>{const n=document.querySelector('#tasks-form [name="'+name+'"]');if(!n)throw Error('Missing field '+name);n.value=text;n.dispatchEvent(new Event('input',{bubbles:true}));};
|
||||
const value=(name,text)=>{let n=document.querySelector('#tasks-form [name="'+name+'"]');if(!n)throw Error('Missing field '+name);if(n.type==='radio'){n=document.querySelector('#tasks-form [name="'+name+'"][value="'+text+'"]');n.click();}else{n.value=text;n.dispatchEvent(new Event('input',{bubbles:true}));}};
|
||||
try {
|
||||
if (!sessionStorage.getItem('focus-reload')) {
|
||||
$('dav-open').click(); await wait(()=>$('dav-dialog').open&&$('dav-dialog').querySelector('thead'));
|
||||
|
||||
Reference in new issue
Block a user