mirror of
https://github.com/logseq/logseq.git
synced 2026-04-27 23:54:55 +00:00
enhance: add optional support for importing all tags as classes
Part of LOG-3235 and fixes part of logseq/db-test#7. Not enabled in UI yet as need to test more
This commit is contained in:
@@ -112,7 +112,7 @@
|
||||
"Import a file graph dir just like UI does. However, unlike the UI the
|
||||
exporter receives file maps containing keys :path and ::rpath since :path
|
||||
are full paths"
|
||||
[file-graph-dir conn {:keys [assets] :as options}]
|
||||
[file-graph-dir conn {:keys [assets] :or {assets (atom [])} :as options}]
|
||||
(let [*files (build-graph-files file-graph-dir)
|
||||
config-file (first (filter #(string/ends-with? (:path %) "logseq/config.edn") *files))
|
||||
_ (assert config-file "No 'logseq/config.edn' found for file graph dir")
|
||||
@@ -155,9 +155,8 @@
|
||||
(p/let [file-graph-dir "test/resources/docs-0.10.9"
|
||||
_ (docs-graph-helper/clone-docs-repo-if-not-exists file-graph-dir "v0.10.9")
|
||||
conn (db-test/create-conn)
|
||||
assets (atom [])
|
||||
{:keys [import-state]}
|
||||
(import-file-graph-to-db file-graph-dir conn {:assets assets})]
|
||||
(import-file-graph-to-db file-graph-dir conn {})]
|
||||
|
||||
(is (empty? (map :entity (:errors (db-validate/validate-db! @conn))))
|
||||
"Created graph has no validation errors")
|
||||
@@ -191,6 +190,11 @@
|
||||
:where [?b :block/title] [_ :block/page ?b]] @conn)
|
||||
(filter ldb/internal-page?))))
|
||||
"Correct number of pages with block content")
|
||||
(is (= 0 (->> @conn
|
||||
(d/q '[:find [?ident ...]
|
||||
:where [?b :block/type "class"] [?b :db/ident ?ident] (not [?b :logseq.property/built-in?])])
|
||||
count))
|
||||
"Correct number of user classes")
|
||||
(is (= 4 (count (d/datoms @conn :avet :block/type "whiteboard"))))
|
||||
(is (= 0 (count @(:ignored-properties import-state))) ":filters should be the only ignored property")
|
||||
(is (= 1 (count @assets))))
|
||||
@@ -459,6 +463,23 @@
|
||||
(:logseq.property/page-tags (readable-properties @conn (find-page-by-name @conn "chat-gpt"))))
|
||||
"tagged page has new page and other pages marked with '#' and '[[]]` imported as tags to page-tags")))))
|
||||
|
||||
(deftest-async export-basic-graph-with-convert-all-tags
|
||||
(p/let [file-graph-dir "test/resources/exporter-test-graph"
|
||||
conn (db-test/create-conn)
|
||||
;; Simulate frontend path-refs being calculated
|
||||
_ (db-pipeline/add-listener conn)
|
||||
{:keys [import-state]}
|
||||
(import-file-graph-to-db file-graph-dir conn {:convert-all-tags? true})]
|
||||
|
||||
(is (empty? (map :entity (:errors (db-validate/validate-db! @conn))))
|
||||
"Created graph has no validation errors")
|
||||
(is (= 0 (count @(:ignored-properties import-state))) "No ignored properties")
|
||||
(is (= 9 (->> @conn
|
||||
(d/q '[:find [?ident ...]
|
||||
:where [?b :block/type "class"] [?b :db/ident ?ident] (not [?b :logseq.property/built-in?])])
|
||||
count))
|
||||
"Correct number of user classes")))
|
||||
|
||||
(deftest-async export-files-with-tag-classes-option
|
||||
(p/let [file-graph-dir "test/resources/exporter-test-graph"
|
||||
files (mapv #(node-path/join file-graph-dir %) ["journals/2024_02_07.md" "pages/Interstellar.md"])
|
||||
|
||||
Reference in New Issue
Block a user