blockref.spec.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { expect } from '@playwright/test'
  2. import { test } from './fixtures'
  3. import { createRandomPage, enterNextBlock, modKey, editNthBlock, moveCursorToBeginning, moveCursorToEnd } from './utils'
  4. import { dispatch_kb_events } from './util/keyboard-events'
  5. // Create a random page with some pre-defined blocks
  6. // - a
  7. // - b
  8. // id:: UUID
  9. // - ((id))
  10. async function setUpBlocks(page, block) {
  11. await createRandomPage(page)
  12. await block.mustFill('a')
  13. await block.enterNext()
  14. await block.mustFill('b')
  15. await page.keyboard.press(modKey + '+c', { delay: 100 })
  16. await page.waitForTimeout(100)
  17. await block.enterNext()
  18. await page.keyboard.press(modKey + '+v', { delay: 100 })
  19. await page.waitForTimeout(100)
  20. }
  21. test('backspace at the beginning of a refed block #9406', async ({ page, block }) => {
  22. await setUpBlocks(page, block)
  23. await page.waitForTimeout(100)
  24. await editNthBlock(page, 1)
  25. await page.waitForTimeout(100)
  26. await moveCursorToBeginning(page)
  27. await page.keyboard.press('Backspace', { delay: 100 })
  28. await expect(page.locator('textarea >> nth=0')).toHaveText("ab")
  29. await expect(await block.selectionStart()).toEqual(1)
  30. await expect(page.locator('.block-ref >> text="ab"')).toHaveCount(1);
  31. })
  32. test('delete at the end of a prev block before a refed block #9406', async ({ page, block }) => {
  33. await setUpBlocks(page, block)
  34. await page.waitForTimeout(100)
  35. await editNthBlock(page, 0)
  36. await page.waitForTimeout(100)
  37. await moveCursorToEnd(page)
  38. await page.keyboard.press('Delete', { delay: 100 })
  39. await page.waitForTimeout(100)
  40. await expect(page.locator('textarea >> nth=0')).toHaveText("ab")
  41. await expect(await block.selectionStart()).toEqual(1)
  42. await expect(page.locator('.block-ref >> text="ab"')).toHaveCount(1);
  43. })
  44. test('delete selected blocks, block ref should be replaced by content #9406', async ({ page, block }) => {
  45. await setUpBlocks(page, block)
  46. await editNthBlock(page, 0)
  47. await page.waitForTimeout(100)
  48. await page.keyboard.down('Shift')
  49. await page.keyboard.press('ArrowDown', { delay: 20 })
  50. await page.keyboard.press('ArrowDown', { delay: 20 })
  51. await page.keyboard.up('Shift')
  52. await block.waitForSelectedBlocks(2)
  53. await page.keyboard.press('Backspace')
  54. await expect(page.locator('.ls-block')).toHaveCount(1)
  55. await editNthBlock(page, 0)
  56. await expect(page.locator('textarea >> nth=0')).toHaveText("b")
  57. })
  58. test('delete and undo #9406', async ({ page, block }) => {
  59. await setUpBlocks(page, block)
  60. await editNthBlock(page, 0)
  61. await page.waitForTimeout(100)
  62. await page.keyboard.down('Shift')
  63. await page.keyboard.press('ArrowDown', { delay: 20 })
  64. await page.keyboard.press('ArrowDown', { delay: 20 })
  65. await page.keyboard.up('Shift')
  66. await block.waitForSelectedBlocks(2)
  67. await page.keyboard.press('Backspace', { delay: 100 })
  68. await expect(page.locator('.ls-block')).toHaveCount(1)
  69. await page.keyboard.press(modKey + '+z', { delay: 100 })
  70. await page.waitForTimeout(100)
  71. await expect(page.locator('.ls-block')).toHaveCount(3)
  72. await expect(page.locator('.block-ref >> text="b"')).toHaveCount(1);
  73. })