From cc8ce571e70a238c726a6f1d1d7e966297f9829c Mon Sep 17 00:00:00 2001 From: rcmerci Date: Wed, 28 Aug 2024 20:53:59 +0800 Subject: [PATCH] test(rtc): add basic-edits-test --- shadow-cljs.edn | 2 +- src/main/frontend/worker/db_listener.cljs | 8 +++- src/main/frontend/worker/rtc/const.cljs | 3 +- src/rtc_e2e_test/basic_edits_test.cljs | 45 +++++++++++++++++++++++ src/rtc_e2e_test/block_update_test.cljs | 12 ------ src/rtc_e2e_test/fixture.cljs | 7 +++- src/rtc_e2e_test/helper.cljs | 4 ++ 7 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 src/rtc_e2e_test/basic_edits_test.cljs delete mode 100644 src/rtc_e2e_test/block_update_test.cljs diff --git a/shadow-cljs.edn b/shadow-cljs.edn index c6c0611d2b..f5c18cd6ed 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -91,7 +91,7 @@ :rtc-e2e-test {:target :browser-test :test-dir "static/rtc-e2e-test" - :closure-defines {frontend.worker.rtc.const/RTC-E2E-TEST true} + :closure-defines {frontend.worker.rtc.const/RTC-E2E-TEST* true} :devtools {:enabled false} :compiler-options {:infer-externs :auto :output-feature-set :es-next-in diff --git a/src/main/frontend/worker/db_listener.cljs b/src/main/frontend/worker/db_listener.cljs index 60bc8feafc..a074b9fa57 100644 --- a/src/main/frontend/worker/db_listener.cljs +++ b/src/main/frontend/worker/db_listener.cljs @@ -83,6 +83,12 @@ generate asset-change events.") (when (seq blocks-to-add) (.search-upsert-blocks wo repo (bean/->js blocks-to-add)))))))))) +(comment + (defmethod listen-db-changes :debug-listen-db-changes + [_ {:keys [tx-data tx-meta]}] + (prn :debug-listen-db-changes) + (prn :tx-data tx-data) + (prn :tx-meta tx-meta))) (defn listen-db-changes! [repo conn & {:keys [handler-keys]}] @@ -90,7 +96,7 @@ generate asset-change events.") (select-keys (methods listen-db-changes) handler-keys) (methods listen-db-changes))] (d/unlisten! conn ::listen-db-changes!) - (prn :listen-db-changes! (keys handlers)) + (prn :listen-db-changes! (keys handlers) :repo repo) (d/listen! conn ::listen-db-changes! (fn [{:keys [tx-data _db-before _db-after tx-meta] :as tx-report}] (let [tx-meta (merge (batch-tx/get-batch-opts) tx-meta) diff --git a/src/main/frontend/worker/rtc/const.cljs b/src/main/frontend/worker/rtc/const.cljs index 156cc63ef4..e674076dda 100644 --- a/src/main/frontend/worker/rtc/const.cljs +++ b/src/main/frontend/worker/rtc/const.cljs @@ -5,7 +5,8 @@ [malli.transform :as mt] [malli.util :as mu])) -(goog-define RTC-E2E-TEST false) +(goog-define RTC-E2E-TEST* false) +(def RTC-E2E-TEST RTC-E2E-TEST*) (def block-pos-schema [:catn diff --git a/src/rtc_e2e_test/basic_edits_test.cljs b/src/rtc_e2e_test/basic_edits_test.cljs new file mode 100644 index 0000000000..b72cb5834f --- /dev/null +++ b/src/rtc_e2e_test/basic_edits_test.cljs @@ -0,0 +1,45 @@ +(ns basic-edits-test + (:require [cljs.test :as t :refer [deftest testing is]] + [fixture] + [helper] + [frontend.worker.rtc.client-op :as client-op] + [const] + [datascript.core :as d] + [logseq.db :as ldb] + [logseq.outliner.batch-tx :as batch-tx])) + +(t/use-fixtures :once + fixture/install-some-consts + fixture/install-example-db-fixture + fixture/clear-test-remote-graphs-fixture + fixture/build-two-conns-by-download-example-graph-fixture) + +(deftest basic-edits-test + (let [conn1 (helper/get-downloaded-test-conn) + conn2 (helper/get-downloaded-test-conn2) + [page-uuid1 block-uuid1] (repeatedly random-uuid)] + (testing "create page first" + (let [tx-data [{:db/id "page" + :block/name "basic-edits-test" + :block/title "basic-edits-test" + :block/uuid page-uuid1 + :block/created-at 1724836490809 + :block/updated-at 1724836490809 + :block/type "page" + :block/format :markdown} + {:block/uuid block-uuid1 + :block/updated-at 1724836490810 + :block/created-at 1724836490810 + :block/format :markdown + :block/title "block1" + :block/parent "page" + :block/order "a0" + :block/page "page"}]] + (batch-tx/with-batch-tx-mode conn1 {:e2e-test const/downloaded-test-repo} + (d/transact! conn1 tx-data)) + (is (= + #{[:update page-uuid1] [:update-page page-uuid1] [:move block-uuid1] [:update block-uuid1]} + (set (map (juxt first (comp :block-uuid last)) (client-op/get-all-ops const/downloaded-test-repo))))) + (prn :all-ops + (client-op/get-all-ops const/downloaded-test-repo) + (client-op/get-local-tx const/downloaded-test-repo)))))) diff --git a/src/rtc_e2e_test/block_update_test.cljs b/src/rtc_e2e_test/block_update_test.cljs deleted file mode 100644 index 40dadce0f9..0000000000 --- a/src/rtc_e2e_test/block_update_test.cljs +++ /dev/null @@ -1,12 +0,0 @@ -(ns block-update-test - (:require [cljs.test :as t :refer [deftest]] - [fixture])) - -(t/use-fixtures :once - fixture/install-some-consts - fixture/install-example-db-fixture - fixture/clear-test-remote-graphs-fixture - fixture/build-two-conns-by-download-example-graph-fixture) - -(deftest insert-blocks-test - ) diff --git a/src/rtc_e2e_test/fixture.cljs b/src/rtc_e2e_test/fixture.cljs index 75c96a716c..1f3eb29197 100644 --- a/src/rtc_e2e_test/fixture.cljs +++ b/src/rtc_e2e_test/fixture.cljs @@ -5,6 +5,7 @@ [example] [frontend.common.missionary-util :as c.m] [frontend.worker.rtc.client-op :as client-op] + [frontend.worker.rtc.db-listener] [frontend.worker.state :as worker-state] [helper] [missionary.core :as m])) @@ -42,6 +43,9 @@ (c.m/run-task-throw (m/sp (swap! worker-state/*datascript-conns dissoc const/downloaded-test-repo const/downloaded-test-repo2) + (swap! worker-state/*client-ops-conns assoc + const/downloaded-test-repo (d/create-conn client-op/schema-in-db) + const/downloaded-test-repo2 (d/create-conn client-op/schema-in-db)) (let [{:keys [graph-uuid]} (m/? helper/new-task--upload-example-graph)] (m/? (helper/new-task--wait-creating-graph graph-uuid)) (m/? (helper/new-task--download-graph graph-uuid const/downloaded-test-graph-name)) @@ -49,4 +53,5 @@ (done))) :build-two-conns-by-download-example-graph-fixture)) :after - #(swap! worker-state/*datascript-conns dissoc const/downloaded-test-repo const/downloaded-test-repo2)}) + #(do (swap! worker-state/*datascript-conns dissoc const/downloaded-test-repo const/downloaded-test-repo2) + (swap! worker-state/*client-ops-conns dissoc const/downloaded-test-repo const/downloaded-test-repo2))}) diff --git a/src/rtc_e2e_test/helper.cljs b/src/rtc_e2e_test/helper.cljs index 1a8a64b5f6..a0ed19f317 100644 --- a/src/rtc_e2e_test/helper.cljs +++ b/src/rtc_e2e_test/helper.cljs @@ -50,6 +50,10 @@ [] (worker-state/get-datascript-conn const/downloaded-test-repo)) +(defn get-downloaded-test-conn2 + [] + (worker-state/get-datascript-conn const/downloaded-test-repo2)) + (defn get-example-test-conn [] (worker-state/get-datascript-conn const/test-repo))