From eac5f104f1dd2c7d5ae259ff0d7486f3585563ed Mon Sep 17 00:00:00 2001 From: rcmerci Date: Sun, 21 Jul 2024 18:47:06 +0800 Subject: [PATCH] chore(rtc): remove outdated unittests --- src/main/frontend/worker/rtc/const.cljs | 4 +- .../frontend/worker/rtc/db_listener_test.cljs | 8 + .../worker/rtc/local_tx_to_remote_test.cljs | 83 ---------- .../frontend/worker/rtc/rtc_fns_test.cljs | 147 ------------------ 4 files changed, 11 insertions(+), 231 deletions(-) delete mode 100644 src/test/frontend/worker/rtc/local_tx_to_remote_test.cljs diff --git a/src/main/frontend/worker/rtc/const.cljs b/src/main/frontend/worker/rtc/const.cljs index 4af911dae..6ea997c50 100644 --- a/src/main/frontend/worker/rtc/const.cljs +++ b/src/main/frontend/worker/rtc/const.cljs @@ -59,7 +59,9 @@ [:db/cardinality {:optional true} :keyword] [:db/index {:optional true} :boolean]]]]]) -(def to-ws-ops-validator (m/validator [:sequential to-ws-op-schema])) +(comment + (def to-ws-ops-validator (m/validator [:sequential to-ws-op-schema]))) + (def to-ws-ops-decoder (m/decoder [:sequential to-ws-op-schema] mt/string-transformer)) (def ^:private extra-attr-map-schema diff --git a/src/test/frontend/worker/rtc/db_listener_test.cljs b/src/test/frontend/worker/rtc/db_listener_test.cljs index 5b78fca56..881320a9e 100644 --- a/src/test/frontend/worker/rtc/db_listener_test.cljs +++ b/src/test/frontend/worker/rtc/db_listener_test.cljs @@ -1,10 +1,17 @@ (ns frontend.worker.rtc.db-listener-test (:require [cljs.test :as t :refer [deftest is testing]] [datascript.core :as d] + [frontend.test.helper :as test-helper] [frontend.worker.db-listener :as worker-db-listener] [frontend.worker.rtc.db-listener :as subject] + [frontend.worker.rtc.fixture :as r.fixture] [logseq.db.frontend.schema :as db-schema])) + +(t/use-fixtures :each + test-helper/db-based-start-and-destroy-db-map-fixture + r.fixture/listen-test-db-to-gen-rtc-ops-fixture) + (def empty-db (d/empty-db db-schema/schema-for-db-based-graph)) (defn- tx-data=>e->a->add?->v->t @@ -13,6 +20,7 @@ id->same-entity-datoms (group-by first datom-vec-coll)] (update-vals id->same-entity-datoms #'worker-db-listener/entity-datoms=>a->add?->v->t))) +;;; TODO: add more cases (deftest entity-datoms=>ops-test (testing "remove whiteboard page-block" (let [conn (d/conn-from-db empty-db) diff --git a/src/test/frontend/worker/rtc/local_tx_to_remote_test.cljs b/src/test/frontend/worker/rtc/local_tx_to_remote_test.cljs deleted file mode 100644 index 65e076251..000000000 --- a/src/test/frontend/worker/rtc/local_tx_to_remote_test.cljs +++ /dev/null @@ -1,83 +0,0 @@ -(ns frontend.worker.rtc.local-tx-to-remote-test - (:require [clojure.test :as t :refer [deftest is testing use-fixtures]] - [datascript.core :as d] - [frontend.db.conn :as conn] - [frontend.state :as state] - [frontend.test.helper :as test-helper] - [frontend.worker.rtc.client :as r.client] - [frontend.worker.rtc.const :as rtc-const] - [frontend.worker.rtc.fixture :as rtc-fixture] - [frontend.worker.state :as worker-state] - [logseq.common.config :as common-config] - [logseq.db :as ldb] - [logseq.outliner.core :as outliner-core] - [logseq.outliner.transaction :as outliner-tx])) - -(use-fixtures :each - test-helper/db-based-start-and-destroy-db-map-fixture - rtc-fixture/listen-test-db-to-gen-rtc-ops-fixture) - -(deftest ^:fix-me local-db-tx->remote-ops-test - (let [repo (state/get-current-repo) - conn (conn/get-db repo false) - [page1-uuid - uuid1 uuid2] (repeatedly random-uuid) - page1-name (str page1-uuid) - date-formatter (common-config/get-date-formatter (worker-state/get-config repo)) - opts {:persist-op? true - :transact-opts {:repo repo - :conn conn}} - gen-ops-fn (fn [] - (let [r (rtc-const/to-ws-ops-decoder - (#'r.client/sort-remote-ops - (#'r.client/gen-block-uuid->remote-ops repo conn "user-uuid")))] - (is (rtc-const/to-ws-ops-validator r) r) - r))] - (testing "create a new page" - (test-helper/create-page! page1-name {:redirect? false :create-first-block? false :uuid page1-uuid}) - (let [ops (gen-ops-fn) - ops* (map - (fn [[op-type op-value]] - [op-type (cond-> op-value - (:av-coll op-value) (assoc :av-coll-keys (map first (:av-coll op-value))) - true (dissoc :av-coll))]) - ops)] - (is (= [[:update-page {:block-uuid page1-uuid - :page-name page1-name - :original-name page1-name}] - [:update {:block-uuid page1-uuid - :pos [nil nil] - :av-coll-keys [:block/created-at :block/updated-at :block/type]}]] ops*) - ops))) - - (testing "insert some blocks" - (outliner-tx/transact! - opts - (outliner-core/insert-blocks! - repo - conn - [{:block/uuid uuid1 - :block/content "uuid1-client" - :block/parent [:block/uuid page1-uuid]} - {:block/uuid uuid2 :block/content "uuid2-client" - :block/parent [:block/uuid page1-uuid]}] - (ldb/get-page @conn page1-name) - {:sibling? true :keep-uuid? true})) - (let [ops (gen-ops-fn)] - (is (= #{[:move uuid1 page1-uuid] - [:move uuid2 page1-uuid] - [:update uuid1 page1-uuid] - [:update uuid2 page1-uuid]} - (set (map (juxt first (comp :block-uuid second) (comp first :pos second)) ops)))))) - - (testing "remove some blocks" - (outliner-tx/transact! - opts - (outliner-core/delete-blocks! - repo - conn - date-formatter - [(d/entity @conn [:block/uuid uuid1])] - opts)) - (let [ops (gen-ops-fn)] - (is (contains? (set ops) [:remove {:block-uuids [uuid1]}])))))) diff --git a/src/test/frontend/worker/rtc/rtc_fns_test.cljs b/src/test/frontend/worker/rtc/rtc_fns_test.cljs index a3b0d5cc7..2f9b0a256 100644 --- a/src/test/frontend/worker/rtc/rtc_fns_test.cljs +++ b/src/test/frontend/worker/rtc/rtc_fns_test.cljs @@ -80,45 +80,6 @@ :block/content "update content"}} r))))) -;; (deftest gen-remote-ops-test -;; (let [repo (state/get-current-repo) -;; conn (conn/get-db repo false) -;; [uuid1 uuid2 uuid3 uuid4] (repeatedly random-uuid) -;; opts {:persist-op? false -;; :transact-opts {:repo repo -;; :conn conn}}] -;; (test-helper/create-page! "gen-remote-ops-test" {:redirect? false :create-first-block? false :uuid uuid1}) -;; (outliner-tx/transact! -;; opts -;; (outliner-core/insert-blocks! -;; repo -;; conn -;; [{:block/uuid uuid2 :block/content "uuid2-block"} -;; {:block/uuid uuid3 :block/content "uuid3-block" -;; :block/parent [:block/uuid uuid1]} -;; {:block/uuid uuid4 :block/content "uuid4-block" -;; :block/parent [:block/uuid uuid1]}] -;; (ldb/get-page @conn "gen-remote-ops-test") -;; {:sibling? true :keep-uuid? true})) - -;; (op-mem-layer/init-empty-ops-store! repo) -;; (op-mem-layer/add-ops! repo [[:move 1 {:block-uuid uuid2}] -;; [:move 2 {:block-uuid uuid4}] -;; [:move 3 {:block-uuid uuid3}] -;; [:update 4 {:block-uuid uuid4 -;; :av-coll [[:block/content (ldb/write-transit-str "uuid4-block") 4 true]]}]]) -;; (let [_ (op-mem-layer/new-branch! repo) -;; r1 (#'r.client/gen-block-uuid->remote-ops repo conn :n 1) -;; _ (op-mem-layer/rollback! repo) -;; r2 (#'r.client/gen-block-uuid->remote-ops repo conn :n 3)] -;; (is (= {uuid2 [:move]} -;; (update-vals r1 keys))) -;; (is (= {uuid2 [:move] -;; uuid3 [:move] -;; uuid4 [:move :update]} -;; (update-vals r2 keys)))) -;; (op-mem-layer/remove-ops-store! repo))) - (deftest ^:fix-me apply-remote-move-ops-test (let [repo (state/get-current-repo) conn (conn/get-db repo false) @@ -189,114 +150,6 @@ (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])))))))))) -;; (deftest ^:large-vars/cleanup-todo apply-remote-update-ops-test -;; (let [repo (state/get-current-repo) -;; conn (conn/get-db repo false) -;; opts {:persist-op? false -;; :transact-opts {:repo repo -;; :conn conn}} -;; date-formatter (common-config/get-date-formatter (worker-state/get-config repo)) -;; page-name "apply-remote-update-ops-test" -;; [page-uuid -;; uuid1-client uuid2-client -;; uuid1-remote -;; uuid1-not-exist -;; tag1-uuid] (repeatedly random-uuid)] -;; (test-helper/create-page! page-name {:redirect? false :create-first-block? false :uuid page-uuid}) -;; (outliner-tx/transact! -;; opts -;; (outliner-core/insert-blocks! -;; repo -;; 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]}] -;; (ldb/get-page @conn page-name) -;; {:sibling? true :keep-uuid? true})) -;; (testing "apply-remote-update-ops-test1" -;; (let [data-from-ws {:req-id "req-id" -;; :t 1 ;; not used -;; :t-before 0 -;; :affected-blocks -;; {uuid1-remote {:op :update-attrs -;; :self uuid1-remote -;; :parents [uuid1-client] -;; :left uuid1-client -;; :content "uuid2-remote" -;; :created-at 1 -;; :link uuid1-client -;; :type ["property"]}}} -;; update-ops (vals -;; (:update-ops-map -;; (#'r.remote/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))] -;; (is (rtc-const/data-from-ws-validator data-from-ws)) -;; (#'r.remote/apply-remote-update-ops repo conn date-formatter update-ops) -;; (let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})] -;; (is (= #{uuid1-client uuid2-client uuid1-remote} (set (map :block/uuid page-blocks)))) -;; (is (= [uuid1-client #{"property"}] -;; ((juxt (comp :block/uuid :block/link) :block/type) (d/entity @conn [:block/uuid uuid1-remote]))))))) - -;; (testing "apply-remote-update-ops-test2" -;; (let [data-from-ws {:req-id "req-id" -;; :t 1 -;; :t-before 0 -;; :affected-blocks -;; {uuid1-remote {:op :update-attrs -;; :self uuid1-remote -;; :parents [uuid1-client] -;; :left uuid1-client -;; :content "uuid2-remote" -;; :created-at 1 -;; :link nil -;; :type nil}}} -;; update-ops (vals -;; (:update-ops-map -;; (#'r.remote/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))] -;; (is (rtc-const/data-from-ws-validator data-from-ws)) -;; (#'r.remote/apply-remote-update-ops repo conn date-formatter update-ops) -;; (let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})] -;; (is (= #{uuid1-client uuid2-client uuid1-remote} (set (map :block/uuid page-blocks)))) -;; (is (= [nil nil] ((juxt :block/link :block/type) (d/entity @conn [:block/uuid uuid1-remote]))))))) -;; (testing "apply-remote-update-ops-test3" -;; (let [data-from-ws {:req-id "req-id" -;; :t 1 :t-before 0 -;; :affected-blocks -;; {uuid1-remote {:op :update-attrs -;; :self uuid1-remote -;; :parents [uuid2-client] -;; :left uuid2-client -;; :link uuid1-not-exist}}} -;; update-ops (vals -;; (:update-ops-map -;; (#'r.remote/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))] -;; (is (rtc-const/data-from-ws-validator data-from-ws)) -;; (#'r.remote/apply-remote-update-ops repo conn date-formatter update-ops) -;; (let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})] -;; (is (= #{uuid1-client uuid2-client uuid1-remote} (set (map :block/uuid page-blocks)))) -;; (is (= [nil nil] ((juxt :block/link :block/type) (d/entity @conn [:block/uuid uuid1-remote]))))))) -;; (testing "update-attr :block/tags" -;; (let [data-from-ws {:req-id "req-id" -;; :t 1 :t-before 0 -;; :affected-blocks -;; {uuid1-remote {:op :update-attrs -;; :self uuid1-remote -;; :parents [uuid2-client] -;; :left uuid2-client -;; :tags [tag1-uuid]}}} -;; update-ops (vals -;; (:update-ops-map -;; (#'r.remote/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))] -;; (d/transact! conn [{:block/uuid tag1-uuid -;; :block/type #{"class"}, -;; :block/name "task", -;; :block/original-name "Task"}]) -;; (is (rtc-const/data-from-ws-validator data-from-ws)) -;; (#'r.remote/apply-remote-update-ops repo conn date-formatter update-ops) -;; (is (= #{tag1-uuid} (set (map :block/uuid (:block/tags (d/entity @conn [:block/uuid uuid1-remote])))))))))) - (deftest ^:fix-me apply-remote-remove-ops-test (let [repo (state/get-current-repo) conn (conn/get-db repo false)