mirror of https://github.com/logseq/logseq
fix(test): use e2e to test hashtag
parent
f5731065a4
commit
40366f6dbf
|
@ -29,6 +29,41 @@ test('hashtag and quare brackets in same line #4178', async ({ page }) => {
|
|||
)
|
||||
})
|
||||
|
||||
test('hashtag search page auto-complete', async ({ page, block }) => {
|
||||
await createRandomPage(page)
|
||||
|
||||
await block.activeEditing(0)
|
||||
|
||||
await page.type('textarea >> nth=0', '#', { delay: 100 })
|
||||
await page.waitForSelector('text="Search for a page"', { state: 'visible' })
|
||||
await page.keyboard.press('Escape', { delay: 50 })
|
||||
|
||||
await block.mustFill("done")
|
||||
|
||||
await enterNextBlock(page)
|
||||
await page.type('textarea >> nth=0', 'Some#', { delay: 100 })
|
||||
await page.waitForSelector('text="Search for a page"', { state: 'visible' })
|
||||
await page.keyboard.press('Escape', { delay: 50 })
|
||||
|
||||
await block.mustFill("done")
|
||||
|
||||
await enterNextBlock(page)
|
||||
await page.type('textarea >> nth=0', 'Some #', { delay: 100 })
|
||||
await page.waitForSelector('text="Search for a page"', { state: 'visible' })
|
||||
await page.keyboard.press('Escape', { delay: 50 })
|
||||
|
||||
await block.mustFill("done")
|
||||
|
||||
await enterNextBlock(page)
|
||||
await page.type('textarea >> nth=0', 'SomeInner', { delay: 100 })
|
||||
for (let i = 0; i < 5; i++) {
|
||||
await page.press('textarea >> nth=0', 'ArrowLeft', { delay: 50 })
|
||||
}
|
||||
await page.type('textarea >> nth=0', '#', { delay: 50 })
|
||||
await page.waitForSelector('text="Search for a page"', { state: 'visible' })
|
||||
await page.keyboard.press('Escape', { delay: 50 })
|
||||
})
|
||||
|
||||
test('disappeared children #4814', async ({ page, block }) => {
|
||||
await createRandomPage(page)
|
||||
|
||||
|
|
|
@ -45,56 +45,6 @@
|
|||
"[[https://github.com/logseq/logseq][logseq]] is #awesome :)" 0 editor/url-regex))
|
||||
"Finds url in org link correctly"))
|
||||
|
||||
(defn- keydown-not-matched-handler
|
||||
"Spied version of editor/keydown-not-matched-handler"
|
||||
[{: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 "})
|
||||
(is (= :page-search-hashtag (state/get-editor-action))
|
||||
"Autocomplete tags if starting new word")
|
||||
|
||||
(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 in middle of word")
|
||||
|
||||
(keydown-not-matched-handler {:value "`One backtick "})
|
||||
(is (= :page-search-hashtag (state/get-editor-action))
|
||||
"Autocomplete tags if only one backtick")
|
||||
|
||||
(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)))
|
||||
|
||||
(defn- set-marker
|
||||
"Spied version of editor/set-marker"
|
||||
[marker content format]
|
||||
|
|
Loading…
Reference in New Issue