editor.spec.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import { expect } from '@playwright/test'
  2. import { test } from './fixtures'
  3. import { createRandomPage, enterNextBlock, systemModifier, IsMac } from './utils'
  4. import { dispatch_kb_events } from './util/keyboard-events'
  5. import * as kb_events from './util/keyboard-events'
  6. test('hashtag and quare brackets in same line #4178', async ({ page }) => {
  7. await createRandomPage(page)
  8. await page.type('textarea >> nth=0', '#foo bar')
  9. await enterNextBlock(page)
  10. await page.type('textarea >> nth=0', 'bar [[blah]]', { delay: 100 })
  11. for (let i = 0; i < 12; i++) {
  12. await page.press('textarea >> nth=0', 'ArrowLeft')
  13. }
  14. await page.type('textarea >> nth=0', ' ')
  15. await page.press('textarea >> nth=0', 'ArrowLeft')
  16. await page.type('textarea >> nth=0', '#')
  17. await page.waitForSelector('text="Search for a page"', { state: 'visible' })
  18. await page.type('textarea >> nth=0', 'fo')
  19. await page.click('.absolute >> text=' + 'foo')
  20. expect(await page.inputValue('textarea >> nth=0')).toBe(
  21. '#foo bar [[blah]]'
  22. )
  23. })
  24. test('disappeared children #4814', async ({ page, block }) => {
  25. await createRandomPage(page)
  26. await block.mustType('parent')
  27. await block.enterNext()
  28. expect(await block.indent()).toBe(true)
  29. for (let i = 0; i < 5; i++) {
  30. await block.mustType(i.toString())
  31. await block.enterNext()
  32. }
  33. // collapse
  34. await page.click('.block-control >> nth=0')
  35. // expand
  36. await page.click('.block-control >> nth=0')
  37. await block.waitForBlocks(7) // 1 + 5 + 1 empty
  38. // Ensures there's no active editor
  39. await expect(page.locator('.editor-inner')).toHaveCount(0, { timeout: 500 })
  40. })
  41. test('create new page from bracketing text #4971', async ({ page, block }) => {
  42. let title = 'Page not Exists yet'
  43. await createRandomPage(page)
  44. await block.mustType(`[[${title}]]`)
  45. await page.keyboard.press(systemModifier('Control+o'))
  46. // Check page title equals to `title`
  47. await page.waitForTimeout(100)
  48. expect(await page.locator('h1.title').innerText()).toContain(title)
  49. // Check there're linked references
  50. await page.waitForSelector(`.references .ls-block >> nth=1`, { state: 'detached', timeout: 100 })
  51. })
  52. test.skip('backspace and cursor position #4897', async ({ page, block }) => {
  53. await createRandomPage(page)
  54. // Delete to previous block, and check cursor postion, with markup
  55. await block.mustFill('`012345`')
  56. await block.enterNext()
  57. await block.mustType('`abcdef', { toBe: '`abcdef`' }) // "`" auto-completes
  58. expect(await block.selectionStart()).toBe(7)
  59. expect(await block.selectionEnd()).toBe(7)
  60. for (let i = 0; i < 7; i++) {
  61. await page.keyboard.press('ArrowLeft')
  62. }
  63. expect(await block.selectionStart()).toBe(0)
  64. await page.keyboard.press('Backspace')
  65. await block.waitForBlocks(1) // wait for delete and re-render
  66. expect(await block.selectionStart()).toBe(8)
  67. })
  68. test.skip('next block and cursor position', async ({ page, block }) => {
  69. await createRandomPage(page)
  70. // Press Enter and check cursor postion, with markup
  71. await block.mustType('abcde`12345', { toBe: 'abcde`12345`' }) // "`" auto-completes
  72. for (let i = 0; i < 7; i++) {
  73. await page.keyboard.press('ArrowLeft')
  74. }
  75. expect(await block.selectionStart()).toBe(5) // after letter 'e'
  76. await block.enterNext()
  77. expect(await block.selectionStart()).toBe(0) // should at the beginning of the next block
  78. const locator = page.locator('textarea >> nth=0')
  79. await expect(locator).toHaveText('`12345`', { timeout: 1000 })
  80. })
  81. test(
  82. "Press CJK Left Black Lenticular Bracket `【` by 2 times #3251 should trigger [[]], " +
  83. "but dont trigger RIME #3440 ",
  84. // cases should trigger [[]] #3251
  85. async ({ page, block }) => {
  86. for (let [idx, events] of [
  87. kb_events.win10_pinyin_left_full_square_bracket,
  88. kb_events.macos_pinyin_left_full_square_bracket
  89. // TODO: support #3741
  90. // kb_events.win10_legacy_pinyin_left_full_square_bracket,
  91. ].entries()) {
  92. await createRandomPage(page)
  93. let check_text = "#3251 test " + idx
  94. await block.mustFill(check_text + "【")
  95. await dispatch_kb_events(page, ':nth-match(textarea, 1)', events)
  96. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe(check_text + '【')
  97. await block.mustFill(check_text + "【【")
  98. await dispatch_kb_events(page, ':nth-match(textarea, 1)', events)
  99. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe(check_text + '[[]]')
  100. };
  101. // dont trigger RIME #3440
  102. for (let [idx, events] of [
  103. kb_events.macos_pinyin_selecting_candidate_double_left_square_bracket,
  104. kb_events.win10_RIME_selecting_candidate_double_left_square_bracket
  105. ].entries()) {
  106. await createRandomPage(page)
  107. let check_text = "#3440 test " + idx
  108. await block.mustFill(check_text)
  109. await dispatch_kb_events(page, ':nth-match(textarea, 1)', events)
  110. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe(check_text)
  111. await dispatch_kb_events(page, ':nth-match(textarea, 1)', events)
  112. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe(check_text)
  113. }
  114. })
  115. test('copy & paste block ref and replace its content', async ({ page, block }) => {
  116. await createRandomPage(page)
  117. await block.mustFill('Some random text')
  118. // FIXME: copy instantly will make content disappear
  119. await page.waitForTimeout(1000)
  120. if (IsMac) {
  121. await page.keyboard.press('Meta+c')
  122. } else {
  123. await page.keyboard.press('Control+c')
  124. }
  125. await page.press('textarea >> nth=0', 'Enter')
  126. if (IsMac) {
  127. await page.keyboard.press('Meta+v')
  128. } else {
  129. await page.keyboard.press('Control+v')
  130. }
  131. await page.keyboard.press('Enter')
  132. const blockRef = page.locator('.block-ref >> text="Some random text"');
  133. // Check if the newly created block-ref has the same referenced content
  134. await expect(blockRef).toHaveCount(1);
  135. // Move cursor into the block ref
  136. for (let i = 0; i < 4; i++) {
  137. await page.press('textarea >> nth=0', 'ArrowLeft')
  138. }
  139. // Trigger replace-block-reference-with-content-at-point
  140. if (IsMac) {
  141. await page.keyboard.press('Meta+Shift+r')
  142. } else {
  143. await page.keyboard.press('Control+Shift+v')
  144. }
  145. })