fix: rtc unit tests

This commit is contained in:
Tienson Qin
2025-10-14 21:25:38 +08:00
parent b8eb7a8564
commit a63a5acc8b
2 changed files with 26 additions and 13 deletions

View File

@@ -208,13 +208,14 @@ so need to pull earlier remote-data from websocket."})
b (d/entity @conn [:block/uuid block-uuid])]
(case [whiteboard-page-block? (some? local-parent) (some? remote-block-order)]
[false true true]
(do (if move?
(transact-db! :move-blocks repo conn [(block-reuse-db-id b)] local-parent {:sibling? false})
(transact-db! :insert-blocks repo conn
[{:block/uuid block-uuid
:block/title ""}]
local-parent {:sibling? false :keep-uuid? true}))
(transact-db! :update-block-order-directly repo conn block-uuid first-remote-parent remote-block-order))
(do
(if move?
(transact-db! :move-blocks repo conn [(block-reuse-db-id b)] local-parent {:sibling? false})
(transact-db! :insert-blocks repo conn
[{:block/uuid block-uuid
:block/title ""}]
local-parent {:sibling? false :keep-uuid? true}))
(transact-db! :update-block-order-directly repo conn block-uuid first-remote-parent remote-block-order))
[false true false]
(if move?
@@ -447,7 +448,8 @@ so need to pull earlier remote-data from websocket."})
remote-v* (set (map ldb/read-transit-str remote-v))
[local-only remote-only] (data/diff (set local-v) remote-v*)]
(cond-> []
(seq local-only) (concat (map (fn [v] [:db/retract e k v]) local-only))
(seq local-only) (concat (map (fn [v]
[:db/retract e k v]) local-only))
(seq remote-only) (concat (map (fn [v] [:db/add e k v]) remote-only)))))))
(defn- diff-block-map->tx-data

View File

@@ -172,10 +172,12 @@
(outliner-core/insert-blocks!
repo
conn
[{:block/uuid uuid1-client :block/title "uuid1-client"
[{:block/uuid uuid1-client
:block/title "uuid1-client"
:block/order "a1"
:block/parent [:block/uuid page-uuid]}
{:block/uuid uuid2-client :block/title "uuid2-client"
{:block/uuid uuid2-client
:block/title "uuid2-client"
:block/order "a2"
:block/parent [:block/uuid page-uuid]}]
(ldb/get-page @conn page-name)
@@ -188,7 +190,10 @@
{uuid1-remote {:op :move
:self uuid1-remote
:parents [page-uuid]
:block/order "a0"}}}
:block/order "a0"
:block/title (ldb/write-transit-str "")
:block/created-at (js/Date.now)
:block/updated-at (js/Date.now)}}}
move-ops (#'r.remote/move-ops-map->sorted-move-ops
(:move-ops-map
(#'r.remote/affected-blocks->diff-type-ops
@@ -208,11 +213,17 @@
{uuid2-remote {:op :move
:self uuid2-remote
:parents [uuid1-client]
:block/order "a0"}
:block/order "a0"
:block/title (ldb/write-transit-str "")
:block/created-at (js/Date.now)
:block/updated-at (js/Date.now)}
uuid1-remote {:op :move
:self uuid1-remote
:parents [uuid2-remote]
:block/order "a1"}}}
:block/order "a1"
:block/title (ldb/write-transit-str "")
:block/created-at (js/Date.now)
:block/updated-at (js/Date.now)}}}
move-ops (#'r.remote/move-ops-map->sorted-move-ops
(:move-ops-map
(#'r.remote/affected-blocks->diff-type-ops