Tienson Qin 2 anni fa
parent
commit
ede24e81dd
2 ha cambiato i file con 99 aggiunte e 1 eliminazioni
  1. 74 0
      e2e-tests/blockref.spec.ts
  2. 25 1
      e2e-tests/utils.ts

+ 74 - 0
e2e-tests/blockref.spec.ts

@@ -0,0 +1,74 @@
+import { expect } from '@playwright/test'
+import { test } from './fixtures'
+import { createRandomPage, enterNextBlock, modKey, editNthBlock, moveCursorToBeginning, moveCursorToEnd } from './utils'
+import { dispatch_kb_events } from './util/keyboard-events'
+
+// Create a random page with some pre-defined blocks
+// - a
+// - b
+//   id:: UUID
+// - ((id))
+async function setUpBlocks(page, block) {
+  await createRandomPage(page)
+
+  await block.mustFill('a')
+  await block.enterNext()
+  await block.mustFill('b')
+  await page.keyboard.press(modKey + '+c')
+  await page.waitForTimeout(100)
+  await block.enterNext()
+  await page.keyboard.press(modKey + '+v')
+  await page.waitForTimeout(100)
+}
+
+test('backspace at the beginning of a refed block #9406', async ({ page, block }) => {
+  await setUpBlocks(page, block)
+  await editNthBlock(page, 1)
+  await moveCursorToBeginning(page)
+  await page.keyboard.press('Backspace')
+  await expect(page.locator('textarea >> nth=0')).toHaveText("ab")
+  await expect(await block.selectionStart()).toEqual(1)
+  await expect(page.locator('.block-ref >> text="ab"')).toHaveCount(1);
+})
+
+test('delete at the end of a prev block before a refed block #9406', async ({ page, block }) => {
+  await setUpBlocks(page, block)
+  await editNthBlock(page, 0)
+  await moveCursorToEnd(page)
+  await page.keyboard.press('Delete')
+  await expect(page.locator('textarea >> nth=0')).toHaveText("ab")
+  await expect(await block.selectionStart()).toEqual(1)
+  await expect(page.locator('.block-ref >> text="ab"')).toHaveCount(1);
+})
+
+test('delete selected blocks, block ref should be replaced by content #9406', async ({ page, block }) => {
+  await setUpBlocks(page, block)
+  await editNthBlock(page, 0)
+  await page.waitForTimeout(100)
+  await page.keyboard.down('Shift')
+  await page.keyboard.press('ArrowDown')
+  await page.keyboard.press('ArrowDown')
+  await page.keyboard.up('Shift')
+  await block.waitForSelectedBlocks(2)
+  await page.keyboard.press('Backspace')
+  await expect(page.locator('.ls-block')).toHaveCount(1)
+  await editNthBlock(page, 0)
+  await expect(page.locator('textarea >> nth=0')).toHaveText("b")
+})
+
+test('delete and undo #9406', async ({ page, block }) => {
+  await setUpBlocks(page, block)
+  await editNthBlock(page, 0)
+  await page.waitForTimeout(100)
+  await page.keyboard.down('Shift')
+  await page.keyboard.press('ArrowDown')
+  await page.keyboard.press('ArrowDown')
+  await page.keyboard.up('Shift')
+  await block.waitForSelectedBlocks(2)
+  await page.keyboard.press('Backspace')
+  await expect(page.locator('.ls-block')).toHaveCount(1)
+  await page.keyboard.press(modKey + '+z')
+  await page.waitForTimeout(100)
+  await expect(page.locator('.ls-block')).toHaveCount(3)
+  await expect(page.locator('.block-ref >> text="b"')).toHaveCount(1);
+})

+ 25 - 1
e2e-tests/utils.ts

@@ -31,6 +31,26 @@ export async function lastBlock(page: Page): Promise<Locator> {
   return page.locator('textarea >> nth=0')
 }
 
+/**
+ * Move the cursor to the beginning of the current editor
+ * @param page The Playwright Page object.
+ */
+export async function moveCursorToBeginning(page: Page): Promise<Locator> {
+  await page.press('textarea >> nth=0', modKey + '+a') // select all
+  await page.press('textarea >> nth=0', 'ArrowLeft')
+  return page.locator('textarea >> nth=0')
+}
+
+/**
+ * Move the cursor to the end of the current editor
+ * @param page The Playwright Page object.
+ */
+export async function moveCursorToEnd(page: Page): Promise<Locator> {
+  await page.press('textarea >> nth=0', modKey + '+a') // select all
+  await page.press('textarea >> nth=0', 'ArrowRight')
+  return page.locator('textarea >> nth=0')
+}
+
 /**
  * Press Enter and create the next block.
  * @param page The Playwright Page object.
@@ -155,8 +175,12 @@ export async function loadLocalGraph(page: Page, path: string): Promise<void> {
   console.log('Graph loaded for ' + path)
 }
 
+export async function editNthBlock(page: Page, n) {
+  await page.click(`.ls-block .block-content >> nth=${n}`)
+}
+
 export async function editFirstBlock(page: Page) {
-  await page.click('.ls-block .block-content >> nth=0')
+  await editNthBlock(page, 0)
 }
 
 /**