Browse Source

fix: tests

Tienson Qin 3 tuần trước cách đây
mục cha
commit
248fdeb422

+ 9 - 8
deps/graph-parser/src/logseq/graph_parser/exporter.cljs

@@ -1188,7 +1188,7 @@
                    (:block/uuid asset-data)
                    {:asset-name-uuid [asset-name (:block/uuid asset-data)]}
 
-                   (nil? (get-asset-block-id assets asset-name))
+                   (not (get-asset-block-id assets asset-name))
                    (js/console.error (str "No asset-id for " asset-name))
 
                    :else
@@ -1964,13 +1964,14 @@
 
 (defn- read-and-copy-asset-files
   "Reads and copies files under assets/"
-  [*asset-files <read-and-copy-asset-file {:keys [notify-user set-ui-state assets]
+  [*asset-files <read-and-copy-asset-file {:keys [notify-user set-ui-state assets rpath-key]
                                            :or {set-ui-state (constantly nil)}}]
   (assert <read-and-copy-asset-file "read-and-copy-asset-file fn required")
-  (let [asset-files (mapv #(assoc %1 :idx %2)
-                          ;; Sort files to ensure reproducible import behavior
-                          (sort-by :path *asset-files)
-                          (range 0 (count *asset-files)))
+  (let [asset-files (let [assets (common-util/distinct-by rpath-key *asset-files)]
+                      (mapv #(assoc %1 :idx %2)
+                            ;; Sort files to ensure reproducible import behavior
+                            (sort-by :path assets)
+                            (range 0 (count assets))))
         read-and-copy-asset (fn read-and-copy-asset [{:keys [path] :as file}]
                               (-> (<read-and-copy-asset-file
                                    file assets
@@ -1980,7 +1981,7 @@
                                            pdf-annotation? (some #{:highlights} (keys edn-content))
                                            with-edn-content (fn [m]
                                                               (cond-> m
-                                                                edn?
+                                                                edn-content
                                                                 (assoc :edn-content edn-content)))]
                                        {:with-edn-content with-edn-content
                                         :pdf-annotation? pdf-annotation?})))
@@ -2100,7 +2101,7 @@
         ;; Assets are read first as doc-files need data from them to make Asset blocks.
         (read-and-copy-asset-files asset-files
                                    <read-and-copy-asset
-                                   (merge (select-keys options [:notify-user :set-ui-state])
+                                   (merge (select-keys options [:notify-user :set-ui-state :rpath-key])
                                           {:assets (get-in doc-options [:import-state :assets])}))
         (export-doc-files conn doc-files <read-file doc-options)
         (export-favorites-from-config-edn conn repo-or-conn config {})

+ 3 - 2
deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs

@@ -101,8 +101,9 @@
           asset-id (d/squuid)
           asset-name (gp-exporter/asset-path->name (:path file))
           asset-type (db-asset/asset-path->type (:path file))
-          {:keys [with-edn-content _pdf-annotation?]} (buffer-handler buffer)]
-    (swap! *asset-ids conj asset-id)
+          {:keys [with-edn-content pdf-annotation?]} (buffer-handler buffer)]
+    (when-not pdf-annotation?
+      (swap! *asset-ids conj asset-id))
     (swap! assets assoc asset-name
            (with-edn-content
              {:size (.-length buffer)