diff --git a/tests/roam-files/with-alias.org b/tests/roam-files/with-alias.org new file mode 100644 index 0000000..d5c0768 --- /dev/null +++ b/tests/roam-files/with-alias.org @@ -0,0 +1,5 @@ +:PROPERTIES: +:ID: 57FF3CE7-5BDA-4825-8FCA-C09F523E87BA +:ROAM_ALIASES: Batman +:END: +#+title: Bruce Wayne diff --git a/tests/test-org-roam-node.el b/tests/test-org-roam-node.el index d8e609c..93a02f1 100644 --- a/tests/test-org-roam-node.el +++ b/tests/test-org-roam-node.el @@ -26,6 +26,52 @@ (defvar root-directory default-directory) +(describe "org-roam-node-from-id" + (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)) + + (it "returns nil for unknown id" + (expect (org-roam-node-from-id "non-existing") :to-equal nil)) + + (it "returns correct node from id" + (let ((node (org-roam-node-from-id "884b2341-b7fe-434d-848c-5282c0727861"))) + (expect (org-roam-node-title node) :to-equal "Foo")))) + +(describe "org-roam-node-from-title-or-alias" + (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)) + + (it "returns nil for unknown title" + (expect (org-roam-node-from-title-or-alias "non-existing") :to-equal nil)) + + (it "returns correct node from title" + (let ((node (org-roam-node-from-title-or-alias "Foo"))) + (expect (org-roam-node-title node) :to-equal "Foo"))) + + (it "returns correct node from alias" + (let ((node (org-roam-node-from-title-or-alias "Batman"))) + (expect (org-roam-node-title node) :to-equal "Bruce Wayne"))) + + (it "returns correct node from alias with nocase" + (let ((node (org-roam-node-from-title-or-alias "batman" t))) + (expect (org-roam-node-title node) :to-equal "Bruce Wayne")))) + (describe "org-roam--h1-count" (after-each (cd root-directory)) @@ -72,7 +118,7 @@ (it "returns the list of titles and aliases" (expect (org-roam--get-titles) :to-have-same-items-as - `("Bar" "Child" "Family" "Foo" "Grand-Parent" "Parent" "ref with space")))) + `("Bar" "Batman" "Bruce Wayne" "Child" "Family" "Foo" "Grand-Parent" "Parent" "ref with space")))) (provide 'test-org-roam-node) diff --git a/tests/test-org-roam.el b/tests/test-org-roam.el index b4930c9..c5681f5 100644 --- a/tests/test-org-roam.el +++ b/tests/test-org-roam.el @@ -36,17 +36,17 @@ (delete-file org-roam-db-location)) (it "gets files correctly" - (expect (length (org-roam-list-files)) :to-equal 6)) + (expect (length (org-roam-list-files)) :to-equal 7)) (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 7)) + (expect (length (org-roam-list-files)) :to-equal 8)) (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 5))) + (expect (length (org-roam-list-files)) :to-equal 6))) (describe "org-roam-db-sync" (before-all @@ -63,12 +63,12 @@ (it "has the correct number of files" (expect (caar (org-roam-db-query [:select (funcall count) :from files])) :to-equal - 6)) + 7)) (it "has the correct number of nodes" (expect (caar (org-roam-db-query [:select (funcall count) :from nodes])) :to-equal - 7)) + 8)) (it "has the correct number of links" (expect (caar (org-roam-db-query [:select (funcall count) :from links])) @@ -85,6 +85,7 @@ "0fa5bb3e-3d8c-4966-8bc9-78d32e505d69" "5fb4fdc5-b6d2-4f75-8d54-e60053e467ec" "77a90980-1994-464e-901f-7e3d3df07fd3" + "57FF3CE7-5BDA-4825-8FCA-C09F523E87BA" "998b2341-b7fe-434d-848c-5282c0727870"))) (it "reads ref in quotes correctly"