Browse Source

fix: repo test

need to stub worker-state config instead of state config. Also removed
unused async code in test fn
Gabriel Horner 7 months ago
parent
commit
f846ec9dae

+ 3 - 28
src/main/frontend/handler/file_based/file.cljs

@@ -193,14 +193,12 @@
                                    :payload {:type :write-file/failed-for-alter-file}}]))))))))
 
 (defn alter-file-test-version
-  "Write any in-DB file, e.g. repo config, page, whiteboard, etc."
-  [repo path content {:keys [reset? re-render-root? from-disk? skip-compare? new-graph? verbose
+  "Test version of alter-file that is synchronous"
+  [repo path content {:keys [reset? from-disk? new-graph? verbose
                              ctime mtime]
                       :fs/keys [event]
                       :or {reset? true
-                           re-render-root? false
-                           from-disk? false
-                           skip-compare? false}}]
+                           from-disk? false}}]
   (let [path (common-util/path-normalize path)
         config-file? (= path "logseq/config.edn")
         _ (when config-file?
@@ -224,29 +222,6 @@
                                                          ;; To avoid skipping the `:or` bounds for keyword destructuring
                                                  (when (some? verbose) {:verbose verbose}))))
                      (db/set-file-content! repo path content opts))]
-        (-> (p/let [_ (when-not from-disk?
-                        (write-file-aux! repo path content {:skip-compare? skip-compare?}))]
-              (when re-render-root? (ui-handler/re-render-root!))
-
-              (cond
-                (= path "logseq/custom.css")
-                (do
-                  ;; ui-handler will load css from db and config
-                  (db/set-file-content! repo path content)
-                  (ui-handler/add-style-if-exists!))
-
-                (= path "logseq/config.edn")
-                (p/let [_ (repo-config-handler/restore-repo-config! repo content)]
-                  (state/pub-event! [:shortcut/refresh])))
-
-              result)
-            (p/catch
-             (fn [error]
-               (println "Write file failed, path: " path ", content: " content)
-               (log/error :write/failed error)
-               (state/pub-event! [:capture-error
-                                  {:error error
-                                   :payload {:type :write-file/failed-for-alter-file}}]))))
         result))))
 
 (defn set-file-content!

+ 3 - 2
src/test/frontend/handler/repo_test.cljs

@@ -10,7 +10,8 @@
             [datascript.core :as d]
             [clojure.edn :as edn]
             ["path" :as node-path]
-            ["fs" :as fs]))
+            ["fs" :as fs]
+            [frontend.worker.state :as worker-state]))
 
 (use-fixtures :each test-helper/start-and-destroy-db)
 
@@ -19,7 +20,7 @@
         _ (docs-graph-helper/clone-docs-repo-if-not-exists graph-dir "v0.10.9")
         repo-config (edn/read-string (str (fs/readFileSync (node-path/join graph-dir "logseq/config.edn"))))
         files (#'gp-cli/build-graph-files graph-dir repo-config)
-        _ (test-helper/with-config repo-config
+        _ (with-redefs [worker-state/get-config (constantly repo-config)]
             (file-repo-handler/parse-files-and-load-to-db! test-helper/test-db files {:re-render? false :verbose false}))
         db (conn/get-db test-helper/test-db)]