AtlatestRepositoryfolio
1
(import (sigil test)2
(sigil struct)3
(sigil string)4
(sigil fs)5
(sigil path)6
(folio store)7
(folio task)8
(folio inbox)9
(folio project)10
(folio tools))12
;; ============================================================13
;; task-update text editing14
;; ============================================================16
(test-group "task-update text"17
(test "update task text in inbox"18
(call-with-temp-directory19
(lambda (dir)20
(let ((store (make-folio-store dir)))21
(let* ((task (inbox-add! store "Original text" '()))22
(task-id (folio-task-id task)))23
;; Update the task text24
(update-task-in-store! store task-id25
(dict text: "Updated text"))26
;; Read back and verify27
(let* ((tasks (read-inbox store))28
(updated (find (lambda (t)29
(equal? (folio-task-id t) task-id))30
tasks)))31
(assert-equal "Updated text" (folio-task-text updated))))))))33
(test "update task text in project"34
(call-with-temp-directory35
(lambda (dir)36
(let* ((store (make-folio-store dir))37
(file (project-create! store "Test" "Goal" #f)))38
(let* ((task (project-add-task! file "Project task" '((priority . "high"))))39
(task-id (folio-task-id task)))40
;; Update the task text41
(update-task-in-store! store task-id42
(dict text: "New project task text"))43
;; Read back and verify44
(let* ((proj (read-project file))45
(tasks (folio-project-tasks proj))46
(updated (find (lambda (t)47
(equal? (folio-task-id t) task-id))48
tasks)))49
(assert-equal "New project task text" (folio-task-text updated))50
;; Metadata should be preserved51
(assert-equal "high" (task-priority updated))))))))53
(test "update task text and metadata together"54
(call-with-temp-directory55
(lambda (dir)56
(let ((store (make-folio-store dir)))57
(let* ((task (inbox-add! store "Old text" '((priority . "low"))))58
(task-id (folio-task-id task)))59
;; Update both text and priority60
(update-task-in-store! store task-id61
(dict text: "New text" priority: "high"))62
;; Read back and verify63
(let* ((tasks (read-inbox store))64
(updated (find (lambda (t)65
(equal? (folio-task-id t) task-id))66
tasks)))67
(assert-equal "New text" (folio-task-text updated))68
(assert-equal "high" (task-priority updated))))))))70
(test "update metadata only preserves text"71
(call-with-temp-directory72
(lambda (dir)73
(let ((store (make-folio-store dir)))74
(let* ((task (inbox-add! store "Keep this text" '()))75
(task-id (folio-task-id task)))76
;; Update only priority, no text77
(update-task-in-store! store task-id78
(dict priority: "medium"))79
;; Read back and verify text unchanged80
(let* ((tasks (read-inbox store))81
(updated (find (lambda (t)82
(equal? (folio-task-id t) task-id))83
tasks)))84
(assert-equal "Keep this text" (folio-task-text updated))85
(assert-equal "medium" (task-priority updated))))))))87
(test "update text preserves done state"88
(call-with-temp-directory89
(lambda (dir)90
(let ((store (make-folio-store dir)))91
(let* ((task (inbox-add! store "Done task" '()))92
(task-id (folio-task-id task)))93
;; Complete the task first by writing the file directly94
(let* ((inbox-path (store-inbox-path store))95
(content (read-file-string inbox-path))96
(new-content (string-replace content "- [ ]" "- [x]")))97
(write-file-string inbox-path new-content))98
;; Update the text99
(update-task-in-store! store task-id100
(dict text: "Updated done task"))101
;; Read back and verify102
(let* ((tasks (read-inbox store))103
(updated (find (lambda (t)104
(equal? (folio-task-id t) task-id))105
tasks)))106
(assert-equal "Updated done task" (folio-task-text updated))107
(assert-true (folio-task-done? updated))))))))109
(test "update nonexistent task returns not found"110
(call-with-temp-directory111
(lambda (dir)112
(let ((store (make-folio-store dir)))113
(inbox-add! store "Some task" '())114
(let ((result (update-task-in-store! store "t-zzzz"115
(dict text: "Won't work"))))116
(assert-true (string-contains? result "not found"))))))))