Browse Source

test(rtc): update apply-remote-move-ops-test

rcmerci 1 year ago
parent
commit
7375990c2b
1 changed files with 64 additions and 38 deletions
  1. 64 38
      src/test/frontend/worker/rtc/rtc_fns_test.cljs

+ 64 - 38
src/test/frontend/worker/rtc/rtc_fns_test.cljs

@@ -114,49 +114,75 @@
   (test-helper/destroy-test-db!))
 
 
-(deftest apply-remote-move-ops-test1
+(deftest apply-remote-move-ops-test
   (state/set-current-repo! test-helper/test-db)
   (test-helper/reset-test-db!)
-  (let [page-name "apply-remote-move-ops-test1"
-        conn (conn/get-db test-helper/test-db false)
+  (let [conn (conn/get-db test-helper/test-db false)
         repo test-helper/test-db
         opts {:persist-op? false
               :transact-opts {:repo test-helper/test-db
                               :conn conn}}
+        date-formatter (common-config/get-date-formatter (worker-state/get-config test-helper/test-db))
+        page-name "apply-remote-move-ops-test"
         [page-uuid
          uuid1-client uuid2-client
-         uuid1-remote] (repeatedly random-uuid)
-        data-from-ws {:req-id "req-id"
-                      :t 1
-                      :t-before 0
-                      :affected-blocks
-                      {uuid1-remote {:op :move
-                                     :self uuid1-remote
-                                     :parents [page-uuid]
-                                     :left page-uuid
-                                     :content "uuid1-remote"}}}
-        move-ops (#'rtc-core/move-ops-map->sorted-move-ops
-                  (:move-ops-map
-                   (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
-    (is (rtc-const/data-from-ws-validator data-from-ws))
-    (page-handler/create! page-name {:redirect? false :create-first-block? false :uuid page-uuid})
-    (outliner-tx/transact!
-     opts
-     (outliner-core/insert-blocks!
-      test-helper/test-db
-      conn
-      [{:block/uuid uuid1-client :block/content "uuid1-client"
-        :block/left [:block/uuid page-uuid]
-        :block/parent [:block/uuid page-uuid]}
-       {:block/uuid uuid2-client :block/content "uuid2-client"
-        :block/left [:block/uuid uuid1-client]
-        :block/parent [:block/uuid page-uuid]}]
-      (d/pull @conn '[*] [:block/name page-name])
-      {:sibling? true :keep-uuid? true}))
-    (rtc-core/apply-remote-move-ops repo conn
-                                    (common-config/get-date-formatter (worker-state/get-config test-helper/test-db))
-                                    move-ops)
-    (let [sorted-page-blocks (ldb/sort-by-left
-                              (ldb/get-page-blocks @conn page-name {})
-                              (d/entity @conn [:block/uuid page-uuid]))]
-      (is (= [uuid1-remote uuid1-client uuid2-client] (map :block/uuid sorted-page-blocks))))))
+         uuid1-remote uuid2-remote] (repeatedly random-uuid)]
+    (testing "apply-remote-move-ops-test1"
+      (let [data-from-ws {:req-id "req-id"
+                          :t 1 ;; not used
+                          :t-before 0 ;; not used
+                          :affected-blocks
+                          {uuid1-remote {:op :move
+                                         :self uuid1-remote
+                                         :parents [page-uuid]
+                                         :left page-uuid
+                                         :content "uuid1-remote"}}}
+            move-ops (#'rtc-core/move-ops-map->sorted-move-ops
+                      (:move-ops-map
+                       (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
+        (is (rtc-const/data-from-ws-validator data-from-ws))
+        (page-handler/create! page-name {:redirect? false :create-first-block? false :uuid page-uuid})
+        (outliner-tx/transact!
+         opts
+         (outliner-core/insert-blocks!
+          test-helper/test-db
+          conn
+          [{:block/uuid uuid1-client :block/content "uuid1-client"
+            :block/left [:block/uuid page-uuid]
+            :block/parent [:block/uuid page-uuid]}
+           {:block/uuid uuid2-client :block/content "uuid2-client"
+            :block/left [:block/uuid uuid1-client]
+            :block/parent [:block/uuid page-uuid]}]
+          (d/pull @conn '[*] [:block/name page-name])
+          {:sibling? true :keep-uuid? true}))
+        (rtc-core/apply-remote-move-ops repo conn date-formatter move-ops)
+        (let [page-blocks (ldb/get-page-blocks @conn page-name {})]
+          (is (= #{uuid1-remote uuid1-client uuid2-client} (set (map :block/uuid page-blocks))))
+          (is (= page-uuid (:block/uuid (:block/left (d/entity @conn [:block/uuid uuid1-remote]))))))))
+
+    (testing "apply-remote-move-ops-test2"
+      (let [data-from-ws {:req-id "req-id"
+                          :t 1 ;; not used
+                          :t-before 0
+                          :affected-blocks
+                          {uuid2-remote {:op :move
+                                         :self uuid2-remote
+                                         :parents [uuid1-client]
+                                         :left uuid1-client
+                                         :content "uuid2-remote"}
+                           uuid1-remote {:op :move
+                                         :self uuid1-remote
+                                         :parents [uuid2-remote]
+                                         :left uuid2-remote}}}
+            move-ops (#'rtc-core/move-ops-map->sorted-move-ops
+                      (:move-ops-map
+                       (#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
+        (is (rtc-const/data-from-ws-validator data-from-ws))
+        (rtc-core/apply-remote-move-ops repo conn date-formatter move-ops)
+        (let [page-blocks (ldb/get-page-blocks @conn page-name {})]
+          (is (= #{uuid1-remote uuid2-remote uuid1-client uuid2-client} (set (map :block/uuid page-blocks))))
+          (is (= uuid1-client (:block/uuid (:block/left (d/entity @conn [:block/uuid uuid2-remote])))))
+          (is (= uuid2-remote (:block/uuid (:block/left (d/entity @conn [:block/uuid uuid1-remote]))))))))
+
+    (state/set-current-repo! nil)
+    (test-helper/destroy-test-db!)))