Skip to content

Commit 27f71ed

Browse files
committed
refactoring tests - wip
1 parent 169b1ac commit 27f71ed

File tree

2 files changed

+59
-46
lines changed

2 files changed

+59
-46
lines changed

src/test/clojure/com/github/clojure_lsp/intellij/foo_test.clj

+8-46
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,24 @@
11
(ns com.github.clojure-lsp.intellij.foo-test
22
(:require
3-
[clojure.java.io :as io]
43
[clojure.test :refer [deftest is]]
5-
[com.github.clojure-lsp.intellij.client :as lsp-client]
64
[com.github.clojure-lsp.intellij.db :as db]
75
[com.github.clojure-lsp.intellij.server :as server]
6+
[com.github.clojure-lsp.intellij.test-utils :as test-utils]
87
[com.github.ericdallo.clj4intellij.app-manager :as app-manager]
98
[com.github.ericdallo.clj4intellij.test :as clj4intellij.test])
109
(:import
11-
[com.github.clojure_lsp.intellij.extension SettingsState]
12-
[com.intellij.ide DataManager]
13-
[com.intellij.openapi.actionSystem ActionManager]
10+
[com.github.clojure_lsp.intellij.extension SettingsState]
1411
[com.intellij.openapi.components ServiceManager]
15-
[com.intellij.openapi.editor LogicalPosition]
16-
[com.intellij.openapi.wm WindowManager]))
12+
[com.intellij.openapi.editor LogicalPosition]))
1713

1814
(set! *warn-on-reflection* true)
1915

20-
(defn dispatch-all-until
21-
[{:keys [project millis timeout]
22-
:or {millis 1000
23-
timeout 10000}}]
24-
(let [start-time (System/currentTimeMillis)]
25-
(loop []
26-
(let [current-time (System/currentTimeMillis)
27-
elapsed-time (- current-time start-time)
28-
_ (println "Elapsed time >> "elapsed-time)
29-
status (lsp-client/server-status project)]
30-
(cond
31-
(>= elapsed-time timeout)
32-
(throw (ex-info "LSP server failed to start within timeout"
33-
{:elapsed-time elapsed-time
34-
:final-status status}))
35-
36-
(= status :started)
37-
true
38-
39-
:else
40-
(do
41-
(clj4intellij.test/dispatch-all)
42-
(Thread/sleep millis)
43-
(recur)))))))
4416

4517

46-
(defn get-status-bar-widget [project widget-id]
47-
(let [status-bar (.. (WindowManager/getInstance) (getStatusBar project))]
48-
(.getWidget status-bar widget-id)))
4918

50-
(defn run-editor-action [action-id project]
51-
(let [action (.getAction (ActionManager/getInstance) action-id)
52-
context (.getDataContext (DataManager/getInstance))]
53-
(println "Running action:" action-id)
54-
(app-manager/write-command-action
55-
project
56-
(fn []
57-
(.actionPerformed
58-
action
59-
(com.intellij.openapi.actionSystem.AnActionEvent/createFromDataContext action-id nil context))))))
19+
20+
21+
6022

6123

6224
(deftest foo-test
@@ -78,7 +40,7 @@
7840
(.loadState my-settings my-settings));; Atualiza estado
7941

8042
(clj4intellij.test/dispatch-all)
81-
(dispatch-all-until {:project project})
43+
(test-utils/dispatch-all-until {:project project})
8244
(println "status LSP >> " (db/get-in project [:status]))
8345
(let [editor (.getEditor fixture)
8446
document (.getDocument editor)
@@ -91,7 +53,7 @@
9153
{:invoke-fn (fn []
9254
#_(.moveToOffset caret (+ offset 9))
9355
(.moveToLogicalPosition caret new-position))}))
94-
(run-editor-action "ClojureLSP.ForwardSlurp" project)
56+
(test-utils/run-editor-action "ClojureLSP.ForwardSlurp" project)
9557
(clj4intellij.test/dispatch-all)
9658
(println (-> fixture .getEditor .getDocument .getText))
9759
(.checkResultByFile fixture "foo_expected.clj")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
(ns com.github.clojure-lsp.intellij.test-utils
2+
(:require
3+
[com.github.clojure-lsp.intellij.client :as lsp-client]
4+
[com.github.ericdallo.clj4intellij.app-manager :as app-manager]
5+
[com.github.ericdallo.clj4intellij.test :as clj4intellij.test])
6+
(:import
7+
[com.intellij.openapi.wm WindowManager]
8+
[com.intellij.ide DataManager]
9+
[com.intellij.openapi.actionSystem ActionManager]))
10+
11+
(set! *warn-on-reflection* true)
12+
13+
(defn get-status-bar-widget [project widget-id]
14+
(let [status-bar (.. (WindowManager/getInstance) (getStatusBar project))]
15+
(.getWidget status-bar widget-id)))
16+
17+
(defn run-editor-action [action-id project]
18+
(let [action (.getAction (ActionManager/getInstance) action-id)
19+
context (.getDataContext (DataManager/getInstance))]
20+
(println "Running action:" action-id)
21+
(app-manager/write-command-action
22+
project
23+
(fn []
24+
(.actionPerformed
25+
action
26+
(com.intellij.openapi.actionSystem.AnActionEvent/createFromDataContext action-id nil context))))))
27+
28+
(defn dispatch-all-until
29+
[{:keys [project millis timeout]
30+
:or {millis 1000
31+
timeout 10000}}]
32+
(let [start-time (System/currentTimeMillis)]
33+
(loop []
34+
(let [current-time (System/currentTimeMillis)
35+
elapsed-time (- current-time start-time)
36+
_ (println "Elapsed time >> " elapsed-time)
37+
status (lsp-client/server-status project)]
38+
(cond
39+
(>= elapsed-time timeout)
40+
(throw (ex-info "LSP server failed to start within timeout"
41+
{:elapsed-time elapsed-time
42+
:final-status status}))
43+
44+
(= status :started)
45+
true
46+
47+
:else
48+
(do
49+
(clj4intellij.test/dispatch-all)
50+
(Thread/sleep millis)
51+
(recur)))))))

0 commit comments

Comments
 (0)