From 0b9fcbc97b65b349826e63bad89ca121a08fd2be Mon Sep 17 00:00:00 2001 From: Bruno Heridet Date: Tue, 16 Jul 2024 22:35:22 +0200 Subject: [PATCH] (test): add org-roam-db-get-{scheduled|deadline}-time (#2465) --- tests/roam-files/with-times.org | 16 ++++++++++++ tests/test-org-roam-db.el | 43 +++++++++++++++++++++++++++++++-- tests/test-org-roam-node.el | 4 ++- tests/test-org-roam.el | 6 ++--- 4 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 tests/roam-files/with-times.org diff --git a/tests/roam-files/with-times.org b/tests/roam-files/with-times.org new file mode 100644 index 0000000..ebab199 --- /dev/null +++ b/tests/roam-files/with-times.org @@ -0,0 +1,16 @@ +:PROPERTIES: +:ID: 9a20ca6c-5555-41c9-a039-ac38bf59c7a9 +:END: +#+title: With Times + +* Scheduled heading +SCHEDULED: <2024-07-16 Tue> +:PROPERTIES: +:ID: a523c198-4cb4-44d2-909c-a0e3258089cd +:END: + +* Deadline heading +DEADLINE: <2024-07-17 Tue> +:PROPERTIES: +:ID: 3ab84701-d1c1-463f-b5c6-715e6ff5a0bf +:END: diff --git a/tests/test-org-roam-db.el b/tests/test-org-roam-db.el index 89f0913..8715ca0 100644 --- a/tests/test-org-roam-db.el +++ b/tests/test-org-roam-db.el @@ -24,6 +24,42 @@ (require 'buttercup) (require 'org-roam) +(defvar root-directory default-directory) + +(describe "org-roam-db-get-scheduled-time" + (before-all + (setq org-roam-directory (expand-file-name "tests/roam-files") + org-roam-db-location (expand-file-name "org-roam.db" temporary-file-directory) + org-roam-file-extensions '("org") + org-roam-file-exclude-regexp nil) + (org-roam-db-sync)) + + (after-all + (org-roam-db--close) + (delete-file org-roam-db-location) + (cd root-directory)) + + (it "should get scheduled time for current heading node" + (org-roam-id-open "a523c198-4cb4-44d2-909c-a0e3258089cd" nil) + (expect (org-roam-db-get-scheduled-time) :to-equal "2024-07-16T00:00:00+0000"))) + +(describe "org-roam-db-get-deadline-time" + (before-all + (setq org-roam-directory (expand-file-name "tests/roam-files") + org-roam-db-location (expand-file-name "org-roam.db" temporary-file-directory) + org-roam-file-extensions '("org") + org-roam-file-exclude-regexp nil) + (org-roam-db-sync)) + + (after-all + (org-roam-db--close) + (delete-file org-roam-db-location) + (cd root-directory)) + + (it "should get deadline time for current heading node" + (org-roam-id-open "3ab84701-d1c1-463f-b5c6-715e6ff5a0bf" nil) + (expect (org-roam-db-get-deadline-time) :to-equal "2024-07-17T00:00:00+0000"))) + (describe "org-roam-db--file-hash" (it "computes the SHA1 of file" (expect (org-roam-db--file-hash "tests/roam-files/family.org") @@ -45,12 +81,12 @@ (it "has the correct number of files" (expect (caar (org-roam-db-query [:select (funcall count) :from files])) :to-equal - 8)) + 9)) (it "has the correct number of nodes" (expect (caar (org-roam-db-query [:select (funcall count) :from nodes])) :to-equal - 9)) + 12)) (it "has the correct number of links" (expect (caar (org-roam-db-query [:select (funcall count) :from links])) @@ -69,6 +105,9 @@ "77a90980-1994-464e-901f-7e3d3df07fd3" "57ff3ce7-5bda-4825-8fca-c09f523e87ba" "998b2341-b7fe-434d-848c-5282c0727870" + "a523c198-4cb4-44d2-909c-a0e3258089cd" + "3ab84701-d1c1-463f-b5c6-715e6ff5a0bf" + "9a20ca6c-5555-41c9-a039-ac38bf59c7a9" "97bf31cf-dfee-45d8-87a5-2ae0dabc4734"))) (it "reads ref in quotes correctly" diff --git a/tests/test-org-roam-node.el b/tests/test-org-roam-node.el index 6938e8e..8f71c5d 100644 --- a/tests/test-org-roam-node.el +++ b/tests/test-org-roam-node.el @@ -128,7 +128,9 @@ (it "returns the list of titles and aliases" (expect (org-roam--get-titles) :to-have-same-items-as - `("Bar" "Batman" "Bruce Wayne" "Child" "Demoteable" "Family" "Foo" "Grand-Parent" "Parent" "ref with space")))) + `("Bar" "Batman" "Bruce Wayne" "Child" "Deadline heading" "Demoteable" "Family" + "Foo" "Grand-Parent" "Parent" "ref with space" "Scheduled heading" "With Times")))) + (describe "org-roam-alias" (before-all diff --git a/tests/test-org-roam.el b/tests/test-org-roam.el index 76d19b1..4383639 100644 --- a/tests/test-org-roam.el +++ b/tests/test-org-roam.el @@ -57,17 +57,17 @@ (delete-file org-roam-db-location)) (it "gets files correctly" - (expect (length (org-roam-list-files)) :to-equal 8)) + (expect (length (org-roam-list-files)) :to-equal 9)) (it "respects org-roam-file-extensions" (setq org-roam-file-extensions '("md")) (expect (length (org-roam-list-files)) :to-equal 1) (setq org-roam-file-extensions '("org" "md")) - (expect (length (org-roam-list-files)) :to-equal 9)) + (expect (length (org-roam-list-files)) :to-equal 10)) (it "respects org-roam-file-exclude-regexp" (setq org-roam-file-exclude-regexp (regexp-quote "foo.org")) - (expect (length (org-roam-list-files)) :to-equal 7))) + (expect (length (org-roam-list-files)) :to-equal 8))) (describe "org-roam--list-files-search-globs"