|
|
@@ -47,31 +47,50 @@
|
|
|
|
|
|
(defn- keydown-not-matched-handler
|
|
|
"Spied version of editor/keydown-not-matched-handler"
|
|
|
- [{:keys [value key format] :or {format "markdown"}}]
|
|
|
- (with-redefs [util/get-selected-text (constantly false)
|
|
|
- state/get-input (constantly #js {:value value})
|
|
|
- cursor/get-caret-pos (constantly {})]
|
|
|
- ((editor/keydown-not-matched-handler format)
|
|
|
- #js {:key key} nil)))
|
|
|
+ [{:keys [value key format cursor-pos] :or {key "#" format "markdown"}}]
|
|
|
+ ;; Reset editor action in order to test result
|
|
|
+ (state/set-editor-action! nil)
|
|
|
+ ;; Default cursor pos to end of line
|
|
|
+ (let [pos (or cursor-pos (count value))]
|
|
|
+ (with-redefs [util/get-selected-text (constantly false)
|
|
|
+ state/get-input (constantly #js {:value value})
|
|
|
+ cursor/pos (constantly pos)
|
|
|
+ cursor/get-caret-pos (constantly {})]
|
|
|
+ ((editor/keydown-not-matched-handler format)
|
|
|
+ #js {:key key} nil))))
|
|
|
|
|
|
(deftest keydown-not-matched-handler-test
|
|
|
(testing "Tag autocompletion"
|
|
|
- (keydown-not-matched-handler {:value "Some words " :key "#"})
|
|
|
+ (keydown-not-matched-handler {:value "Some words "})
|
|
|
(is (= :page-search-hashtag (state/get-editor-action))
|
|
|
"Autocomplete tags if starting new word")
|
|
|
- (state/set-editor-action! nil)
|
|
|
|
|
|
- (keydown-not-matched-handler {:value "String" :key "#"})
|
|
|
+ (keydown-not-matched-handler {:value ""})
|
|
|
+ (is (= :page-search-hashtag (state/get-editor-action))
|
|
|
+ "Autocomplete tags if starting a new line")
|
|
|
+
|
|
|
+ (keydown-not-matched-handler {:value "Some words" :cursor-pos 0})
|
|
|
+ (is (= :page-search-hashtag (state/get-editor-action))
|
|
|
+ "Autocomplete tags if there is are existing words and cursor is at start of line")
|
|
|
+
|
|
|
+ (keydown-not-matched-handler {:value "Some words" :cursor-pos 5})
|
|
|
+ (is (= :page-search-hashtag (state/get-editor-action))
|
|
|
+ "Autocomplete tags if there is whitespace before cursor")
|
|
|
+
|
|
|
+ (keydown-not-matched-handler {:value "String"})
|
|
|
+ (is (= nil (state/get-editor-action))
|
|
|
+ "Don't autocomplete tags if at end of word")
|
|
|
+
|
|
|
+ (keydown-not-matched-handler {:value "String" :cursor-pos 3})
|
|
|
(is (= nil (state/get-editor-action))
|
|
|
- "Don't autocomplete tags if not starting a new word")
|
|
|
- (state/set-editor-action! nil)
|
|
|
+ "Don't autocomplete tags if in middle of word")
|
|
|
|
|
|
- (keydown-not-matched-handler {:value "`One backtick " :key "#"})
|
|
|
+ (keydown-not-matched-handler {:value "`One backtick "})
|
|
|
(is (= :page-search-hashtag (state/get-editor-action))
|
|
|
"Autocomplete tags if only one backtick")
|
|
|
- (state/set-editor-action! nil)
|
|
|
|
|
|
- (keydown-not-matched-handler {:value "`String#gsub and String`" :key "#"})
|
|
|
+ (keydown-not-matched-handler {:value "`String#gsub and String`"
|
|
|
+ :cursor-pos (dec (count "`String#gsub and String`"))})
|
|
|
(is (= nil (state/get-editor-action))
|
|
|
"Don't autocomplete tags within backticks")
|
|
|
(state/set-editor-action! nil)))
|