aboutsummaryrefslogtreecommitdiff
path: root/tests/test-pearl-org-write.el
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-pearl-org-write.el')
-rw-r--r--tests/test-pearl-org-write.el29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/test-pearl-org-write.el b/tests/test-pearl-org-write.el
index c253190..bd06ef0 100644
--- a/tests/test-pearl-org-write.el
+++ b/tests/test-pearl-org-write.el
@@ -26,6 +26,7 @@
;;; Code:
(require 'test-bootstrap (expand-file-name "test-bootstrap.el"))
+(require 'cl-lib)
(defvar test-pearl--sample-issues
'((:id "u" :identifier "ENG-1" :title "T" :priority 3 :state (:name "Todo")))
@@ -81,5 +82,33 @@ The state mapping is bound so rendering is deterministic."
(should (string-match-p "unsaved edits" (buffer-string)))
(should-not (string-match-p "ENG-1" (buffer-string)))))))
+(ert-deftest test-pearl-update-org-dirty-buffer-preserves-disk-and-surfaces ()
+ "A dirty buffer is left as-is, the on-disk file is untouched, and the buffer is surfaced."
+ (test-pearl--with-org-file tmp
+ (let ((buf (find-file-noselect tmp))
+ (surfaced nil))
+ (with-current-buffer buf
+ (insert "ORIGINAL DISK CONTENT\n")
+ (save-buffer)
+ ;; an unsaved edit on top of the saved content
+ (goto-char (point-max))
+ (insert "UNSAVED EDIT\n"))
+ (cl-letf (((symbol-function 'pearl--surface-buffer)
+ (lambda (b) (setq surfaced b))))
+ (pearl--update-org-from-issues test-pearl--sample-issues))
+ ;; buffer keeps the unsaved edit and stays modified
+ (with-current-buffer buf
+ (should (buffer-modified-p))
+ (should (string-match-p "UNSAVED EDIT" (buffer-string)))
+ (should-not (string-match-p "ENG-1" (buffer-string))))
+ ;; the disk file still holds the original saved content — not the render,
+ ;; and not the unsaved buffer text
+ (let ((disk (with-temp-buffer (insert-file-contents tmp) (buffer-string))))
+ (should (string-match-p "ORIGINAL DISK CONTENT" disk))
+ (should-not (string-match-p "UNSAVED EDIT" disk))
+ (should-not (string-match-p "ENG-1" disk)))
+ ;; the dirty buffer is still surfaced, per the UX contract
+ (should (eq surfaced buf)))))
+
(provide 'test-pearl-org-write)
;;; test-pearl-org-write.el ends here