summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ss-capture-tests.el145
1 files changed, 105 insertions, 40 deletions
diff --git a/tests/ss-capture-tests.el b/tests/ss-capture-tests.el
index b91d4ef..006c90d 100644
--- a/tests/ss-capture-tests.el
+++ b/tests/ss-capture-tests.el
@@ -13,6 +13,65 @@
(require 'ss-capture)
(require 'ss-org)
+(ert-deftest ss-jump-back-restores-previous-location-and-enables-forward ()
+ (let ((ss-navigation-back-stack nil)
+ (ss-navigation-forward-stack nil)
+ (buffer-a (generate-new-buffer " *ss-nav-a*"))
+ (buffer-b (generate-new-buffer " *ss-nav-b*")))
+ (unwind-protect
+ (save-window-excursion
+ (with-current-buffer buffer-a
+ (insert "alpha")
+ (goto-char 3))
+ (with-current-buffer buffer-b
+ (insert "bravo")
+ (goto-char 5))
+ (switch-to-buffer buffer-a)
+ (ss-navigation-push-current-location)
+ (switch-to-buffer buffer-b)
+ (should (ss-jump-back))
+ (should (eq (current-buffer) buffer-a))
+ (should (= (point) 3))
+ (should (ss-jump-forward))
+ (should (eq (current-buffer) buffer-b))
+ (should (= (point) 5)))
+ (kill-buffer buffer-a)
+ (kill-buffer buffer-b))))
+
+(ert-deftest ss-navigation-push-current-location-clears-forward-after-back ()
+ (let ((ss-navigation-back-stack nil)
+ (ss-navigation-forward-stack nil)
+ (buffer-a (generate-new-buffer " *ss-nav-a*"))
+ (buffer-b (generate-new-buffer " *ss-nav-b*")))
+ (unwind-protect
+ (save-window-excursion
+ (with-current-buffer buffer-a
+ (insert "alpha")
+ (goto-char 2))
+ (with-current-buffer buffer-b
+ (insert "bravo")
+ (goto-char 4))
+ (switch-to-buffer buffer-a)
+ (ss-navigation-push-current-location)
+ (switch-to-buffer buffer-b)
+ (should (ss-jump-back))
+ (should ss-navigation-forward-stack)
+ (ss-navigation-push-current-location)
+ (should-not ss-navigation-forward-stack))
+ (kill-buffer buffer-a)
+ (kill-buffer buffer-b))))
+
+(ert-deftest ss-navigation-record-jump-skips-noop-movements ()
+ (let ((ss-navigation-back-stack nil)
+ (ss-navigation-forward-stack nil))
+ (with-temp-buffer
+ (switch-to-buffer (current-buffer))
+ (insert "alpha")
+ (goto-char 2)
+ (ss-navigation--record-jump (lambda () nil))
+ (should-not ss-navigation-back-stack)
+ (should-not ss-navigation-forward-stack))))
+
(ert-deftest ss-journal-ensure-day-sections-adds-all-standard-sections ()
(with-temp-buffer
(org-mode)
@@ -34,30 +93,35 @@
(ert-deftest ss-open-journal-narrows-to-today-when-entry-exists ()
(let* ((file (make-temp-file "ss-journal" nil ".org"))
- (ss-journal-file file))
+ (ss-journal-file file)
+ (test-time (encode-time 0 0 12 9 4 2026)))
(unwind-protect
- (progn
+ (cl-letf (((symbol-function 'current-time)
+ (lambda ()
+ test-time)))
(with-temp-file file
(insert "#+title: Journal\n"
"* 2026\n"
"** 2026-04-09 Thursday\n"
"*** Notes\n"))
- (let ((org-overriding-default-time (encode-time 0 0 12 9 4 2026)))
- (ss-open-journal)
- (should (buffer-narrowed-p))
- (should (equal (org-get-outline-path t)
- '("2026" "2026-04-09 Thursday")))
- (should (looking-at-p "^\\*\\* 2026-04-09 Thursday$"))))
- (when (buffer-live-p (current-buffer))
- (kill-buffer (current-buffer)))
+ (ss-open-journal)
+ (should (buffer-narrowed-p))
+ (should (equal (org-get-outline-path t)
+ '("2026" "2026-04-09 Thursday")))
+ (should (looking-at-p "^\\*\\* 2026-04-09 Thursday$")))
+ (when-let ((buffer (get-file-buffer file)))
+ (kill-buffer buffer))
(when (file-exists-p file)
(delete-file file)))))
(ert-deftest ss-open-journal-reveals-folded-today-subtree ()
(let* ((file (make-temp-file "ss-journal" nil ".org"))
- (ss-journal-file file))
+ (ss-journal-file file)
+ (test-time (encode-time 0 0 12 9 4 2026)))
(unwind-protect
- (progn
+ (cl-letf (((symbol-function 'current-time)
+ (lambda ()
+ test-time)))
(with-temp-file file
(insert "#+title: Journal\n"
"* 2026\n"
@@ -66,45 +130,46 @@
"Body\n"))
(with-current-buffer (find-file-noselect file)
(org-overview))
- (let ((org-overriding-default-time (encode-time 0 0 12 9 4 2026)))
- (ss-open-journal)
- (should (buffer-narrowed-p))
- (should-not
- (save-excursion
- (goto-char (point-min))
- (re-search-forward "^\\*\\*\\* Notes$" nil t)
- (invisible-p (point))))
- (should-not
- (save-excursion
- (goto-char (point-min))
- (re-search-forward "^Body$" nil t)
- (invisible-p (point))))))
- (when (buffer-live-p (current-buffer))
- (kill-buffer (current-buffer)))
+ (ss-open-journal)
+ (should (buffer-narrowed-p))
+ (should-not
+ (save-excursion
+ (goto-char (point-min))
+ (re-search-forward "^\\*\\*\\* Notes$" nil t)
+ (invisible-p (point))))
+ (should-not
+ (save-excursion
+ (goto-char (point-min))
+ (re-search-forward "^Body$" nil t)
+ (invisible-p (point)))))
+ (when-let ((buffer (get-file-buffer file)))
+ (kill-buffer buffer))
(when (file-exists-p file)
(delete-file file)))))
(ert-deftest ss-open-journal-creates-missing-today-entry-with-standard-sections ()
(let* ((file (make-temp-file "ss-journal" nil ".org"))
- (ss-journal-file file))
+ (ss-journal-file file)
+ (test-time (encode-time 0 0 12 9 4 2026)))
(unwind-protect
- (progn
+ (cl-letf (((symbol-function 'current-time)
+ (lambda ()
+ test-time)))
(with-temp-file file
(insert "#+title: Journal\n"
"* 2026\n"
"** 2026-04-08 Wednesday\n"
"*** Notes\n"))
- (let ((org-overriding-default-time (encode-time 0 0 12 9 4 2026)))
- (ss-open-journal)
- (should (buffer-narrowed-p))
- (should (equal (org-get-outline-path t)
- '("2026" "2026-04-09 Thursday")))
- (should (string-match-p
- (regexp-quote
- "** 2026-04-09 Thursday\n*** Tasks\n*** Notes\n*** Meetings\n")
- (buffer-string)))))
- (when (buffer-live-p (current-buffer))
- (kill-buffer (current-buffer)))
+ (ss-open-journal)
+ (should (buffer-narrowed-p))
+ (should (equal (org-get-outline-path t)
+ '("2026" "2026-04-09 Thursday")))
+ (should (string-match-p
+ (regexp-quote
+ "** 2026-04-09 Thursday\n*** Tasks\n*** Notes\n*** Meetings\n")
+ (buffer-string))))
+ (when-let ((buffer (get-file-buffer file)))
+ (kill-buffer buffer))
(when (file-exists-p file)
(delete-file file)))))