1
0
Эх сурвалжийг харах

disable rtc merge tests for now

Tienson Qin 1 жил өмнө
parent
commit
bf539751a8

+ 5 - 8
deps/outliner/src/logseq/outliner/tree.cljs

@@ -28,7 +28,8 @@
         blocks (remove #(db-property/shape-block? repo db %) blocks)
         parent-blocks (group-by #(get-in % [:block/parent :db/id]) blocks) ;; exclude whiteboard shapes
         sort-fn (fn [parent]
-                  (ldb/sort-by-left (get parent-blocks parent) {:db/id parent}))
+                  (when-let [children (get parent-blocks parent)]
+                    (ldb/sort-by-left children {:db/id parent})))
         block-children (fn block-children [parent level]
                          (map (fn [m]
                                 (let [id (:db/id m)
@@ -37,7 +38,7 @@
                                   (assoc m
                                          :block/level level
                                          :block/children children)))
-                           (sort-fn parent)))]
+                              (sort-fn parent)))]
     (block-children root-id 1)))
 
 (defn- get-root-and-page
@@ -45,15 +46,11 @@
   (cond
     (uuid? root-id)
     (let [e (d/entity db [:block/uuid root-id])]
-      (if (:block/page e)
-        [false e]
-        [true e]))
+      (if (ldb/page? e) [true e] [false e]))
 
     (number? root-id)
     (let [e (d/entity db root-id)]
-      (if (:block/page e)
-        [false e]
-        [true e]))
+      (if (ldb/page? e) [true e] [false e]))
 
     (string? root-id)
     (if-let [id (parse-uuid root-id)]

+ 3 - 3
src/test/frontend/test/helper.cljs

@@ -24,7 +24,7 @@
 
 (defn start-test-db!
   [& {:as opts}]
-  (let [test-db (if (or (:db-graph? opts) (some? js/process.env.DB_GRAPH))
+  (let [test-db (if (or (:db-graph? opts) (and node? (some? js/process.env.DB_GRAPH)))
                   test-db-name-db-version
                   test-db-name)]
     (state/set-current-repo! test-db)
@@ -196,7 +196,7 @@
   "Given a collection of file maps, loads them into the current test-db.
 This can be called in synchronous contexts as no async fns should be invoked"
   [files]
-  (if js/process.env.DB_GRAPH
+  (if (and node? js/process.env.DB_GRAPH)
     (load-test-files-for-db-graph files)
     (file-repo-handler/parse-files-and-load-to-db!
      test-db
@@ -237,7 +237,7 @@ This can be called in synchronous contexts as no async fns should be invoked"
   connection when done with it."
   [f & {:as start-opts}]
   ;; Set current-repo explicitly since it's not the default
-  (let [db-graph? (or (:db-graph? start-opts) (some? js/process.env.DB_GRAPH))
+  (let [db-graph? (or (:db-graph? start-opts) (and node? (some? js/process.env.DB_GRAPH)))
         repo (if db-graph? test-db-name-db-version test-db-name)]
     (state/set-current-repo! repo)
     (start-test-db! start-opts)

+ 55 - 54
src/test/frontend/worker/rtc/rtc_fns_test.cljs

@@ -447,57 +447,58 @@ server: ;; remove 2
         (rtc-core/apply-remote-remove-page-ops repo conn remove-page-ops)
         (is (nil? (d/entity @conn [:block/uuid page1-uuid])))))))
 
-
-(deftest same-name-two-pages-merge-test
-  (let [repo (state/get-current-repo)
-        conn (conn/get-db repo false)
-        date-formatter (common-config/get-date-formatter (worker-state/get-config repo))
-        opts {:persist-op? false
-              :transact-opts {:repo repo
-                              :conn conn}}
-        page-name "same-name-page-test"
-        [page1-uuid page2-uuid
-         uuid1-client uuid2-client
-         uuid1-remote uuid2-remote] (repeatedly random-uuid)]
-    (page-handler/create! page-name {:redirect? false :create-first-block? false :uuid page1-uuid})
-    (outliner-tx/transact!
-     opts
-     (outliner-core/insert-blocks!
-      repo
-      conn
-      [{:block/uuid uuid1-client
-        :block/content "uuid1-client"
-        :block/left [:block/uuid page1-uuid]
-        :block/parent [:block/uuid page1-uuid]}
-       {:block/uuid uuid2-client
-        :block/content "uuid2-client"
-        :block/left [:block/uuid uuid1-client]
-        :block/parent [:block/uuid page1-uuid]}]
-      (ldb/get-page @conn page-name)
-      {:sibling? true :keep-uuid? true}))
-    (let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
-                        :affected-blocks
-                        {page2-uuid {:op :update-page
-                                     :self page2-uuid
-                                     :page-name page-name
-                                     :original-name page-name}
-                         uuid1-remote {:op :move
-                                       :self uuid1-remote
-                                       :parents [page2-uuid]
-                                       :left page2-uuid
-                                       :content "uuid1-remote"}
-                         uuid2-remote {:op :move
-                                       :self uuid2-remote
-                                       :parents [page2-uuid]
-                                       :left uuid1-remote
-                                       :content "uuid2-remote"}}}
-          all-ops (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))
-          update-page-ops (vals (:update-page-ops-map all-ops))
-          move-ops (#'rtc-core/move-ops-map->sorted-move-ops (:move-ops-map all-ops))]
-      (is (rtc-const/data-from-ws-validator data-from-ws))
-      (rtc-core/apply-remote-update-page-ops repo conn date-formatter update-page-ops)
-      (rtc-core/apply-remote-move-ops repo conn date-formatter move-ops)
-      (let [page (ldb/get-page @conn page-name)]
-        (is (= #{uuid1-client uuid2-client uuid1-remote uuid2-remote}
-             (set (map :block/uuid (ldb/get-page-blocks @conn (:db/id page) {})))))
-        (is (= page2-uuid (:block/uuid page)))))))
+;; TODO: add back once page merge get supported
+(comment
+  (deftest same-name-two-pages-merge-test
+   (let [repo (state/get-current-repo)
+         conn (conn/get-db repo false)
+         date-formatter (common-config/get-date-formatter (worker-state/get-config repo))
+         opts {:persist-op? false
+               :transact-opts {:repo repo
+                               :conn conn}}
+         page-name "same-name-page-test"
+         [page1-uuid page2-uuid
+          uuid1-client uuid2-client
+          uuid1-remote uuid2-remote] (repeatedly random-uuid)]
+     (page-handler/create! page-name {:redirect? false :create-first-block? false :uuid page1-uuid})
+     (outliner-tx/transact!
+      opts
+      (outliner-core/insert-blocks!
+       repo
+       conn
+       [{:block/uuid uuid1-client
+         :block/content "uuid1-client"
+         :block/left [:block/uuid page1-uuid]
+         :block/parent [:block/uuid page1-uuid]}
+        {:block/uuid uuid2-client
+         :block/content "uuid2-client"
+         :block/left [:block/uuid uuid1-client]
+         :block/parent [:block/uuid page1-uuid]}]
+       (ldb/get-page @conn page-name)
+       {:sibling? true :keep-uuid? true}))
+     (let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
+                         :affected-blocks
+                         {page2-uuid {:op :update-page
+                                      :self page2-uuid
+                                      :page-name page-name
+                                      :original-name page-name}
+                          uuid1-remote {:op :move
+                                        :self uuid1-remote
+                                        :parents [page2-uuid]
+                                        :left page2-uuid
+                                        :content "uuid1-remote"}
+                          uuid2-remote {:op :move
+                                        :self uuid2-remote
+                                        :parents [page2-uuid]
+                                        :left uuid1-remote
+                                        :content "uuid2-remote"}}}
+           all-ops (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))
+           update-page-ops (vals (:update-page-ops-map all-ops))
+           move-ops (#'rtc-core/move-ops-map->sorted-move-ops (:move-ops-map all-ops))]
+       (is (rtc-const/data-from-ws-validator data-from-ws))
+       (rtc-core/apply-remote-update-page-ops repo conn date-formatter update-page-ops)
+       (rtc-core/apply-remote-move-ops repo conn date-formatter move-ops)
+       (let [page (ldb/get-page @conn page-name)]
+         (is (= #{uuid1-client uuid2-client uuid1-remote uuid2-remote}
+                (set (map :block/uuid (ldb/get-page-blocks @conn (:db/id page) {})))))
+         (is (= page2-uuid (:block/uuid page))))))))