浏览代码

dev(e2e): add tests for selecting codeblock language (#9557)

* dev(e2e): add tests for selecting codeblock language

* remove trailing whitespace from test
Bad3r 2 年之前
父节点
当前提交
6760f897ac
共有 1 个文件被更改,包括 41 次插入1 次删除
  1. 41 1
      e2e-tests/code-editing.spec.ts

+ 41 - 1
e2e-tests/code-editing.spec.ts

@@ -1,6 +1,11 @@
 import { expect } from '@playwright/test'
 import { test } from './fixtures'
-import { createRandomPage, escapeToCodeEditor, escapeToBlockEditor } from './utils'
+import {
+  createRandomPage,
+  escapeToCodeEditor,
+  escapeToBlockEditor,
+  repeatKeyPress,
+} from './utils'
 
 /**
  * NOTE: CodeMirror is a complex library that requires a lot of setup to work.
@@ -239,3 +244,38 @@ test('multi properties with code', async ({ page }) => {
     '```'
   )
 })
+
+test('Select codeblock language', async ({ page }) => {
+  await createRandomPage(page)
+
+  await page.type('textarea >> nth=0', '/code block', { delay: 100 })
+  await page.press('textarea >> nth=0', 'Enter', { delay: 100 })
+
+  // Select Clojure from the dropdown menu
+  await repeatKeyPress(page, 'ArrowDown', 6)
+  await page.press('textarea >> nth=0', 'Enter', { delay: 100 })
+
+  await page.fill('.CodeMirror textarea', '(println "Hello, Logseq!")')
+  await page.press('.CodeMirror textarea', 'Escape', { delay: 100 })
+  expect(await page.inputValue('.block-editor textarea')).toBe(
+    '```clojure\n(println "Hello, Logseq!")\n```'
+  )
+})
+
+test('Select codeblock language while surrounded by text', async ({ page }) => {
+  await createRandomPage(page)
+
+  await page.fill('textarea >> nth=0', 'abc abc')
+  await repeatKeyPress(page, 'ArrowLeft', 3)
+  await page.type('textarea >> nth=0', '/code', { delay: 100 })
+  await page.press('textarea >> nth=0', 'Enter', { delay: 100 })
+
+  // Select Clojure from the dropdown menu
+  await repeatKeyPress(page, 'ArrowDown', 6)
+  await page.press('textarea >> nth=0', 'Enter', { delay: 100 })
+
+  await page.press('.CodeMirror textarea', 'Escape', { delay: 100 })
+  expect(await page.inputValue('.block-editor textarea')).toBe(
+    'abc \n```clojure\n```\nabc'
+  )
+})