|
1 | 1 | (ns frontend.handler.editor-test |
2 | | - (:require [clojure.test :refer [deftest is testing use-fixtures]] |
| 2 | + (:require [clojure.test :refer [async deftest is testing use-fixtures]] |
3 | 3 | [frontend.commands :as commands] |
| 4 | + [frontend.components.editor :as editor-component] |
4 | 5 | [frontend.db :as db] |
| 6 | + [frontend.db.async :as db-async] |
5 | 7 | [frontend.db.model :as model] |
6 | 8 | [frontend.handler.editor :as editor] |
7 | 9 | [frontend.state :as state] |
8 | 10 | [frontend.test.helper :as test-helper] |
9 | 11 | [frontend.util :as util] |
10 | 12 | [frontend.util.cursor :as cursor] |
11 | 13 | [goog.dom :as gdom] |
12 | | - [logseq.outliner.core :as outliner-core])) |
| 14 | + [logseq.outliner.core :as outliner-core] |
| 15 | + [promesa.core :as p])) |
13 | 16 |
|
14 | | -(use-fixtures :each test-helper/start-and-destroy-db) |
| 17 | +(use-fixtures :each {:before test-helper/start-test-db! |
| 18 | + :after (fn [] |
| 19 | + (state/set-current-repo! nil) |
| 20 | + (test-helper/destroy-test-db!))}) |
15 | 21 |
|
16 | 22 | (deftest extract-nearest-link-from-text-test |
17 | 23 | (testing "Page, block and tag links" |
|
122 | 128 | ;; Reset state |
123 | 129 | (state/set-editor-action! nil)) |
124 | 130 |
|
125 | | -(deftest get-matched-classes-excludes-class-aliases |
| 131 | +(defn- create-tag-with-alias! |
| 132 | + [] |
126 | 133 | (test-helper/create-page! "Project Tag" :redirect? false :class? true) |
127 | 134 | (test-helper/create-page! "Alias Only" :redirect? false) |
128 | 135 | (let [class (db/get-case-page "Project Tag") |
129 | 136 | alias (db/get-case-page "Alias Only")] |
130 | 137 | (db/transact! test-helper/test-db [{:db/id (:db/id class) |
131 | | - :block/alias #{(:db/id alias)}}])) |
| 138 | + :block/alias #{(:db/id alias)}}]))) |
| 139 | + |
| 140 | +(deftest get-matched-classes-includes-class-aliases |
| 141 | + (create-tag-with-alias!) |
132 | 142 | (is (= ["Project Tag"] |
133 | 143 | (map :block/title (editor/get-matched-classes "Project Tag"))) |
134 | 144 | "Existing tag title matching still works") |
135 | | - (is (empty? (filter #(= "Alias Only" (:block/title %)) |
136 | | - (editor/get-matched-classes "Alias Only"))) |
137 | | - "Tag aliases are not separate tag completion choices")) |
| 145 | + (is (= ["Alias Only"] |
| 146 | + (map :block/title (editor/get-matched-classes "Alias Only"))) |
| 147 | + "Tag aliases stay available as tag completion choices")) |
| 148 | + |
| 149 | +(deftest tag-search-does-not-convert-class-aliases |
| 150 | + (async done |
| 151 | + (create-tag-with-alias!) |
| 152 | + (let [matched-pages (atom nil)] |
| 153 | + (-> (p/with-redefs [db-async/<get-block (fn [_repo _title _opts] |
| 154 | + (p/resolved (db/get-page "Alias Only")))] |
| 155 | + (#'editor-component/search-pages "Alias Only" true #(reset! matched-pages %))) |
| 156 | + (.then |
| 157 | + (fn [] |
| 158 | + (is (some #(= "Alias Only" (:block/title %)) @matched-pages) |
| 159 | + "The alias is still selectable from tag completion") |
| 160 | + (is (not-any? :convert-page-to-tag? @matched-pages) |
| 161 | + "A class alias must not show a redundant Convert action") |
| 162 | + (done))))))) |
138 | 163 |
|
139 | 164 | (defn- default-keyup-result |
140 | 165 | [{:keys [value cursor-pos key code action is-processed?] |
|
0 commit comments