exporter_test.cljs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. (ns ^:node-only logseq.graph-parser.exporter-test
  2. (:require [cljs.test :refer [testing is]]
  3. [logseq.graph-parser.test.helper :as test-helper :include-macros true :refer [deftest-async]]
  4. [logseq.graph-parser.test.docs-graph-helper :as docs-graph-helper]
  5. [datascript.core :as d]
  6. [clojure.string :as string]
  7. [clojure.set :as set]
  8. ["path" :as node-path]
  9. ["fs" :as fs]
  10. [logseq.common.graph :as common-graph]
  11. [promesa.core :as p]
  12. [logseq.db.frontend.validate :as db-validate]
  13. [logseq.graph-parser.exporter :as gp-exporter]
  14. [logseq.db.frontend.malli-schema :as db-malli-schema]
  15. [logseq.db.frontend.property :as db-property]
  16. [logseq.db.frontend.property.type :as db-property-type]
  17. [logseq.common.config :as common-config]
  18. [logseq.db :as ldb]
  19. [logseq.outliner.db-pipeline :as db-pipeline]
  20. [logseq.db.test.helper :as db-test]
  21. [logseq.db.frontend.rules :as rules]))
  22. ;; Helpers
  23. ;; =======
  24. ;; some have been copied from db-import script
  25. (defn- find-block-by-content [db content]
  26. (if (instance? js/RegExp content)
  27. (->> content
  28. (d/q '[:find [(pull ?b [*]) ...]
  29. :in $ ?pattern
  30. :where [?b :block/title ?content]
  31. [(missing? $ ?b :block/type)]
  32. [(re-find ?pattern ?content)]]
  33. db)
  34. first)
  35. (->> content
  36. (d/q '[:find [(pull ?b [*]) ...]
  37. :in $ ?content
  38. :where [?b :block/title ?content] [(missing? $ ?b :block/type)]]
  39. db)
  40. first)))
  41. (defn- find-block-by-property [db property property-value]
  42. (->> (d/q '[:find [(pull ?b [*]) ...]
  43. :in $ ?prop ?prop-value %
  44. :where (property ?b ?prop ?prop-value)]
  45. db property property-value (rules/extract-rules rules/db-query-dsl-rules [:property]))
  46. first))
  47. (defn- find-page-by-name [db name]
  48. (->> name
  49. (d/q '[:find [(pull ?b [*]) ...]
  50. :in $ ?name
  51. :where [?b :block/title ?name]]
  52. db)
  53. first))
  54. (defn- build-graph-files
  55. "Given a file graph directory, return all files including assets and adds relative paths
  56. on ::rpath since paths are absolute by default and exporter needs relative paths for
  57. some operations"
  58. [dir*]
  59. (let [dir (node-path/resolve dir*)]
  60. (->> (common-graph/get-files dir)
  61. (concat (when (fs/existsSync (node-path/join dir* "assets"))
  62. (common-graph/readdir (node-path/join dir* "assets"))))
  63. (mapv #(hash-map :path %
  64. ::rpath (node-path/relative dir* %))))))
  65. (defn- <read-file
  66. [file]
  67. (p/let [s (fs/readFileSync (:path file))]
  68. (str s)))
  69. (defn- notify-user [m]
  70. (println (:msg m))
  71. (when (:ex-data m)
  72. (println "Ex-data:" (pr-str (dissoc (:ex-data m) :error)))
  73. (println "Stacktrace:")
  74. (if-let [stack (some-> (get-in m [:ex-data :error]) ex-data :sci.impl/callstack deref)]
  75. (println (string/join
  76. "\n"
  77. (map
  78. #(str (:file %)
  79. (when (:line %) (str ":" (:line %)))
  80. (when (:sci.impl/f-meta %)
  81. (str " calls #'" (get-in % [:sci.impl/f-meta :ns]) "/" (get-in % [:sci.impl/f-meta :name]))))
  82. (reverse stack))))
  83. (println (some-> (get-in m [:ex-data :error]) .-stack))))
  84. (when (= :error (:level m))
  85. (js/process.exit 1)))
  86. (def default-export-options
  87. {;; common options
  88. :rpath-key ::rpath
  89. :notify-user notify-user
  90. :<read-file <read-file
  91. ;; :set-ui-state prn
  92. ;; config file options
  93. ;; TODO: Add actual default
  94. :default-config {}})
  95. ;; Copied from db-import script and tweaked for an in-memory import
  96. (defn- import-file-graph-to-db
  97. "Import a file graph dir just like UI does. However, unlike the UI the
  98. exporter receives file maps containing keys :path and ::rpath since :path
  99. are full paths"
  100. [file-graph-dir conn {:keys [assets] :as options}]
  101. (let [*files (build-graph-files file-graph-dir)
  102. config-file (first (filter #(string/ends-with? (:path %) "logseq/config.edn") *files))
  103. _ (assert config-file "No 'logseq/config.edn' found for file graph dir")
  104. options' (-> (merge default-export-options
  105. options
  106. ;; asset file options
  107. {:<copy-asset #(swap! assets conj %)})
  108. (dissoc :assets))]
  109. (gp-exporter/export-file-graph conn conn config-file *files options')))
  110. (defn- import-files-to-db
  111. "Import specific doc files for dev purposes"
  112. [files conn options]
  113. (p/let [doc-options (gp-exporter/build-doc-options {:macros {}} (merge default-export-options options))
  114. files' (mapv #(hash-map :path %) files)
  115. _ (gp-exporter/export-doc-files conn files' <read-file doc-options)]
  116. {:import-state (:import-state doc-options)}))
  117. (defn- readable-properties
  118. [db query-ent]
  119. (->> (db-property/properties query-ent)
  120. (map (fn [[k v]]
  121. (if (boolean? v)
  122. [k v]
  123. [k
  124. (if-let [built-in-type (get-in db-property/built-in-properties [k :schema :type])]
  125. (if (= :block/tags k)
  126. (mapv #(:db/ident (d/entity db (:db/id %))) v)
  127. (if (db-property-type/all-ref-property-types built-in-type)
  128. (db-property/ref->property-value-contents db v)
  129. v))
  130. (db-property/ref->property-value-contents db v))])))
  131. (into {})))
  132. ;; Tests
  133. ;; =====
  134. (deftest-async ^:integration export-docs-graph
  135. (p/let [file-graph-dir "test/resources/docs-0.10.9"
  136. _ (docs-graph-helper/clone-docs-repo-if-not-exists file-graph-dir "v0.10.9")
  137. conn (db-test/create-conn)
  138. assets (atom [])
  139. {:keys [import-state]}
  140. (import-file-graph-to-db file-graph-dir conn {:assets assets})]
  141. (is (empty? (map :entity (:errors (db-validate/validate-db! @conn))))
  142. "Created graph has no validation errors")
  143. (is (= 0 (count @(:ignored-properties import-state))) "No ignored properties")))
  144. (deftest-async export-basic-graph
  145. ;; This graph will contain basic examples of different features to import
  146. (p/let [file-graph-dir "test/resources/exporter-test-graph"
  147. conn (db-test/create-conn)
  148. ;; Simulate frontend path-refs being calculated
  149. _ (db-pipeline/add-listener conn)
  150. assets (atom [])
  151. {:keys [import-state]} (import-file-graph-to-db file-graph-dir conn {:assets assets})]
  152. (testing "whole graph"
  153. (is (empty? (map :entity (:errors (db-validate/validate-db! @conn))))
  154. "Created graph has no validation errors")
  155. ;; Counts
  156. ;; Includes journals as property values e.g. :logseq.task/deadline
  157. (is (= 18 (count (d/q '[:find ?b :where [?b :block/type "journal"]] @conn))))
  158. (is (= 18 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Journal]] @conn))))
  159. (is (= 4 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Task]] @conn))))
  160. (is (= 2 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Query]] @conn))))
  161. ;; Don't count pages like url.md that have properties but no content
  162. (is (= 8
  163. (count (->> (d/q '[:find [(pull ?b [:block/title :block/type]) ...]
  164. :where [?b :block/title] [_ :block/page ?b]] @conn)
  165. (filter #(= "page" (:block/type %))))))
  166. "Correct number of pages with block content")
  167. (is (= 4 (count (d/datoms @conn :avet :block/type "whiteboard"))))
  168. (is (= 1 (count @(:ignored-properties import-state))) ":filters should be the only ignored property")
  169. (is (= 1 (count @assets))))
  170. (testing "logseq files"
  171. (is (= ".foo {}\n"
  172. (ffirst (d/q '[:find ?content :where [?b :file/path "logseq/custom.css"] [?b :file/content ?content]] @conn))))
  173. (is (= "logseq.api.show_msg('hello good sir!');\n"
  174. (ffirst (d/q '[:find ?content :where [?b :file/path "logseq/custom.js"] [?b :file/content ?content]] @conn)))))
  175. (testing "favorites"
  176. (is (= #{"Interstellar" "some page"}
  177. (->>
  178. (ldb/get-page-blocks @conn
  179. (:db/id (ldb/get-page @conn common-config/favorites-page-name))
  180. {:pull-keys '[* {:block/link [:block/title]}]})
  181. (map #(get-in % [:block/link :block/title]))
  182. set))))
  183. (testing "user properties"
  184. (is (= 18
  185. (->> @conn
  186. (d/q '[:find [(pull ?b [:db/ident]) ...]
  187. :where [?b :block/type "property"]])
  188. (remove #(db-malli-schema/internal-ident? (:db/ident %)))
  189. count))
  190. "Correct number of user properties")
  191. (is (= #{{:db/ident :user.property/prop-bool :block/schema {:type :checkbox}}
  192. {:db/ident :user.property/prop-string :block/schema {:type :default}}
  193. {:db/ident :user.property/prop-num :block/schema {:type :number}}
  194. {:db/ident :user.property/sameas :block/schema {:type :url}}
  195. {:db/ident :user.property/rangeincludes :block/schema {:type :node}}
  196. {:db/ident :user.property/startedat :block/schema {:type :date}}}
  197. (->> @conn
  198. (d/q '[:find [(pull ?b [:db/ident :block/schema]) ...]
  199. :where [?b :block/type "property"]])
  200. (filter #(contains? #{:prop-bool :prop-string :prop-num :rangeincludes :sameas :startedat}
  201. (keyword (name (:db/ident %)))))
  202. set))
  203. "Main property types have correct inferred :type")
  204. (is (= :default
  205. (get-in (d/entity @conn :user.property/description) [:block/schema :type]))
  206. "Property value consisting of text and refs is inferred as :default")
  207. (is (= :url
  208. (get-in (d/entity @conn :user.property/url) [:block/schema :type]))
  209. "Property value with a macro correctly inferred as :url")
  210. (is (= {:user.property/prop-bool true
  211. :user.property/prop-num 5
  212. :user.property/prop-string "woot"}
  213. (update-vals (db-property/properties (find-block-by-content @conn "b1"))
  214. (fn [v] (if (map? v) (db-property/ref->property-value-content @conn v) v))))
  215. "Basic block has correct properties")
  216. (is (= #{"prop-num" "prop-string" "prop-bool"}
  217. (->> (d/entity @conn (:db/id (find-block-by-content @conn "b1")))
  218. :block/refs
  219. (map :block/title)
  220. set))
  221. "Block with properties has correct refs")
  222. (is (= {:user.property/prop-num2 10}
  223. (readable-properties @conn (find-page-by-name @conn "new page")))
  224. "New page has correct properties")
  225. (is (= {:user.property/prop-bool true
  226. :user.property/prop-num 5
  227. :user.property/prop-string "yeehaw"}
  228. (readable-properties @conn (find-page-by-name @conn "some page")))
  229. "Existing page has correct properties")
  230. (is (= {:user.property/rating 5.5}
  231. (readable-properties @conn (find-block-by-content @conn ":rating float")))
  232. "Block with float property imports as a float"))
  233. (testing "built-in properties"
  234. (is (= [(:db/id (find-block-by-content @conn "original block"))]
  235. (mapv :db/id (:block/refs (find-block-by-content @conn #"ref to"))))
  236. "block with a block-ref has correct :block/refs")
  237. (let [b (find-block-by-content @conn #"MEETING TITLE")]
  238. (is (= {}
  239. (and b (readable-properties @conn b)))
  240. ":template properties are ignored to not invalidate its property types"))
  241. (is (= {:logseq.task/deadline "Nov 26th, 2022"}
  242. (readable-properties @conn (find-block-by-content @conn "only deadline")))
  243. "deadline block has correct journal as property value")
  244. (is (= {:logseq.task/deadline "Nov 25th, 2022"}
  245. (readable-properties @conn (find-block-by-content @conn "only scheduled")))
  246. "scheduled block converted to correct deadline")
  247. (is (= {:logseq.task/priority "High"}
  248. (readable-properties @conn (find-block-by-content @conn "high priority")))
  249. "priority block has correct property")
  250. (is (= {:logseq.task/status "Doing" :logseq.task/priority "Medium" :block/tags [:logseq.class/Task]}
  251. (readable-properties @conn (find-block-by-content @conn "status test")))
  252. "status block has correct task properties and class")
  253. (is (= #{:logseq.task/status :block/tags}
  254. (set (keys (readable-properties @conn (find-block-by-content @conn "old todo block")))))
  255. "old task properties like 'todo' are ignored")
  256. (is (= {:logseq.property/order-list-type "number"}
  257. (readable-properties @conn (find-block-by-content @conn "list one")))
  258. "numered block has correct property")
  259. (is (= #{"gpt"}
  260. (:block/alias (readable-properties @conn (find-page-by-name @conn "chat-gpt")))))
  261. (is (= {:logseq.property.table/sorting [{:id :user.property/prop-num, :asc? false}]
  262. :logseq.property.view/type "Table View"
  263. :logseq.property.table/ordered-columns [:block/title :user.property/prop-string :user.property/prop-num]
  264. :logseq.property/query "(property :prop-string)"
  265. :block/tags [:logseq.class/Query]}
  266. (readable-properties @conn (find-block-by-property @conn :logseq.property/query "(property :prop-string)")))
  267. "query block has correct query properties")
  268. (is (= "For example, here's a query with title text:"
  269. (:block/title (find-block-by-content @conn #"query with title text")))
  270. "Text around a query block is set as a query's title"))
  271. (testing "db attributes"
  272. (is (= true
  273. (:block/collapsed? (find-block-by-content @conn "collapsed block")))
  274. "Collapsed blocks are imported"))
  275. (testing "property :type changes"
  276. (is (= :node
  277. (get-in (d/entity @conn :user.property/finishedat) [:block/schema :type]))
  278. ":date property to :node value changes to :node")
  279. (is (= :node
  280. (get-in (d/entity @conn :user.property/participants) [:block/schema :type]))
  281. ":node property to :date value remains :node")
  282. (is (= :default
  283. (get-in (d/entity @conn :user.property/description) [:block/schema :type]))
  284. ":default property to :node (or any non :default value) remains :default")
  285. (is (= "[[Jakob]]"
  286. (:user.property/description (readable-properties @conn (find-block-by-content @conn #":default to :node"))))
  287. ":default to :node property saves :default property value default with full text")
  288. (testing "with changes to upstream/existing property value"
  289. (is (= :default
  290. (get-in (d/entity @conn :user.property/duration) [:block/schema :type]))
  291. ":number property to :default value changes to :default")
  292. (is (= "20"
  293. (:user.property/duration (readable-properties @conn (find-block-by-content @conn "existing :number to :default"))))
  294. "existing :number property value correctly saved as :default")
  295. (is (= {:block/schema {:type :default} :db/cardinality :db.cardinality/many}
  296. (select-keys (d/entity @conn :user.property/people) [:block/schema :db/cardinality]))
  297. ":node property to :default value changes to :default and keeps existing cardinality")
  298. (is (= #{"[[Jakob]] [[Gabriel]]"}
  299. (:user.property/people (readable-properties @conn (find-block-by-content @conn ":node people"))))
  300. "existing :node property value correctly saved as :default with full text")
  301. (is (= #{"[[Gabriel]] [[Jakob]]"}
  302. (:user.property/people (readable-properties @conn (find-block-by-content @conn #"pending block for :node"))))
  303. "pending :node property value correctly saved as :default with full text")))
  304. (testing "replacing refs in :block/title"
  305. (is (= 2
  306. (->> (find-block-by-content @conn #"replace with same start string")
  307. :block/title
  308. (re-seq #"\[\[~\^\S+\]\]")
  309. distinct
  310. count))
  311. "A block with ref names that start with same string has 2 distinct refs")
  312. (is (= 1
  313. (->> (find-block-by-content @conn #"replace case insensitive")
  314. :block/title
  315. (re-seq #"\[\[~\^\S+\]\]")
  316. distinct
  317. count))
  318. "A block with different case of same ref names has 1 distinct ref"))
  319. (testing "imported concepts can have names of new-built concepts"
  320. (is (= #{:logseq.property/description :user.property/description}
  321. (set (d/q '[:find [?ident ...] :where [?b :db/ident ?ident] [?b :block/name "description"]] @conn)))
  322. "user description property is separate from built-in one")
  323. (is (= #{"page" "class"}
  324. (set (d/q '[:find [?type ...] :where [?b :block/type ?type] [?b :block/name "task"]] @conn)))
  325. "user page is separate from built-in class"))
  326. (testing "multiline blocks"
  327. (is (= "|markdown| table|\n|some|thing|" (:block/title (find-block-by-content @conn #"markdown.*table"))))
  328. (is (= "multiline block\na 2nd\nand a 3rd" (:block/title (find-block-by-content @conn #"multiline block"))))
  329. (is (= "logbook block" (:block/title (find-block-by-content @conn #"logbook block"))))
  330. (is (re-find #"(?s)^Text before\n#\+BEGIN_QUERY.*END_QUERY\nText after$"
  331. (:block/title (find-block-by-content @conn #":title \"tasks")))))
  332. (testing "block refs and path-refs"
  333. (let [block (find-block-by-content @conn "old todo block")]
  334. (is (set/subset?
  335. #{:logseq.task/status :logseq.class/Task}
  336. (->> block
  337. :block/path-refs
  338. (map #(:db/ident (d/entity @conn (:db/id %))))
  339. set))
  340. "Correct :block/refs")
  341. (is (set/subset?
  342. #{:logseq.task/status :logseq.class/Task}
  343. (->> block
  344. :block/path-refs
  345. (map #(:db/ident (d/entity @conn (:db/id %))))
  346. set))
  347. "Correct :block/path-refs")))
  348. (testing "whiteboards"
  349. (let [block-with-props (find-block-by-content @conn #"block with props")]
  350. (is (= {:user.property/prop-num 10}
  351. (readable-properties @conn block-with-props)))
  352. (is (= "block with props" (:block/title block-with-props)))))
  353. (testing "tags without tag options"
  354. (let [block (find-block-by-content @conn #"Inception")
  355. tag-page (find-page-by-name @conn "Movie")
  356. tagged-page (find-page-by-name @conn "Interstellar")]
  357. (is (string/starts-with? (str (:block/title block)) "Inception [[")
  358. "tagged block tag converts tag to page ref")
  359. (is (= [(:db/id tag-page)] (map :db/id (:block/refs block)))
  360. "tagged block has correct refs")
  361. (is (and tag-page (not (ldb/class? tag-page)))
  362. "tag page is not a class")
  363. (is (= {:logseq.property/page-tags #{"Movie"}}
  364. (readable-properties @conn tagged-page))
  365. "tagged page has existing page imported as a tag to page-tags")
  366. (is (= #{"LargeLanguageModel" "fun" "ai"}
  367. (:logseq.property/page-tags (readable-properties @conn (find-page-by-name @conn "chat-gpt"))))
  368. "tagged page has new page and other pages marked with '#' and '[[]]` imported as tags to page-tags")))))
  369. (deftest-async export-files-with-tag-classes-option
  370. (p/let [file-graph-dir "test/resources/exporter-test-graph"
  371. files (mapv #(node-path/join file-graph-dir %) ["journals/2024_02_07.md" "pages/Interstellar.md"])
  372. conn (db-test/create-conn)
  373. _ (import-files-to-db files conn {:tag-classes ["movie"]})]
  374. (is (empty? (map :entity (:errors (db-validate/validate-db! @conn))))
  375. "Created graph has no validation errors")
  376. (let [block (find-block-by-content @conn #"Inception")
  377. tag-page (find-page-by-name @conn "Movie")
  378. another-tag-page (find-page-by-name @conn "p0")]
  379. (is (= (:block/title block) "Inception")
  380. "tagged block with configured tag strips tag from content")
  381. (is (= [:user.class/Movie]
  382. (:block/tags (readable-properties @conn block)))
  383. "tagged block has configured tag imported as a class")
  384. (is (= "class" (:block/type tag-page))
  385. "configured tag page in :tag-classes is a class")
  386. (is (and another-tag-page (not (ldb/class? another-tag-page)))
  387. "unconfigured tag page is not a class")
  388. (is (= {:block/tags [:user.class/Movie]}
  389. (readable-properties @conn (find-page-by-name @conn "Interstellar")))
  390. "tagged page has configured tag imported as a class"))))
  391. (deftest-async export-files-with-property-classes-option
  392. (p/let [file-graph-dir "test/resources/exporter-test-graph"
  393. files (mapv #(node-path/join file-graph-dir %) ["journals/2024_02_23.md" "pages/url.md"])
  394. conn (db-test/create-conn)
  395. _ (import-files-to-db files conn {:property-classes ["type"]})
  396. _ (@#'gp-exporter/export-class-properties conn conn)]
  397. (is (empty? (map :entity (:errors (db-validate/validate-db! @conn))))
  398. "Created graph has no validation errors")
  399. (is (= #{:user.class/Property :user.class/Movie}
  400. (->> @conn
  401. (d/q '[:find [?ident ...]
  402. :where [?b :block/type "class"] [?b :db/ident ?ident] (not [?b :logseq.property/built-in?])])
  403. set))
  404. "All classes are correctly defined by :type")
  405. (is (= #{:user.property/url :user.property/sameas :user.property/rangeincludes}
  406. (->> (d/entity @conn :user.class/Property)
  407. :logseq.property.class/properties
  408. (map :db/ident)
  409. set))
  410. "Properties are correctly inferred for a class")
  411. (let [block (find-block-by-content @conn #"The Creator")
  412. tag-page (find-page-by-name @conn "Movie")]
  413. (is (= (:block/title block) "The Creator")
  414. "tagged block with configured tag strips tag from content")
  415. (is (= [:user.class/Movie]
  416. (:block/tags (readable-properties @conn block)))
  417. "tagged block has configured tag imported as a class")
  418. (is (= (:user.property/testtagclass block) (:block/tags block))
  419. "tagged block can have another property that references the same class it is tagged with,
  420. without creating a duplicate class")
  421. (is (= "class" (:block/type tag-page))
  422. "configured tag page derived from :property-classes is a class")
  423. (is (nil? (find-page-by-name @conn "type"))
  424. "No page exists for configured property")
  425. (is (= [:user.class/Property]
  426. (:block/tags (readable-properties @conn (find-page-by-name @conn "url"))))
  427. "tagged page has configured tag imported as a class"))))
  428. (deftest-async export-files-with-ignored-properties
  429. (p/let [file-graph-dir "test/resources/exporter-test-graph"
  430. files (mapv #(node-path/join file-graph-dir %) ["ignored/icon-page.md"])
  431. conn (db-test/create-conn)
  432. {:keys [import-state]} (import-files-to-db files conn {})]
  433. (is (= 2
  434. (count (filter #(= :icon (:property %)) @(:ignored-properties import-state))))
  435. "icon properties are visibly ignored in order to not fail import")))
  436. (deftest-async export-files-with-property-parent-classes-option
  437. (p/let [file-graph-dir "test/resources/exporter-test-graph"
  438. files (mapv #(node-path/join file-graph-dir %) ["pages/CreativeWork.md" "pages/Movie.md" "pages/type.md"])
  439. conn (db-test/create-conn)
  440. _ (import-files-to-db files conn {:property-parent-classes ["parent"]})]
  441. (is (empty? (map :entity (:errors (db-validate/validate-db! @conn))))
  442. "Created graph has no validation errors")
  443. (is (= #{:user.class/Movie :user.class/CreativeWork :user.class/Thing}
  444. (->> @conn
  445. (d/q '[:find [?ident ...]
  446. :where [?b :block/type "class"] [?b :db/ident ?ident] (not [?b :logseq.property/built-in?])])
  447. set))
  448. "All classes are correctly defined by :type")
  449. (is (= "CreativeWork" (get-in (d/entity @conn :user.class/Movie) [:logseq.property/parent :block/title]))
  450. "Existing page correctly set as class parent")
  451. (is (= "Thing" (get-in (d/entity @conn :user.class/CreativeWork) [:logseq.property/parent :block/title]))
  452. "New page correctly set as class parent")))