Explorar o código

test(e2e,rtc): add rtc/with-stop-restart-rtc

rcmerci hai 5 meses
pai
achega
d9d2a4c903
Modificáronse 2 ficheiros con 44 adicións e 26 borrados
  1. 18 0
      clj-e2e/src/logseq/e2e/rtc.clj
  2. 26 26
      clj-e2e/test/logseq/e2e/rtc_extra_test.clj

+ 18 - 0
clj-e2e/src/logseq/e2e/rtc.clj

@@ -54,3 +54,21 @@
 (defn rtc-stop
   []
   (util/search-and-click "(Dev) RTC Stop"))
+
+(defmacro with-stop-restart-rtc
+  "- rtc stop on `stop-pw-pages` in order
+  - run `body`
+  - rtc start and exec `after-start-body` in order"
+  [stop-pw-pages start-pw-page+after-start-body & body]
+  (let [after-body
+        (cons
+         'do
+         (for [[p body] (partition 2 start-pw-page+after-start-body)]
+           `(w/with-page ~p
+              (rtc-start)
+              ~body)))]
+    `(do
+       (doseq [p# ~stop-pw-pages]
+         (w/with-page p# (rtc-stop)))
+       ~@body
+       ~after-body)))

+ 26 - 26
clj-e2e/test/logseq/e2e/rtc_extra_test.clj

@@ -145,17 +145,19 @@
               (reset! *latest-remote-tx remote-tx))))]
     (testing "add some task blocks while rtc disconnected on page1"
       (let [*latest-remote-tx (atom nil)]
-        (with-stop-restart-rtc @*page1 #(insert-task-blocks-in-page2 *latest-remote-tx))
-        (w/with-page @*page1
-          (rtc/wait-tx-update-to @*latest-remote-tx))
+        (rtc/with-stop-restart-rtc
+          [@*page1]
+          [@*page1 (rtc/wait-tx-update-to @*latest-remote-tx)]
+          (insert-task-blocks-in-page2 *latest-remote-tx))
         (validate-task-blocks)
         (validate-2-graphs)))
 
     (testing "update task blocks while rtc disconnected on page1"
       (let [*latest-remote-tx (atom nil)]
-        (with-stop-restart-rtc @*page1 #(update-task-blocks-in-page2 *latest-remote-tx))
-        (w/with-page @*page1
-          (rtc/wait-tx-update-to @*latest-remote-tx))
+        (rtc/with-stop-restart-rtc
+          [@*page1]
+          [@*page1 (rtc/wait-tx-update-to @*latest-remote-tx)]
+          (update-task-blocks-in-page2 *latest-remote-tx))
         (validate-task-blocks)
         (validate-2-graphs)))
 
@@ -187,9 +189,10 @@
               (reset! *latest-remote-tx remote-tx))))]
     (testing "add different types user properties on page2 while keeping rtc connected on page1"
       (let [*latest-remote-tx (atom nil)]
-        (with-stop-restart-rtc @*page1 #(insert-new-property-blocks-in-page2 *latest-remote-tx "rtc-property-test-1"))
-        (w/with-page @*page1
-          (rtc/wait-tx-update-to @*latest-remote-tx))
+        (rtc/with-stop-restart-rtc
+          [@*page1]
+          [@*page1 (rtc/wait-tx-update-to @*latest-remote-tx)]
+          (insert-new-property-blocks-in-page2 *latest-remote-tx "rtc-property-test-1"))
         (validate-2-graphs)))
 
     (new-logseq-page)
@@ -225,9 +228,10 @@
       ;; testing while rtc off then on
       (let [*latest-remote-tx (atom nil)]
         (new-logseq-page)
-        (with-stop-restart-rtc @*page1 #(test-fn-in-page2 *latest-remote-tx))
-        (w/with-page @*page1
-          (rtc/wait-tx-update-to @*latest-remote-tx))
+        (rtc/with-stop-restart-rtc
+          [@*page1]
+          [@*page1 (rtc/wait-tx-update-to @*latest-remote-tx)]
+          (test-fn-in-page2 *latest-remote-tx))
         (validate-2-graphs)))))
 
 (deftest rtc-outliner-conflict-update-test
@@ -243,20 +247,16 @@
           (rtc/wait-tx-update-to @*latest-remote-tx))
         (validate-2-graphs)))
     (testing "disconnect on page1 and page2, do some conflict updates, reconnect and check"
-      (w/with-page @*page1 (rtc/rtc-stop))
-      (w/with-page @*page2 (rtc/rtc-stop))
-
-      ;; TODO: more updates
-      (w/with-page @*page1
-        (w/click (format ".ls-block :text('%s')" (str title-prefix "-" 1)))
-        (b/indent))
-      (w/with-page @*page2
-        (w/click (format ".ls-block :text('%s')" (str title-prefix "-" 0)))
-        (b/delete-blocks))
-      (w/with-page @*page1 (rtc/rtc-start))
-      (w/with-page @*page2 (rtc/rtc-start))
-      (w/with-page @*page1 (rtc/with-wait-tx-updated (b/new-block "xxxx")))
-      (w/with-page @*page2 (rtc/with-wait-tx-updated (b/new-block "yyyy")))
+      (rtc/with-stop-restart-rtc
+        [@*page1 @*page2]
+        [@*page1 (rtc/with-wait-tx-updated (b/new-block "xxxx"))
+         @*page2 (rtc/with-wait-tx-updated (b/new-block "yyyy"))]
+        (w/with-page @*page1
+          (w/click (format ".ls-block :text('%s')" (str title-prefix "-" 1)))
+          (b/indent))
+        (w/with-page @*page2
+          (w/click (format ".ls-block :text('%s')" (str title-prefix "-" 0)))
+          (b/delete-blocks)))
       (validate-2-graphs))))
 
 (comment