Browse Source

test(e2e): refine test cases (#7542)

Andelf 2 years ago
parent
commit
fe5d9b92d9
3 changed files with 47 additions and 37 deletions
  1. 29 27
      e2e-tests/editor.spec.ts
  2. 12 4
      e2e-tests/fixtures.ts
  3. 6 6
      e2e-tests/util/keyboard-events.ts

+ 29 - 27
e2e-tests/editor.spec.ts

@@ -167,9 +167,10 @@ test(
 test('copy & paste block ref and replace its content', async ({ page, block }) => {
   await createRandomPage(page)
 
-  await block.mustFill('Some random text')
-  // FIXME: copy instantly will make content disappear
+  await block.mustType('Some random text')
+  // FIXME: https://github.com/logseq/logseq/issues/7541
   await page.waitForTimeout(1000)
+
   if (IsMac) {
     await page.keyboard.press('Meta+c')
   } else {
@@ -177,6 +178,8 @@ test('copy & paste block ref and replace its content', async ({ page, block }) =
   }
 
   await page.press('textarea >> nth=0', 'Enter')
+  await block.waitForBlocks(2)
+
   if (IsMac) {
     await page.keyboard.press('Meta+v')
   } else {
@@ -184,54 +187,58 @@ test('copy & paste block ref and replace its content', async ({ page, block }) =
   }
   await page.keyboard.press('Enter')
 
-  const blockRef = page.locator('.block-ref >> text="Some random text"');
-
   // Check if the newly created block-ref has the same referenced content
-  await expect(blockRef).toHaveCount(1);
+  await expect(page.locator('.block-ref >> text="Some random text"')).toHaveCount(1);
 
   // Move cursor into the block ref
   for (let i = 0; i < 4; i++) {
     await page.press('textarea >> nth=0', 'ArrowLeft')
   }
 
+  await expect(page.locator('textarea >> nth=0')).not.toHaveValue('Some random text')
+
   // Trigger replace-block-reference-with-content-at-point
   if (IsMac) {
     await page.keyboard.press('Meta+Shift+r')
   } else {
-    await page.keyboard.press('Control+Shift+v')
+    await page.keyboard.press('Control+Shift+r')
   }
+  await expect(page.locator('textarea >> nth=0')).toHaveValue('Some random text')
+  await block.escapeEditing()
+
+  await expect(page.locator('.block-ref >> text="Some random text"')).toHaveCount(0);
+  await expect(page.locator('text="Some random text"')).toHaveCount(2);
 })
 
 test('copy and paste block after editing new block #5962', async ({ page, block }) => {
   await createRandomPage(page)
 
   // Create a block and copy it in block-select mode
-  await block.mustFill('Block being copied')
-  await page.waitForTimeout(100)
+  await block.mustType('Block being copied')
   await page.keyboard.press('Escape')
-  await page.waitForTimeout(100)
+  await expect(page.locator('.ls-block.selected')).toHaveCount(1)
+
   if (IsMac) {
-    await page.keyboard.press('Meta+c')
+    await page.keyboard.press('Meta+c', { delay: 10 })
   } else {
-    await page.keyboard.press('Control+c')
+    await page.keyboard.press('Control+c', { delay: 10 })
   }
-  // await page.waitForTimeout(100)
+
   await page.keyboard.press('Enter')
-  await page.waitForTimeout(100)
+  await expect(page.locator('.ls-block.selected')).toHaveCount(0)
+  await expect(page.locator('textarea >> nth=0')).toBeVisible()
   await page.keyboard.press('Enter')
+  await block.waitForBlocks(2)
 
-  await page.waitForTimeout(100)
-  // Create a new block with some text
-  await page.keyboard.insertText("Typed block")
+  await block.mustType('Typed block')
 
-  // Quickly paste the copied block
   if (IsMac) {
     await page.keyboard.press('Meta+v')
   } else {
     await page.keyboard.press('Control+v')
   }
-
-  await expect(page.locator('text="Typed block"')).toHaveCount(1);
+  await expect(page.locator('text="Typed block"')).toHaveCount(1)
+  await block.waitForBlocks(3)
 })
 
 test('undo and redo after starting an action should not destroy text #6267', async ({ page, block }) => {
@@ -526,11 +533,10 @@ test('should show text after soft return when node is collapsed #5074', async ({
   await block.enterNext()
   expect(await block.indent()).toBe(true)
   await block.mustType('Child text')
-  await page.waitForTimeout(delay)
 
   // collapse
   await page.click('.block-control >> nth=0')
-  await page.waitForTimeout(delay)
+  await block.waitForBlocks(1)
 
   // select the block that has the soft return
   await page.keyboard.press('ArrowDown')
@@ -538,9 +544,7 @@ test('should show text after soft return when node is collapsed #5074', async ({
   await page.keyboard.press('Enter')
   await page.waitForTimeout(delay)
 
-  expect(await page.inputValue('textarea >> nth=0')).toBe(
-    'Before soft return\nAfter soft return'
-  )
+  await expect(page.locator('textarea >> nth=0')).toHaveText('Before soft return\nAfter soft return')
 
   // zoom into the block
   await page.click('a.block-control + a')
@@ -552,9 +556,7 @@ test('should show text after soft return when node is collapsed #5074', async ({
   await page.keyboard.press('Enter')
   await page.waitForTimeout(delay)
 
-  expect(await page.inputValue('textarea >> nth=0')).toBe(
-    'Before soft return\nAfter soft return'
-  )
+  await expect(page.locator('textarea >> nth=0')).toHaveText('Before soft return\nAfter soft return')
 })
 
 test('should not erase typed text when expanding block quickly after typing #3891', async ({ page, block }) => {

+ 12 - 4
e2e-tests/fixtures.ts

@@ -118,11 +118,13 @@ base.beforeEach(async () => {
     await page.keyboard.press('Escape')
     await page.keyboard.press('Escape')
 
+    /*
     const locator = page.locator('.notification-close-button').first()
     while (await locator.isVisible()) {
-      await locator.click()
-      expect(locator.isVisible()).resolves.toBe(false)
+      locator.click() // ignore error
     }
+    */
+    await expect(page.locator('.notification-close-button')).not.toBeVisible()
 
     const rightSidebar = page.locator('.cp__right-sidebar-inner')
     if (await rightSidebar.isVisible()) {
@@ -203,8 +205,14 @@ export const test = base.extend<LogseqFixtures>({
         await page.waitForSelector(`.ls-block.selected >> nth=${total - 1}`, { timeout: 1000 })
       },
       escapeEditing: async (): Promise<void> => {
-        await page.keyboard.press('Escape')
-        await page.keyboard.press('Escape')
+        const blockEdit = page.locator('.ls-block textarea >> nth=0')
+        while (await blockEdit.isVisible()) {
+          await page.keyboard.press('Escape')
+        }
+        const blockSelect = page.locator('.ls-block.selected')
+        while (await blockSelect.isVisible()) {
+          await page.keyboard.press('Escape')
+        }
       },
       activeEditing: async (nth: number): Promise<void> => {
         await page.waitForSelector(`.ls-block >> nth=${nth}`, { timeout: 1000 })

+ 6 - 6
e2e-tests/util/keyboard-events.ts

@@ -1,4 +1,4 @@
-/*** 
+/***
  * Author: Junyi Du <[email protected]>
  * References:
  * https://stackoverflow.com/questions/8892238/detect-keyboard-layout-with-javascript
@@ -243,7 +243,7 @@ export let macos_pinyin_selecting_candidate_double_left_square_bracket: Recorded
       "repeat": false,
       "isComposing": true
     },
-    "latency": 627
+    "latency": 200
   },
   {
     "event_type": "keyup",
@@ -353,7 +353,7 @@ export let macos_pinyin_selecting_candidate_double_left_square_bracket: Recorded
   {
     "event_type": "compositionend",
     "event": {},
-    "latency": 968
+    "latency": 200
   }
 ]
 
@@ -426,7 +426,7 @@ export let win10_RIME_selecting_candidate_double_left_square_bracket: RecordedEv
       "repeat": false,
       "isComposing": true
     },
-    "latency": 237
+    "latency": 200
   },
   {
     "event_type": "keyup",
@@ -461,6 +461,6 @@ export let win10_RIME_selecting_candidate_double_left_square_bracket: RecordedEv
   {
     "event_type": "compositionend",
     "event": {},
-    "latency": 1479
+    "latency": 200
   }
-]
+]