Просмотр исходного кода

test(e2e): update multi-tabs-test

rcmerci 8 месяцев назад
Родитель
Сommit
f3e0036f42

+ 9 - 3
clj-e2e/src/logseq/e2e/block.clj

@@ -1,9 +1,9 @@
 (ns logseq.e2e.block
-  (:require [logseq.e2e.assert :as assert]
+  (:require [clojure.string :as string]
+            [logseq.e2e.assert :as assert]
             [logseq.e2e.keyboard :as k]
             [logseq.e2e.util :as util]
-            [wally.main :as w]
-            [clojure.string :as string]))
+            [wally.main :as w]))
 
 (defn open-last-block
   []
@@ -39,3 +39,9 @@
           (new-block title)))
       (doseq [title titles]
         (new-block title)))))
+
+(defn assert-blocks-visible
+  "blocks - coll of :block/title"
+  [blocks]
+  (doseq [block blocks]
+    (assert/assert-is-visible (format ".ls-page-blocks .ls-block :text('%s')" block))))

+ 2 - 4
clj-e2e/src/logseq/e2e/graph.clj

@@ -9,13 +9,11 @@
 
 (defn goto-all-graphs
   []
-  (util/search "go to all graphs")
-  (w/click (w/get-by-label "Go to all graphs")))
+  (util/search-and-click "Go to all graphs"))
 
 (defn new-graph
   [graph-name enable-sync?]
-  (util/search "add a db graph")
-  (w/click (w/get-by-label "Add a DB graph"))
+  (util/search-and-click "Add a DB graph")
   (w/wait-for "h2:text(\"Create a new graph\")")
   (w/click "input[placeholder=\"your graph name\"]")
   (util/input graph-name)

+ 9 - 0
clj-e2e/src/logseq/e2e/util.clj

@@ -64,6 +64,11 @@
   (w/click :#search-button)
   (w/fill ".cp__cmdk-search-input" text))
 
+(defn search-and-click
+  [search-text]
+  (search search-text)
+  (w/click (w/get-by-label search-text)))
+
 (defn new-page
   [title]
   ;; Question: what's the best way to close all the popups?
@@ -147,3 +152,7 @@
   (input password)
   (w/click "button[type=\"submit\"]:text(\"Sign in\")")
   (w/wait-for-not-visible ".cp__user-login"))
+
+(defn goto-journals
+  []
+  (search-and-click "Go to journals"))

+ 47 - 28
clj-e2e/test/logseq/e2e/multi_tabs_test.clj

@@ -1,26 +1,24 @@
 (ns logseq.e2e.multi-tabs-test
-  (:require
-   [clojure.test :refer [deftest testing is use-fixtures]]
-   [com.climate.claypoole :as cp]
-   [logseq.e2e.block :as b]
-   [logseq.e2e.fixtures :as fixtures]
-   [logseq.e2e.playwright-page :as pw-page]
-   [logseq.e2e.util :as util]
-   [wally.main :as w]
-   [wally.repl :as repl]))
+  (:require [clojure.test :refer [deftest is testing use-fixtures]]
+            [logseq.e2e.assert :as assert]
+            [logseq.e2e.block :as b]
+            [logseq.e2e.fixtures :as fixtures]
+            [logseq.e2e.graph :as graph]
+            [logseq.e2e.playwright-page :as pw-page]
+            [logseq.e2e.util :as util]
+            [wally.main :as w]
+            [wally.repl :as repl]))
 
 (use-fixtures :once fixtures/open-new-context)
 
 (defn- add-blocks-and-check-on-other-tabs
   [new-blocks add-blocks-tab check-blocks-tabs]
-  (let [new-blocks-count (count new-blocks)]
-    (w/with-page add-blocks-tab
-      (b/new-blocks new-blocks))
-    (cp/prun!
-     (count check-blocks-tabs)
-     #(w/with-page %
-        (is (= (util/page-blocks-count) new-blocks-count)))
-     check-blocks-tabs)))
+  (w/with-page add-blocks-tab
+    (b/new-blocks new-blocks))
+  (run!
+   #(w/with-page %
+      (b/assert-blocks-visible new-blocks))
+   check-blocks-tabs))
 
 (deftest multi-tabs-test
   (testing "edit on one tab, check all tab's blocks are same"
@@ -28,15 +26,36 @@
     (let [[p1 p2 p3 :as pages] (pw-page/get-pages fixtures/*pw-ctx*)
           blocks-to-add (map #(str "b" %) (range 10))]
       (is (= 3 (count pages)))
-      (w/with-page p1
-        (b/new-blocks blocks-to-add))
-      (w/with-page p2
-        (is (= (util/page-blocks-count) (count blocks-to-add))))
-      (w/with-page p3
-        (is (= (util/page-blocks-count) (count blocks-to-add))))))
+      (add-blocks-and-check-on-other-tabs blocks-to-add p1 [p2 p3])))
 
-  ;; (testing "add new graphs, and do switching graphs on tabs"
-  ;;   (let [[p1 p2 p3 :as pages] (pw-page/get-pages fixtures/*pw-ctx*)]
-  ;;     (w/with-page p1
-  ;;       (repl/pause))))
-  )
+  (comment
+    ;; this test is failing, produce err:
+    ;;Error caught by UI!
+    ;;Error: Assert failed: (db/db? db)
+    ;; ...
+    (testing "add new graphs, and do switching graphs on tabs"
+      (let [[p1 p2 p3 :as pages] (pw-page/get-pages fixtures/*pw-ctx*)]
+        (w/with-page p1
+          (graph/new-graph "graph1" false)
+          (graph/new-graph "graph2" false)
+          (graph/new-graph "graph3" false))
+        (w/with-page p2
+          ;; FIXME: since all-graphs isn't auto-update when other tabs add new graphs, so refresh here
+          (w/refresh)
+          (util/goto-journals)
+          (assert/assert-in-normal-mode?)
+          (graph/switch-graph "graph1"))
+        (w/with-page p3
+          ;; FIXME: since all-graphs isn't auto-update when other tabs add new graphs, so refresh here
+          (w/refresh)
+          (util/goto-journals)
+          (assert/assert-in-normal-mode?)
+          (graph/switch-graph "graph1"))
+        (w/with-page p1
+          (util/goto-journals)
+          (assert/assert-in-normal-mode?)
+          (graph/switch-graph "graph1"))
+        (let [graph1-new-blocks1 (map #(str "graph1-b1-" %) (range 5))
+              graph1-new-blocks2 (map #(str "graph1-b2-" %) (range 5))
+              graph1-new-blocks3 (map #(str "graph1-b3-" %) (range 5))]
+          (add-blocks-and-check-on-other-tabs graph1-new-blocks1 p1 [p2 p3]))))))