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
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user