Browse Source

add block references test

Tienson Qin 5 months ago
parent
commit
3a1af91b3f

+ 3 - 3
clj-e2e/deps.edn

@@ -1,8 +1,8 @@
 {:paths ["src" "resources"]
 {:paths ["src" "resources"]
  :deps {org.clojure/clojure {:mvn/version "1.12.0"}
  :deps {org.clojure/clojure {:mvn/version "1.12.0"}
-        ;; io.github.pfeodrippe/wally {:local/root "../../../wally"}
-        io.github.pfeodrippe/wally {:git/url "https://github.com/logseq/wally"
-                                    :sha "80ea665c75704a8ca80cb22caeaec3ae6f39ffdb"}
+        io.github.pfeodrippe/wally {:local/root "../../../wally"}
+        ;; io.github.pfeodrippe/wally {:git/url "https://github.com/logseq/wally"
+        ;;                             :sha "0b8d376a3b806969dbede7ba63b7bf7efa47295b"}
         ;; io.github.zmedelis/bosquet {:mvn/version "2025.03.28"}
         ;; io.github.zmedelis/bosquet {:mvn/version "2025.03.28"}
         org.clj-commons/claypoole          {:mvn/version "1.2.2"}
         org.clj-commons/claypoole          {:mvn/version "1.2.2"}
         clj-time/clj-time                  {:mvn/version "0.15.2"}}
         clj-time/clj-time                  {:mvn/version "0.15.2"}}

+ 8 - 2
clj-e2e/dev/user.clj

@@ -10,6 +10,7 @@
             [logseq.e2e.multi-tabs-test]
             [logseq.e2e.multi-tabs-test]
             [logseq.e2e.outliner-test]
             [logseq.e2e.outliner-test]
             [logseq.e2e.plugins-test]
             [logseq.e2e.plugins-test]
+            [logseq.e2e.reference-test]
             [logseq.e2e.rtc-basic-test]
             [logseq.e2e.rtc-basic-test]
             [logseq.e2e.util :as util]
             [logseq.e2e.util :as util]
             [wally.main :as w]
             [wally.main :as w]
@@ -48,6 +49,11 @@
   (->> (future (run-tests 'logseq.e2e.multi-tabs-test))
   (->> (future (run-tests 'logseq.e2e.multi-tabs-test))
        (swap! *futures assoc :multi-tabs-test)))
        (swap! *futures assoc :multi-tabs-test)))
 
 
+(defn run-reference-test
+  []
+  (->> (future (run-tests 'logseq.e2e.reference-test))
+       (swap! *futures assoc :reference-test)))
+
 (defn run-plugins-test
 (defn run-plugins-test
   []
   []
   (->> (future (run-tests 'logseq.e2e.plugins-test))
   (->> (future (run-tests 'logseq.e2e.plugins-test))
@@ -93,8 +99,8 @@
   (do
   (do
     (reset! config/*headless true)
     (reset! config/*headless true)
     (reset! config/*slow-mo 10)
     (reset! config/*slow-mo 10)
-    (dotimes [i 5]
-      (run-multi-tabs-test)))
+    (dotimes [i 10]
+      (run-tests 'logseq.e2e.reference-test)))
 
 
   ;;
   ;;
   )
   )

+ 9 - 1
clj-e2e/src/logseq/e2e/assert.clj

@@ -14,12 +14,16 @@
   (-> (w/-query q) assert-that .isHidden)
   (-> (w/-query q) assert-that .isHidden)
   true)
   true)
 
 
+(defn assert-non-editor-mode
+  []
+  (assert-is-hidden (w/get-by-test-id "block editor")))
+
 (defn assert-in-normal-mode?
 (defn assert-in-normal-mode?
   "- not editing mode
   "- not editing mode
   - no action bar
   - no action bar
   - no search(cmdk) modal"
   - no search(cmdk) modal"
   []
   []
-  (assert-is-hidden (w/get-by-test-id "block editor"))
+  (assert-non-editor-mode)
   (assert-is-hidden ".selection-action-bar")
   (assert-is-hidden ".selection-action-bar")
   (assert-is-visible "#search-button")
   (assert-is-visible "#search-button")
   true)
   true)
@@ -39,3 +43,7 @@
         editor (w/-query klass)]
         editor (w/-query klass)]
     (w/wait-for editor)
     (w/wait-for editor)
     editor))
     editor))
+
+(defn assert-selected-block-text
+  [text]
+  (assert-is-visible (format ".ls-block.selected :text('%s')" text)))

+ 26 - 0
clj-e2e/src/logseq/e2e/block.clj

@@ -1,5 +1,6 @@
 (ns logseq.e2e.block
 (ns logseq.e2e.block
   (:require [clojure.string :as string]
   (:require [clojure.string :as string]
+            [clojure.test :refer [is]]
             [logseq.e2e.assert :as assert]
             [logseq.e2e.assert :as assert]
             [logseq.e2e.keyboard :as k]
             [logseq.e2e.keyboard :as k]
             [logseq.e2e.locator :as loc]
             [logseq.e2e.locator :as loc]
@@ -57,3 +58,28 @@
 (defn jump-to-block
 (defn jump-to-block
   [block-text]
   [block-text]
   (w/click (w/find-one-by-text ".ls-block .block-content" block-text)))
   (w/click (w/find-one-by-text ".ls-block .block-content" block-text)))
+
+(defn wait-editor-text
+  [text]
+  (w/wait-for (format ".editor-wrapper textarea:text('%s')" text)))
+
+(def copy #(k/press "ControlOrMeta+c" {:delay 100}))
+(def paste #(k/press "ControlOrMeta+v" {:delay 100}))
+
+(defn- indent-outdent
+  [indent?]
+  (let [editor (util/get-editor)
+        [x1 _] (util/bounding-xy editor)
+        _ (if indent? (k/tab) (k/shift+tab))
+        [x2 _] (util/bounding-xy editor)]
+    (if indent?
+      (is (< x1 x2))
+      (is (> x1 x2)))))
+
+(defn indent
+  []
+  (indent-outdent true))
+
+(defn outdent
+  []
+  (indent-outdent false))

+ 2 - 19
clj-e2e/src/logseq/e2e/util.clj

@@ -104,7 +104,8 @@
 
 
 (defn exit-edit
 (defn exit-edit
   []
   []
-  (k/esc))
+  (k/esc)
+  (assert/assert-non-editor-mode))
 
 
 (defn get-text
 (defn get-text
   [locator]
   [locator]
@@ -122,24 +123,6 @@
   (let [box (.boundingBox locator)]
   (let [box (.boundingBox locator)]
     [(.-x box) (.-y box)]))
     [(.-x box) (.-y box)]))
 
 
-(defn indent-outdent
-  [indent?]
-  (let [editor (get-editor)
-        [x1 _] (bounding-xy editor)
-        _ (if indent? (k/tab) (k/shift+tab))
-        [x2 _] (bounding-xy editor)]
-    (if indent?
-      (is (< x1 x2))
-      (is (> x1 x2)))))
-
-(defn indent
-  []
-  (indent-outdent true))
-
-(defn outdent
-  []
-  (indent-outdent false))
-
 (defn repeat-keyboard
 (defn repeat-keyboard
   [n shortcut]
   [n shortcut]
   (dotimes [_i n]
   (dotimes [_i n]

+ 8 - 8
clj-e2e/test/logseq/e2e/outliner_test.clj

@@ -20,14 +20,14 @@
 (deftest indent-and-outdent-test
 (deftest indent-and-outdent-test
   (b/new-blocks ["b1" "b2"])
   (b/new-blocks ["b1" "b2"])
   (testing "simple indent and outdent"
   (testing "simple indent and outdent"
-    (util/indent)
-    (util/outdent))
+    (b/indent)
+    (b/outdent))
 
 
   (testing "indent a block with its children"
   (testing "indent a block with its children"
     (b/new-block "b3")
     (b/new-block "b3")
-    (util/indent)
+    (b/indent)
     (k/arrow-up)
     (k/arrow-up)
-    (util/indent)
+    (b/indent)
     (util/exit-edit)
     (util/exit-edit)
     (let [[x1 x2 x3] (map (comp first util/bounding-xy #(w/find-one-by-text "span" %)) ["b1" "b2" "b3"])]
     (let [[x1 x2 x3] (map (comp first util/bounding-xy #(w/find-one-by-text "span" %)) ["b1" "b2" "b3"])]
       (is (< x1 x2 x3))))
       (is (< x1 x2 x3))))
@@ -35,9 +35,9 @@
   (testing "unindent a block with its children"
   (testing "unindent a block with its children"
     (b/open-last-block)
     (b/open-last-block)
     (b/new-blocks ["b4" "b5"])
     (b/new-blocks ["b4" "b5"])
-    (util/indent)
+    (b/indent)
     (k/arrow-up)
     (k/arrow-up)
-    (util/outdent)
+    (b/outdent)
     (util/exit-edit)
     (util/exit-edit)
     (let [[x2 x3 x4 x5] (map (comp first util/bounding-xy #(w/find-one-by-text "span" %)) ["b2" "b3" "b4" "b5"])]
     (let [[x2 x3 x4 x5] (map (comp first util/bounding-xy #(w/find-one-by-text "span" %)) ["b2" "b3" "b4" "b5"])]
       (is (and (= x2 x4) (= x3 x5) (< x2 x3))))))
       (is (and (= x2 x4) (= x3 x5) (< x2 x3))))))
@@ -66,9 +66,9 @@
 (deftest delete-test-with-children
 (deftest delete-test-with-children
   (testing "Delete block with its children"
   (testing "Delete block with its children"
     (b/new-blocks ["b1" "b2" "b3" "b4"])
     (b/new-blocks ["b1" "b2" "b3" "b4"])
-    (util/indent)
+    (b/indent)
     (k/arrow-up)
     (k/arrow-up)
-    (util/indent)
+    (b/indent)
     (k/arrow-up)
     (k/arrow-up)
     (b/delete-blocks)
     (b/delete-blocks)
     (is (= "b1" (util/get-edit-content)))
     (is (= "b1" (util/get-edit-content)))

+ 73 - 0
clj-e2e/test/logseq/e2e/reference_test.clj

@@ -0,0 +1,73 @@
+(ns logseq.e2e.reference-test
+  (:require
+   [clojure.test :refer [deftest testing is use-fixtures]]
+   [logseq.e2e.assert :as assert]
+   [logseq.e2e.block :as b]
+   [logseq.e2e.fixtures :as fixtures]
+   [logseq.e2e.keyboard :as k]
+   [logseq.e2e.util :as util]
+   [wally.repl :as repl]))
+
+(use-fixtures :once fixtures/open-page)
+
+(use-fixtures :each fixtures/new-logseq-page)
+
+;; block references
+(deftest self-reference
+  (testing "self reference"
+    (b/new-block "b2")
+    (b/copy)
+    (b/paste)
+    (util/exit-edit)
+    (assert/assert-selected-block-text "b2b2")))
+
+(deftest mutual-reference
+  (testing "mutual reference"
+    (b/new-blocks ["b1" "b2"])
+    (b/copy)
+    (k/arrow-up)
+    (b/wait-editor-text "b1")
+    (b/paste)
+    (b/copy)
+    (k/arrow-down)
+    (b/wait-editor-text "b2")
+    (b/paste)
+    (util/exit-edit)
+    (b/assert-blocks-visible ["b1b2" "b2b1"])))
+
+(deftest parent-reference
+  (testing "parent reference"
+    (b/new-blocks ["b1" "b2"])
+    (b/indent)
+    (b/copy)
+    (k/arrow-up)
+    (b/wait-editor-text "b1")
+    (b/paste)
+    (b/copy)
+    (k/arrow-down)
+    (b/wait-editor-text "b2")
+    (b/paste)
+    (util/exit-edit)
+    (b/assert-blocks-visible ["b1b2" "b2b1"])))
+
+(deftest cycle-reference
+  (testing "cycle reference"
+    (b/new-blocks ["b1" "b2" "b3"])
+    (b/jump-to-block "b1")
+    (assert/assert-editor-mode)
+    (b/copy)
+    (k/arrow-down)
+    (b/wait-editor-text "b2")
+    (b/paste)
+    (b/copy)
+    (k/arrow-down)
+    (b/wait-editor-text "b3")
+    (b/paste)
+    (b/copy)
+    (b/jump-to-block "b1")
+    (assert/assert-editor-mode)
+    (b/paste)
+    (util/exit-edit)
+    (b/assert-blocks-visible ["b1b3b2" "b2b1b3" "b3b2b1"])))
+
+;; TODO: page references