basic.spec.ts 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. import { expect } from '@playwright/test'
  2. import fs from 'fs/promises'
  3. import path from 'path'
  4. import { test } from './fixtures'
  5. import { randomString, createRandomPage, modKey } from './utils'
  6. test('create page and blocks, save to disk', async ({ page, block, graphDir }) => {
  7. const pageTitle = await createRandomPage(page)
  8. // do editing
  9. await page.keyboard.type('first bullet')
  10. await block.enterNext()
  11. await block.waitForBlocks(2)
  12. await page.keyboard.type('second bullet')
  13. await block.enterNext()
  14. await page.keyboard.type('third bullet')
  15. expect(await block.indent()).toBe(true)
  16. await block.enterNext()
  17. await page.keyboard.type('continue editing')
  18. await page.keyboard.press('Shift+Enter')
  19. await page.keyboard.type('second line')
  20. await block.enterNext()
  21. expect(await block.unindent()).toBe(true)
  22. expect(await block.unindent()).toBe(false)
  23. await page.keyboard.type('test ok')
  24. await page.keyboard.press('Escape')
  25. await block.waitForBlocks(5)
  26. // active edit, and create next block
  27. await block.clickNext()
  28. await page.keyboard.type('test')
  29. for (let i = 0; i < 5; i++) {
  30. await page.keyboard.press('Backspace', { delay: 100 })
  31. }
  32. await page.keyboard.press('Escape')
  33. await block.waitForBlocks(5)
  34. await page.waitForTimeout(2000) // wait for saving to disk
  35. const contentOnDisk = await fs.readFile(
  36. path.join(graphDir, `pages/${pageTitle}.md`),
  37. 'utf8'
  38. )
  39. expect(contentOnDisk.trim()).toEqual(`
  40. - first bullet
  41. - second bullet
  42. - third bullet
  43. - continue editing
  44. second line
  45. - test ok`.trim())
  46. })
  47. test('delete and backspace', async ({ page, block }) => {
  48. await createRandomPage(page)
  49. await block.mustFill('test')
  50. // backspace
  51. await page.keyboard.press('Backspace')
  52. await page.keyboard.press('Backspace')
  53. expect(await page.inputValue('textarea >> nth=0')).toBe('te')
  54. // refill
  55. await block.enterNext()
  56. await block.mustType('test')
  57. await page.keyboard.press('ArrowLeft', { delay: 50 })
  58. await page.keyboard.press('ArrowLeft', { delay: 50 })
  59. // delete
  60. await page.keyboard.press('Delete', { delay: 50 })
  61. expect(await page.inputValue('textarea >> nth=0')).toBe('tet')
  62. await page.keyboard.press('Delete', { delay: 50 })
  63. expect(await page.inputValue('textarea >> nth=0')).toBe('te')
  64. await page.keyboard.press('Delete', { delay: 50 })
  65. expect(await page.inputValue('textarea >> nth=0')).toBe('te')
  66. })
  67. test('selection', async ({ page, block }) => {
  68. await createRandomPage(page)
  69. // add 5 blocks
  70. await block.mustFill('line 1')
  71. await block.enterNext()
  72. await block.mustFill('line 2')
  73. await block.enterNext()
  74. expect(await block.indent()).toBe(true)
  75. await block.mustFill('line 3')
  76. await block.enterNext()
  77. await block.mustFill('line 4')
  78. expect(await block.indent()).toBe(true)
  79. await block.enterNext()
  80. await block.mustFill('line 5')
  81. // shift+up select 3 blocks
  82. await page.keyboard.down('Shift')
  83. await page.keyboard.press('ArrowUp')
  84. await page.keyboard.press('ArrowUp')
  85. await page.keyboard.press('ArrowUp')
  86. await page.keyboard.up('Shift')
  87. await block.waitForSelectedBlocks(3)
  88. await page.keyboard.press('Backspace')
  89. await block.waitForBlocks(2)
  90. })
  91. test('template', async ({ page, block }) => {
  92. const randomTemplate = randomString(6)
  93. await createRandomPage(page)
  94. await block.mustFill('template test\ntemplate:: ')
  95. await page.keyboard.type(randomTemplate, {delay: 100})
  96. await page.keyboard.press('Enter')
  97. await block.clickNext()
  98. expect(await block.indent()).toBe(true)
  99. await block.mustFill('line1')
  100. await block.enterNext()
  101. await block.mustFill('line2')
  102. await block.enterNext()
  103. expect(await block.indent()).toBe(true)
  104. await block.mustFill('line3')
  105. await block.enterNext()
  106. expect(await block.unindent()).toBe(true)
  107. expect(await block.unindent()).toBe(true)
  108. expect(await block.unindent()).toBe(false) // already at the first level
  109. await block.waitForBlocks(5)
  110. // See-also: #9354
  111. await block.enterNext()
  112. await block.mustType('/template')
  113. await page.click('[title="Insert a created template here"]')
  114. // type to search template name
  115. await page.keyboard.type(randomTemplate.substring(0, 3), { delay: 100 })
  116. const popupMenuItem = page.locator('.absolute >> text=' + randomTemplate)
  117. await popupMenuItem.waitFor({ timeout: 2000 }) // wait for template search
  118. await popupMenuItem.click()
  119. await block.waitForBlocks(9)
  120. await block.clickNext()
  121. await block.mustType('/template')
  122. await page.click('[title="Insert a created template here"]')
  123. // type to search template name
  124. await page.keyboard.type(randomTemplate.substring(0, 3), { delay: 100 })
  125. await popupMenuItem.waitFor({ timeout: 2000 }) // wait for template search
  126. await popupMenuItem.click()
  127. await block.waitForBlocks(13) // 9 + 4
  128. })
  129. test('auto completion square brackets', async ({ page, block }) => {
  130. await createRandomPage(page)
  131. // In this test, `type` is unused instead of `fill`, to allow for auto-completion.
  132. // [[]]
  133. await block.mustType('This is a [', { toBe: 'This is a []' })
  134. await block.mustType('[', { toBe: 'This is a [[]]' })
  135. // wait for search popup
  136. await page.waitForSelector('text="Search for a page"')
  137. // re-enter edit mode
  138. await page.press('textarea >> nth=0', 'Escape')
  139. await page.click('.ls-block >> nth=-1')
  140. await page.waitForSelector('textarea >> nth=0', { state: 'visible' })
  141. // #3253
  142. await page.press('textarea >> nth=0', 'ArrowLeft')
  143. await page.press('textarea >> nth=0', 'ArrowLeft')
  144. await page.press('textarea >> nth=0', 'Enter')
  145. await page.waitForSelector('text="Search for a page"', { state: 'visible' })
  146. // type more `]`s
  147. await page.type('textarea >> nth=0', ']')
  148. expect(await page.inputValue('textarea >> nth=0')).toBe('This is a [[]]')
  149. await page.type('textarea >> nth=0', ']')
  150. expect(await page.inputValue('textarea >> nth=0')).toBe('This is a [[]]')
  151. await page.type('textarea >> nth=0', ']')
  152. expect(await page.inputValue('textarea >> nth=0')).toBe('This is a [[]]]')
  153. })
  154. test('auto completion and auto pair', async ({ page, block }) => {
  155. await createRandomPage(page)
  156. await block.mustFill('Auto-completion test')
  157. await block.enterNext()
  158. // {{
  159. await block.mustType('type {{', { toBe: 'type {{}}' })
  160. await page.waitForTimeout(100);
  161. // ((
  162. await block.clickNext()
  163. await block.mustType('type (', { toBe: 'type ()' })
  164. await block.mustType('(', { toBe: 'type (())' })
  165. await block.escapeEditing() // escape any popup from `(())`
  166. // [[ #3251
  167. await block.clickNext()
  168. await block.mustType('type [', { toBe: 'type []' })
  169. await block.mustType('[', { toBe: 'type [[]]' })
  170. await block.escapeEditing() // escape any popup from `[[]]`
  171. // ``
  172. await block.clickNext()
  173. await block.mustType('type `', { toBe: 'type ``' })
  174. await block.mustType('code here', { toBe: 'type `code here`' })
  175. })
  176. test('invalid page props #3944', async ({ page, block }) => {
  177. await createRandomPage(page)
  178. await block.mustFill('public:: true\nsize:: 65535')
  179. await page.press('textarea >> nth=0', 'Enter')
  180. // Force rendering property block
  181. await block.enterNext()
  182. })
  183. test('Scheduled date picker should point to the already specified Date #6985', async({page,block})=>{
  184. await createRandomPage(page)
  185. await block.mustFill('testTask \n SCHEDULED: <2000-05-06 Sat>')
  186. await block.enterNext()
  187. await page.waitForTimeout(500)
  188. await block.escapeEditing()
  189. // Open date picker
  190. await page.click('a.opacity-80')
  191. await page.waitForTimeout(500)
  192. expect(page.locator('text=May 2000')).toBeVisible()
  193. expect(page.locator('td:has-text("6").active')).toBeVisible()
  194. // Close date picker
  195. await page.click('a.opacity-80')
  196. await page.waitForTimeout(500)
  197. })
  198. test('Opening a second datepicker should close the first one #7341', async({page,block})=>{
  199. await createRandomPage(page)
  200. await block.mustFill('testTask \n SCHEDULED: <2000-05-06 Sat>')
  201. await block.enterNext();
  202. await block.mustFill('testTask \n SCHEDULED: <2000-06-07 Wed>')
  203. await block.enterNext();
  204. await page.click('#main-content-container')
  205. // Open date picker
  206. await page.waitForTimeout(500)
  207. await page.click('#main-content-container')
  208. await page.waitForTimeout(500)
  209. await page.click('a:has-text("2000-06-07 Wed").opacity-80')
  210. await page.waitForTimeout(50)
  211. await page.click('a:has-text("2000-05-06 Sat").opacity-80')
  212. await page.waitForTimeout(50)
  213. expect(page.locator('text=May 2000')).toBeVisible()
  214. expect(page.locator('td:has-text("6").active')).toBeVisible()
  215. expect(page.locator('text=June 2000')).not.toBeVisible()
  216. expect(page.locator('td:has-text("7").active')).not.toBeVisible()
  217. // Close date picker
  218. await page.click('a:has-text("2000-05-06 Sat").opacity-80')
  219. })