graph_parser_test.cljs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. (ns logseq.graph-parser-test
  2. (:require [cljs.test :refer [deftest testing is]]
  3. [logseq.graph-parser :as graph-parser]
  4. [logseq.db :as ldb]
  5. [logseq.graph-parser.block :as gp-block]
  6. [datascript.core :as d]))
  7. (deftest parse-file
  8. (testing "id properties"
  9. (let [conn (ldb/start-conn)]
  10. (graph-parser/parse-file conn "foo.md" "- id:: 628953c1-8d75-49fe-a648-f4c612109098" {})
  11. (is (= [{:id "628953c1-8d75-49fe-a648-f4c612109098"}]
  12. (->> (d/q '[:find (pull ?b [*])
  13. :in $
  14. :where [?b :block/content] [(missing? $ ?b :block/name)]]
  15. @conn)
  16. (map first)
  17. (map :block/properties)))
  18. "id as text has correct :block/properties"))
  19. (let [conn (ldb/start-conn)]
  20. (graph-parser/parse-file conn "foo.md" "- id:: [[628953c1-8d75-49fe-a648-f4c612109098]]" {})
  21. (is (= [{:id #{"628953c1-8d75-49fe-a648-f4c612109098"}}]
  22. (->> (d/q '[:find (pull ?b [*])
  23. :in $
  24. :where [?b :block/content] [(missing? $ ?b :block/name)]]
  25. @conn)
  26. (map first)
  27. (map :block/properties)))
  28. "id as linked ref has correct :block/properties")))
  29. (testing "unexpected failure during block extraction"
  30. (let [conn (ldb/start-conn)
  31. deleted-page (atom nil)]
  32. (with-redefs [gp-block/with-pre-block-if-exists (fn stub-failure [& _args]
  33. (throw (js/Error "Testing unexpected failure")))]
  34. (try
  35. (graph-parser/parse-file conn "foo.md" "- id:: 628953c1-8d75-49fe-a648-f4c612109098"
  36. {:delete-blocks-fn (fn [page _file]
  37. (reset! deleted-page page))})
  38. (catch :default _)))
  39. (is (= nil @deleted-page)
  40. "Page should not be deleted when there is unexpected failure"))))