commands_test.clj 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. (ns logseq.e2e.commands-test
  2. (:require
  3. [clojure.string :as string]
  4. [clojure.test :refer [deftest testing is use-fixtures]]
  5. [logseq.e2e.block :as b]
  6. [logseq.e2e.fixtures :as fixtures]
  7. [logseq.e2e.keyboard :as k]
  8. [logseq.e2e.util :as util]
  9. [wally.main :as w]))
  10. (use-fixtures :once fixtures/open-page)
  11. (use-fixtures :each fixtures/new-logseq-page)
  12. (deftest command-trigger-test
  13. (testing "/command trigger popup"
  14. (b/new-block "b2")
  15. (util/type " /")
  16. (w/wait-for ".ui__popover-content")
  17. (is (some? (w/find-one-by-text "span" "Node reference")))
  18. (k/backspace)
  19. (w/wait-for-not-visible ".ui__popover-content")))
  20. (defn- input-command
  21. [command-match]
  22. (util/type "/")
  23. (util/type command-match)
  24. (w/wait-for ".ui__popover-content")
  25. (k/enter))
  26. (deftest node-reference-test
  27. (testing "Node reference"
  28. (testing "Page reference"
  29. (b/new-blocks ["b1" ""])
  30. (input-command "Node eferen")
  31. (util/type "Another page")
  32. (k/enter)
  33. (is (= "[[Another page]]" (util/get-edit-content)))
  34. (util/exit-edit)
  35. (is (= "Another page" (util/get-text "a.page-ref"))))
  36. (testing "Block reference"
  37. (b/new-block "")
  38. (input-command "Node eferen")
  39. (util/type "b1")
  40. (util/wait-timeout 300)
  41. (k/enter)
  42. (is (string/includes? (util/get-edit-content) "[["))
  43. (util/exit-edit)
  44. (is (= "b1" (util/get-text ".block-ref"))))))
  45. (deftest link-test
  46. (testing "/link"
  47. (let [add-logseq-link (fn []
  48. (util/type "https://logseq.com")
  49. (k/tab)
  50. (util/type "Logseq")
  51. (k/tab)
  52. (k/enter))]
  53. (b/new-block "")
  54. (input-command "link")
  55. (add-logseq-link)
  56. (is (= "[Logseq](https://logseq.com)" (util/get-edit-content)))
  57. (util/type " some content ")
  58. (input-command "link")
  59. (add-logseq-link)
  60. (is (= (str "[Logseq](https://logseq.com)"
  61. " some content "
  62. "[Logseq](https://logseq.com)") (util/get-edit-content))))))
  63. (deftest link-image-test
  64. (testing "/image link"
  65. (b/new-block "")
  66. (input-command "image link")
  67. (util/type "https://logseq.com/test.png")
  68. (k/tab)
  69. (util/type "Logseq")
  70. (k/tab)
  71. (k/enter)
  72. (is (= "![Logseq](https://logseq.com/test.png)" (util/get-edit-content)))))
  73. (deftest underline-test
  74. (testing "/underline"
  75. (b/new-block "")
  76. (input-command "underline")
  77. (is (= "<ins></ins>" (util/get-edit-content)))
  78. (util/type "test")
  79. (is (= "<ins>test</ins>" (util/get-edit-content)))
  80. (util/move-cursor-to-end)))
  81. (deftest code-block-test
  82. (testing "/code block"
  83. (b/new-block "")
  84. (input-command "code block")
  85. (w/wait-for ".CodeMirror")
  86. (util/wait-timeout 100)
  87. ;; create another block
  88. (k/shift+enter)))
  89. (deftest math-block-test
  90. (testing "/math block"
  91. (b/new-block "")
  92. (input-command "math block")
  93. (util/type "1 + 2 = 3")
  94. (util/exit-edit)
  95. (w/wait-for ".katex")))
  96. (deftest quote-test
  97. (testing "/quote"
  98. (b/new-block "")
  99. (input-command "quote")
  100. (w/wait-for "div[data-node-type='quote']")))
  101. (deftest headings-test
  102. (testing "/heading"
  103. (dotimes [i 6]
  104. (let [heading (str "h" (inc i))
  105. text (str heading " test ")]
  106. (b/new-block text)
  107. (input-command heading)
  108. (is (= text (util/get-edit-content)))
  109. (util/exit-edit)
  110. (w/wait-for heading)))))
  111. (deftest status-test
  112. (testing "task status commands"
  113. (let [status->icon {"Doing" "InProgress50"
  114. "In review" "InReview"
  115. "Canceled" "Cancelled"}]
  116. (doseq [status ["Backlog" "Todo" "Doing" "In review" "Done" "Canceled"]]
  117. (let [text (str status " test ")]
  118. (b/new-block text)
  119. (input-command status)
  120. (is (= text (util/get-edit-content)))
  121. (util/exit-edit)
  122. (w/wait-for (str ".ls-icon-" (get status->icon status status))))))))
  123. (deftest priority-test
  124. (testing "task priority commands"
  125. (let [priority->icon {"No priority" "line-dashed"}]
  126. (doseq [priority ["No priority" "Low" "Medium" "High" "Urgent"]]
  127. (let [text (str priority " test ")]
  128. (b/new-block text)
  129. (input-command priority)
  130. (is (= text (util/get-edit-content)))
  131. (util/exit-edit)
  132. (w/wait-for (str ".ls-icon-" (get priority->icon priority
  133. (str "priorityLvl" priority)))))))))
  134. (deftest scheduled-deadline-test
  135. (testing "task scheduled and deadline commands"
  136. (doseq [command ["Scheduled" "Deadline"]]
  137. (fixtures/create-page)
  138. (let [text (str command " test ")]
  139. (b/new-block text)
  140. (input-command command)
  141. (k/enter)
  142. (k/esc)
  143. (util/exit-edit)
  144. (is (= command (util/get-text ".property-k")))
  145. (is (= "Today" (util/get-text ".ls-datetime a.page-ref")))))))