mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 22:25:01 +00:00
test(e2e): open 2 instances, login, create rtc-graph
This commit is contained in:
4
clj-e2e/.cljfmt.edn
Normal file
4
clj-e2e/.cljfmt.edn
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{:extra-indents {missionary.core/sp [[:block 0]]
|
||||||
|
missionary.core/ap [[:block 0]]
|
||||||
|
frontend.common.missionary/run-task [[:inner 0]]}
|
||||||
|
:sort-ns-references? true}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
io.github.pfeodrippe/wally {:git/url "https://github.com/logseq/wally"
|
io.github.pfeodrippe/wally {:git/url "https://github.com/logseq/wally"
|
||||||
:sha "6b0583701fc64ec5177eec6577e33bb8d9115d61"}
|
:sha "6b0583701fc64ec5177eec6577e33bb8d9115d61"}
|
||||||
;; 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"}}
|
||||||
:aliases
|
:aliases
|
||||||
{:build {:deps {io.github.clojure/tools.build {:mvn/version "0.10.5"}}
|
{:build {:deps {io.github.clojure/tools.build {:mvn/version "0.10.5"}}
|
||||||
:ns-default build}
|
:ns-default build}
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
[clojure.test :refer [is]]
|
[clojure.test :refer [is]]
|
||||||
[wally.main :as w]
|
[wally.main :as w]
|
||||||
[wally.selectors :as ws])
|
[wally.selectors :as ws])
|
||||||
(:import (com.microsoft.playwright.assertions PlaywrightAssertions)))
|
(:import [com.microsoft.playwright.assertions PlaywrightAssertions]
|
||||||
|
[com.microsoft.playwright TimeoutError]))
|
||||||
|
|
||||||
(def assert-that PlaywrightAssertions/assertThat)
|
(def assert-that PlaywrightAssertions/assertThat)
|
||||||
|
|
||||||
@@ -39,6 +40,11 @@
|
|||||||
|
|
||||||
(def press w/keyboard-press)
|
(def press w/keyboard-press)
|
||||||
|
|
||||||
|
(defn cmdk
|
||||||
|
[input-text]
|
||||||
|
(press "Meta+k")
|
||||||
|
(input input-text))
|
||||||
|
|
||||||
(defn search
|
(defn search
|
||||||
[text]
|
[text]
|
||||||
(w/click :#search-button)
|
(w/click :#search-button)
|
||||||
@@ -147,3 +153,44 @@
|
|||||||
(def mac? (= "Mac OS X" (System/getProperty "os.name")))
|
(def mac? (= "Mac OS X" (System/getProperty "os.name")))
|
||||||
|
|
||||||
(def mod-key (if mac? "Meta" "Control"))
|
(def mod-key (if mac? "Meta" "Control"))
|
||||||
|
|
||||||
|
(defn login-test-account
|
||||||
|
[& {:keys [username password]
|
||||||
|
:or {username "e2etest"
|
||||||
|
password "Logseq-e2e"}}]
|
||||||
|
(w/eval-js "localStorage.setItem(\"login-enabled\",true);")
|
||||||
|
(w/click "button[title=\"More\"]")
|
||||||
|
(w/click "div:text(\"Login\")")
|
||||||
|
(input username)
|
||||||
|
(press "Tab")
|
||||||
|
(input password)
|
||||||
|
(w/click "button[type=\"submit\"]:text(\"Sign in\")")
|
||||||
|
(w/wait-for-not-visible ".cp__user-login"))
|
||||||
|
|
||||||
|
|
||||||
|
(defn new-graph
|
||||||
|
[graph-name enable-sync?]
|
||||||
|
(cmdk "add a db graph")
|
||||||
|
(w/click (w/get-by-label "Add a DB graph"))
|
||||||
|
(w/wait-for "h2:text(\"Create a new graph\")")
|
||||||
|
(w/click "input[placeholder=\"your graph name\"]")
|
||||||
|
(input graph-name)
|
||||||
|
(when enable-sync?
|
||||||
|
(w/click "button#rtc-sync"))
|
||||||
|
(w/click "button:text(\"Submit\")")
|
||||||
|
(when enable-sync?
|
||||||
|
(w/wait-for "button.cloud.on.idle" {:timeout 20000})))
|
||||||
|
|
||||||
|
|
||||||
|
(defn wait-for-remote-graph
|
||||||
|
[graph-name]
|
||||||
|
(cmdk "all graphs")
|
||||||
|
(w/click (w/get-by-label "Go to all graphs"))
|
||||||
|
(dotimes [i 5]
|
||||||
|
(prn :wait-for-remote-graph-try i)
|
||||||
|
(w/click "span:text(\"Refresh\")")
|
||||||
|
(try
|
||||||
|
(w/wait-for (str "span:has-text(\"" graph-name "\")"))
|
||||||
|
(catch TimeoutError e
|
||||||
|
(when (= 4 i)
|
||||||
|
(throw e))))))
|
||||||
|
|||||||
@@ -4,8 +4,9 @@
|
|||||||
;; TODO: save trace
|
;; TODO: save trace
|
||||||
;; TODO: parallel support
|
;; TODO: parallel support
|
||||||
(defn open-page
|
(defn open-page
|
||||||
[f & {:keys [headless]
|
[f & {:keys [headless port]
|
||||||
:or {headless true}}]
|
:or {headless true
|
||||||
|
port 3002}}]
|
||||||
(w/with-page-open
|
(w/with-page-open
|
||||||
(w/make-page {:headless headless
|
(w/make-page {:headless headless
|
||||||
:persistent false
|
:persistent false
|
||||||
@@ -13,5 +14,31 @@
|
|||||||
;; Set `slow-mo` lower to find more flaky tests
|
;; Set `slow-mo` lower to find more flaky tests
|
||||||
;; :slow-mo 30
|
;; :slow-mo 30
|
||||||
})
|
})
|
||||||
(w/navigate "http://localhost:3002")
|
(w/navigate (str "http://localhost:" port))
|
||||||
(f)))
|
(f)))
|
||||||
|
|
||||||
|
(def *page1 (atom nil))
|
||||||
|
(def *page2 (atom nil))
|
||||||
|
|
||||||
|
(defn open-2-pages
|
||||||
|
"Use `*page1` and `*page2` in `f`"
|
||||||
|
[f & {:keys [headless port]
|
||||||
|
:or {headless true
|
||||||
|
port 3002}}]
|
||||||
|
(let [p1 (w/make-page {:headless headless
|
||||||
|
:persistent false
|
||||||
|
:slow-mo 100})
|
||||||
|
p2 (w/make-page {:headless headless
|
||||||
|
:persistent false
|
||||||
|
:slow-mo 100})]
|
||||||
|
(run!
|
||||||
|
#(w/with-page %
|
||||||
|
(w/navigate (str "http://localhost:" port)))
|
||||||
|
[p1 p2])
|
||||||
|
|
||||||
|
(reset! *page1 p1)
|
||||||
|
(reset! *page2 p2)
|
||||||
|
(binding [w/*page* (delay (throw (ex-info "Don't use *page*, use *page1* and *page2* instead" {})))]
|
||||||
|
(f))
|
||||||
|
(w/with-page-open p1)
|
||||||
|
(w/with-page-open p2)))
|
||||||
|
|||||||
29
clj-e2e/test/logseq/e2e/rtc_basic_test.clj
Normal file
29
clj-e2e/test/logseq/e2e/rtc_basic_test.clj
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
(ns logseq.e2e.rtc-basic-test
|
||||||
|
(:require
|
||||||
|
[clojure.test :refer [deftest testing is use-fixtures]]
|
||||||
|
[com.climate.claypoole :as cp]
|
||||||
|
[logseq.e2e.fixtures :as fixtures :refer [*page1 *page2]]
|
||||||
|
[logseq.e2e.util :as util]
|
||||||
|
[wally.main :as w]
|
||||||
|
[wally.repl :as repl]))
|
||||||
|
|
||||||
|
(use-fixtures :once fixtures/open-2-pages)
|
||||||
|
|
||||||
|
;; (use-fixtures :once #(fixtures/open-2-pages % :headless false :port 3001))
|
||||||
|
|
||||||
|
(deftest rtc-basic-test
|
||||||
|
(let [graph-name (str "rtc-graph-" (.toEpochMilli (java.time.Instant/now)))]
|
||||||
|
(testing "open 2 app instances"
|
||||||
|
(cp/prun!
|
||||||
|
2
|
||||||
|
#(w/with-page %
|
||||||
|
(util/login-test-account))
|
||||||
|
[@*page1 @*page2])
|
||||||
|
(w/with-page @*page1
|
||||||
|
(util/new-graph graph-name true))
|
||||||
|
(w/with-page @*page2
|
||||||
|
(util/wait-for-remote-graph graph-name)))))
|
||||||
|
|
||||||
|
(comment
|
||||||
|
(def xxx (future (clojure.test/run-tests)))
|
||||||
|
(future-cancel xxx))
|
||||||
Reference in New Issue
Block a user