Browse Source

fix e2e tests

Tienson Qin 3 years ago
parent
commit
d18d2f24ca

+ 37 - 37
e2e-tests/code-editing.spec.ts

@@ -30,26 +30,26 @@ test('switch code editing mode', async ({ page }) => {
   await page.waitForSelector('.CodeMirror pre', { state: 'hidden' })
   expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('```clojure\n```')
 
-  await page.waitForTimeout(100)
+  await page.waitForTimeout(200)
   await page.press(':nth-match(textarea, 1)', 'Escape')
   await page.waitForSelector('.CodeMirror pre', { state: 'visible' })
 
   // NOTE: must wait here, await loading of CodeMirror editor
-  await page.waitForTimeout(300)
+  await page.waitForTimeout(200)
   await page.click('.CodeMirror pre')
-  await page.waitForTimeout(300)
+  await page.waitForTimeout(200)
 
   await page.type('.CodeMirror textarea', '(+ 1 1')
   await page.press('.CodeMirror textarea', 'Escape')
   await page.waitForSelector('.CodeMirror pre', { state: 'hidden' })
   expect(await page.inputValue('.block-editor textarea')).toBe('```clojure\n(+ 1 1)\n```')
 
-  await page.waitForTimeout(100) // editor unloading
+  await page.waitForTimeout(200) // editor unloading
   await page.press('.block-editor textarea', 'Escape')
-  await page.waitForTimeout(300) // editor loading
+  await page.waitForTimeout(200) // editor loading
   // click position is estimated to be at the begining of the first line
   await page.click('.CodeMirror pre', { position: { x: 1, y: 5 } })
-  await page.waitForTimeout(300)
+  await page.waitForTimeout(200)
 
   await page.type('.CodeMirror textarea', ';; comment\n\n  \n')
 
@@ -57,7 +57,7 @@ test('switch code editing mode', async ({ page }) => {
   await page.waitForSelector('.CodeMirror pre', { state: 'hidden' })
   expect(await page.inputValue('.block-editor textarea')).toBe('```clojure\n;; comment\n\n  \n(+ 1 1)\n```')
 
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
 })
 
 
@@ -66,23 +66,23 @@ test('convert from block content to code', async ({ page }) => {
 
   await page.type('.block-editor textarea', '```')
   await page.press('.block-editor textarea', 'Shift+Enter')
-  await page.waitForTimeout(100) // wait for hotkey handler
+  await page.waitForTimeout(200) // wait for hotkey handler
   await page.press('.block-editor textarea', 'Escape')
   await page.waitForSelector('.CodeMirror pre', { state: 'visible' })
 
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
   await page.click('.CodeMirror pre')
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
   expect(await page.locator('.CodeMirror-gutter-wrapper .CodeMirror-linenumber >> nth=-1').innerText()).toBe('1')
 
   await page.press('.CodeMirror textarea', 'Escape')
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
 
   expect(await page.inputValue('.block-editor textarea')).toBe('```\n```')
 
   // reset block, code block with 1 line
   await page.fill('.block-editor textarea', '```\n\n```')
-  await page.waitForTimeout(100) // wait for fill
+  await page.waitForTimeout(200) // wait for fill
   await escapeToCodeEditor(page)
   expect(await page.locator('.CodeMirror-gutter-wrapper .CodeMirror-linenumber >> nth=-1').innerText()).toBe('1')
   await escapeToBlockEditor(page)
@@ -90,20 +90,20 @@ test('convert from block content to code', async ({ page }) => {
 
   // reset block, code block with 2 line
   await page.fill('.block-editor textarea', '```\n\n\n```')
-  await page.waitForTimeout(100)
+  await page.waitForTimeout(200)
   await escapeToCodeEditor(page)
   expect(await page.locator('.CodeMirror-gutter-wrapper .CodeMirror-linenumber >> nth=-1').innerText()).toBe('2')
   await escapeToBlockEditor(page)
   expect(await page.inputValue('.block-editor textarea')).toBe('```\n\n\n```')
 
   await page.fill('.block-editor textarea', '```\n  indented\nsecond line\n\n```')
-  await page.waitForTimeout(100)
+  await page.waitForTimeout(200)
   await escapeToCodeEditor(page)
   await escapeToBlockEditor(page)
   expect(await page.inputValue('.block-editor textarea')).toBe('```\n  indented\nsecond line\n\n```')
 
   await page.fill('.block-editor textarea', '```\n  indented\n  indented\n```')
-  await page.waitForTimeout(100)
+  await page.waitForTimeout(200)
   await escapeToCodeEditor(page)
   await escapeToBlockEditor(page)
   expect(await page.inputValue('.block-editor textarea')).toBe('```\n  indented\n  indented\n```')
@@ -117,9 +117,9 @@ test('code block mixed input source', async ({ page }) => {
   await escapeToCodeEditor(page)
   await page.type('.CodeMirror textarea', '  DEF\nGHI')
 
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
   await page.press('.CodeMirror textarea', 'Escape')
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
   // NOTE: auto-indent is on
   expect(await page.inputValue('.block-editor textarea')).toBe('```\n  ABC  DEF\n  GHI\n```')
 })
@@ -132,9 +132,9 @@ test('code block with text around', async ({ page }) => {
   await escapeToCodeEditor(page)
   await page.type('.CodeMirror textarea', 'first\n  second')
 
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
   await page.press('.CodeMirror textarea', 'Escape')
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
   expect(await page.inputValue('.block-editor textarea')).toBe('Heading\n```\nfirst\n  second\n```\nFooter')
 })
 
@@ -143,21 +143,21 @@ test('multiple code block', async ({ page }) => {
 
   // NOTE: the two code blocks are of the same content
   await page.fill('.block-editor textarea', '中文 Heading\n```clojure\n```\nMiddle 🚀\n```clojure\n```\nFooter')
-  await page.waitForTimeout(100)
+  await page.waitForTimeout(200)
 
   await page.press('.block-editor textarea', 'Escape')
   await page.waitForSelector('.CodeMirror pre', { state: 'visible' })
 
   // first
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
   await page.click('.CodeMirror pre >> nth=0')
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
 
   await page.type('.CodeMirror textarea >> nth=0', ':key-test\n', { strict: true })
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
 
   await page.press('.CodeMirror textarea >> nth=0', 'Escape')
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
   expect(await page.inputValue('.block-editor textarea'))
     .toBe('中文 Heading\n```clojure\n:key-test\n\n```\nMiddle 🚀\n```clojure\n```\nFooter')
 
@@ -165,15 +165,15 @@ test('multiple code block', async ({ page }) => {
   await page.press('.block-editor textarea', 'Escape')
   await page.waitForSelector('.CodeMirror pre', { state: 'visible' })
 
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
   await page.click('.CodeMirror pre >> nth=1')
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
 
   await page.type('.CodeMirror textarea >> nth=1', '\n  :key-test 日本語\n', { strict: true })
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
 
   await page.press('.CodeMirror textarea >> nth=1', 'Escape')
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
   expect(await page.inputValue('.block-editor textarea'))
     .toBe('中文 Heading\n```clojure\n:key-test\n\n```\nMiddle 🚀\n```clojure\n\n  :key-test 日本語\n\n```\nFooter')
 })
@@ -186,9 +186,9 @@ test('click outside to exit', async ({ page }) => {
   await escapeToCodeEditor(page)
   await page.type('.CodeMirror textarea', '  DEF\nGHI')
 
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
   await page.click('text=Click')
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
   // NOTE: auto-indent is on
   expect(await page.inputValue('.block-editor textarea')).toBe('Header ``Click``\n```\n  ABC  DEF\n  GHI\n```')
 })
@@ -200,13 +200,13 @@ test('click language label to exit #3463', async ({ page }) => {
   await page.waitForTimeout(200)
 
   await page.fill('.block-editor textarea', '```cpp\n```')
-  await page.waitForTimeout(100)
+  await page.waitForTimeout(200)
   await escapeToCodeEditor(page)
   await page.type('.CodeMirror textarea', '#include<iostream>')
 
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
   await page.click('text=cpp') // the language label
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
   expect(await page.inputValue('.block-editor textarea')).toBe('```cpp\n#include<iostream>\n```')
 })
 
@@ -222,17 +222,17 @@ test('multi properties with code', async ({ page }) => {
     '}\n' +
     '```'
   )
-  await page.waitForTimeout(100)
+  await page.waitForTimeout(200)
   await escapeToCodeEditor(page)
 
   // first character of code
   await page.click('.CodeMirror pre', { position: { x: 1, y: 5 } })
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
   await page.type('.CodeMirror textarea', '// Returns nil\n')
 
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
   await page.press('.CodeMirror textarea', 'Escape')
-  await page.waitForTimeout(1000)
+  await page.waitForTimeout(500)
   expect(await page.inputValue('.block-editor textarea')).toBe(
     'type:: code\n' +
     '类型:: 代码\n' +

+ 3 - 3
e2e-tests/page-refs.spec.ts

@@ -2,7 +2,7 @@ import { expect } from '@playwright/test'
 import { test } from './fixtures'
 import { IsMac, createRandomPage, newBlock, newInnerBlock, randomString, lastInnerBlock } from './utils'
 
-/*** 
+/***
  * Test alias features
  * Test search refering features
  * Consider diacritics
@@ -102,7 +102,7 @@ async function alias_test (page, page_name: string, search_kws: string[]){
     await page.waitForTimeout(500)
     page.click(":nth-match(.menu-link, 2)")
     await page.waitForNavigation()
-    await page.waitForTimeout(100)
+    await page.waitForTimeout(500)
     await lastInnerBlock(page)
     expect(await page.inputValue(':nth-match(textarea, 1)')).toBe("[[" + alias_name + "]]")
     await page.keyboard.press(hotkeyBack)}
@@ -117,4 +117,4 @@ async function alias_test (page, page_name: string, search_kws: string[]){
 
 test('page diacritic alias', async ({ page }) => {
   await alias_test(page, "ü", ["ü", "ü", "Ü"])
-})
+})

+ 6 - 2
src/main/frontend/components/block.cljs

@@ -1883,7 +1883,7 @@
                 (not block-ref?)
                 (assoc mouse-down-key (fn [e]
                                         (block-content-on-mouse-down e block block-id content edit-input-id))))]
-    [:div.block-content.inline.select-none
+    [:div.block-content.inline
      (cond-> {:id (str "block-content-" uuid)
               :on-mouse-up (fn [e]
                              (when (and
@@ -1893,7 +1893,11 @@
                                ;; clear highlighted text
                                (util/clear-selection!)))}
        (not slide?)
-       (merge attrs))
+       (merge attrs)
+
+       ;; not playwright ci
+       (not js/window.navigator.webdriver)
+       (assoc :class "select-none"))
 
      [:span
       [:div.flex.flex-row.justify-between