Преглед на файлове

fix: add import test for asset

part of LOG-3092
Gabriel Horner преди 1 година
родител
ревизия
92134dec71

+ 12 - 10
deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs

@@ -58,23 +58,24 @@
   "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 options]
+  [file-graph-dir conn {:keys [assets] :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")
-        options (merge options
-                       default-export-options
-                       ;; TODO: Update when asset is tested
-                        ;; asset file options
-                       {:<copy-asset identity})]
-    (gp-exporter/export-file-graph conn conn config-file *files options)))
+        options' (-> (merge options
+                            default-export-options
+                            ;; asset file options
+                            {:<copy-asset #(swap! assets conj %)})
+                     (dissoc :assets))]
+    (gp-exporter/export-file-graph conn conn config-file *files options')))
 
 (deftest-async export-basic-graph
   ;; This graph will contain basic examples of different features to import
   (p/let [file-graph-dir "test/resources/exporter-test-graph"
           conn (d/create-conn db-schema/schema-for-db-based-graph)
           _ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
-          _ (import-file-graph-to-db file-graph-dir conn {})]
+          assets (atom [])
+          _ (import-file-graph-to-db file-graph-dir conn {:assets assets})]
 
     (is (nil? (:errors (db-validate/validate-db! @conn)))
         "Created graph has no validation errors")
@@ -85,5 +86,6 @@
       (is (= "logseq.api.show_msg('hello good sir!');\n"
              (ffirst (d/q '[:find ?content :where [?b :file/path "logseq/custom.js"] [?b :file/content ?content]] @conn)))))
 
-    (testing "user pages"
-      (is (= 1 (count (d/q '[:find ?b :where [?b :block/type "journal"]] @conn)))))))
+    (testing "user content"
+      (is (= 2 (count (d/q '[:find ?b :where [?b :block/type "journal"]] @conn))))
+      (is (= 1 (count @assets))))))

BIN
deps/graph-parser/test/resources/exporter-test-graph/assets/greg-popovich-thumbs-up_1704749687791_0.png


+ 2 - 0
deps/graph-parser/test/resources/exporter-test-graph/journals/2024_01_08.md

@@ -0,0 +1,2 @@
+- [[some page]]
+- ![greg-popovich-thumbs-up.png](../assets/greg-popovich-thumbs-up_1704749687791_0.png){:height 288, :width 252}