(test): add org-roam-node-from-{id|title-or-alias} (#2454)

This commit is contained in:
Bruno Heridet
2024-07-08 18:59:53 +02:00
committed by GitHub
parent a432539121
commit 43a5362ada
3 changed files with 58 additions and 6 deletions

View File

@ -0,0 +1,5 @@
:PROPERTIES:
:ID: 57FF3CE7-5BDA-4825-8FCA-C09F523E87BA
:ROAM_ALIASES: Batman
:END:
#+title: Bruce Wayne

View File

@ -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)

View File

@ -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"