basic.spec.ts 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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('block selection', async ({ page, block }) => {
  68. await createRandomPage(page)
  69. await block.mustFill('1')
  70. await block.enterNext()
  71. await block.mustFill('2')
  72. expect(await block.indent()).toBe(true)
  73. await block.enterNext()
  74. await block.mustFill('3')
  75. await block.enterNext()
  76. await block.mustFill('4')
  77. expect(await block.unindent()).toBe(true)
  78. await block.enterNext()
  79. await block.mustFill('5')
  80. expect(await block.indent()).toBe(true)
  81. await block.enterNext()
  82. await block.mustFill('6')
  83. await block.enterNext()
  84. await block.mustFill('7')
  85. expect(await block.unindent()).toBe(true)
  86. await block.enterNext()
  87. await block.mustFill('8')
  88. expect(await block.indent()).toBe(true)
  89. await block.enterNext()
  90. await block.mustFill('9')
  91. expect(await block.unindent()).toBe(true)
  92. // shift+up/down
  93. await page.keyboard.down('Shift')
  94. await page.keyboard.press('ArrowUp')
  95. await block.waitForSelectedBlocks(1)
  96. let locator = page.locator('.ls-block >> nth=8')
  97. await page.keyboard.press('ArrowUp')
  98. await block.waitForSelectedBlocks(2)
  99. await page.keyboard.press('ArrowUp')
  100. await block.waitForSelectedBlocks(3)
  101. await page.keyboard.press('ArrowDown')
  102. await block.waitForSelectedBlocks(2)
  103. await page.keyboard.up('Shift')
  104. // mod+click select or deselect
  105. await page.keyboard.down(modKey)
  106. await page.click('.ls-block >> nth=7')
  107. await block.waitForSelectedBlocks(1)
  108. await page.click('.block-main-container >> nth=6')
  109. await block.waitForSelectedBlocks(2)
  110. // mod+shift+click
  111. await page.click('.ls-block >> nth=4')
  112. await block.waitForSelectedBlocks(3)
  113. await page.keyboard.down('Shift')
  114. await page.click('.ls-block >> nth=1')
  115. await block.waitForSelectedBlocks(6)
  116. await page.keyboard.up('Shift')
  117. await page.keyboard.up(modKey)
  118. await page.keyboard.press('Escape')
  119. // shift+click
  120. await page.keyboard.down('Shift')
  121. await page.click('.block-main-container >> nth=0')
  122. await page.click('.block-main-container >> nth=3')
  123. await block.waitForSelectedBlocks(4)
  124. await page.click('.ls-block >> nth=8')
  125. await block.waitForSelectedBlocks(9)
  126. await page.click('.ls-block >> nth=5')
  127. await block.waitForSelectedBlocks(6)
  128. await page.keyboard.up('Shift')
  129. })
  130. test('template', async ({ page, block }) => {
  131. const randomTemplate = randomString(6)
  132. await createRandomPage(page)
  133. await block.mustFill('template test\ntemplate:: ')
  134. await page.keyboard.type(randomTemplate, { delay: 100 })
  135. await page.keyboard.press('Enter')
  136. await block.clickNext()
  137. expect(await block.indent()).toBe(true)
  138. await block.mustFill('line1')
  139. await block.enterNext()
  140. await block.mustFill('line2')
  141. await block.enterNext()
  142. expect(await block.indent()).toBe(true)
  143. await block.mustFill('line3')
  144. await block.enterNext()
  145. expect(await block.unindent()).toBe(true)
  146. expect(await block.unindent()).toBe(true)
  147. expect(await block.unindent()).toBe(false) // already at the first level
  148. await block.waitForBlocks(5)
  149. // See-also: #9354
  150. await block.enterNext()
  151. await block.mustType('/template')
  152. await page.click('[title="Insert a created template here"]')
  153. // type to search template name
  154. await page.keyboard.type(randomTemplate.substring(0, 3), { delay: 100 })
  155. const popupMenuItem = page.locator('.absolute >> text=' + randomTemplate)
  156. await popupMenuItem.waitFor({ timeout: 2000 }) // wait for template search
  157. await popupMenuItem.click()
  158. await block.waitForBlocks(9)
  159. await block.clickNext()
  160. await block.mustType('/template')
  161. await page.click('[title="Insert a created template here"]')
  162. // type to search template name
  163. await page.keyboard.type(randomTemplate.substring(0, 3), { delay: 100 })
  164. await popupMenuItem.waitFor({ timeout: 2000 }) // wait for template search
  165. await popupMenuItem.click()
  166. await block.waitForBlocks(13) // 9 + 4
  167. })
  168. test('auto completion square brackets', async ({ page, block }) => {
  169. await createRandomPage(page)
  170. // In this test, `type` is unused instead of `fill`, to allow for auto-completion.
  171. // [[]]
  172. await block.mustType('This is a [', { toBe: 'This is a []' })
  173. await block.mustType('[', { toBe: 'This is a [[]]' })
  174. // wait for search popup
  175. await page.waitForSelector('text="Search for a page"')
  176. // re-enter edit mode
  177. await page.press('textarea >> nth=0', 'Escape')
  178. await page.click('.ls-block >> nth=-1')
  179. await page.waitForSelector('textarea >> nth=0', { state: 'visible' })
  180. // #3253
  181. await page.press('textarea >> nth=0', 'ArrowLeft')
  182. await page.press('textarea >> nth=0', 'ArrowLeft')
  183. await page.press('textarea >> nth=0', 'Enter')
  184. await page.waitForSelector('text="Search for a page"', { state: 'visible' })
  185. // type more `]`s
  186. await page.type('textarea >> nth=0', ']')
  187. expect(await page.inputValue('textarea >> nth=0')).toBe('This is a [[]]')
  188. await page.type('textarea >> nth=0', ']')
  189. expect(await page.inputValue('textarea >> nth=0')).toBe('This is a [[]]')
  190. await page.type('textarea >> nth=0', ']')
  191. expect(await page.inputValue('textarea >> nth=0')).toBe('This is a [[]]]')
  192. })
  193. test('auto completion and auto pair', async ({ page, block }) => {
  194. await createRandomPage(page)
  195. await block.mustFill('Auto-completion test')
  196. await block.enterNext()
  197. // {{
  198. await block.mustType('type {{', { toBe: 'type {{}}' })
  199. await page.waitForTimeout(100);
  200. // ((
  201. await block.clickNext()
  202. await block.mustType('type (', { toBe: 'type ()' })
  203. await block.mustType('(', { toBe: 'type (())' })
  204. await block.escapeEditing() // escape any popup from `(())`
  205. // [[ #3251
  206. await block.clickNext()
  207. await block.mustType('type [', { toBe: 'type []' })
  208. await block.mustType('[', { toBe: 'type [[]]' })
  209. await block.escapeEditing() // escape any popup from `[[]]`
  210. // ``
  211. await block.clickNext()
  212. await block.mustType('type `', { toBe: 'type ``' })
  213. await block.mustType('code here', { toBe: 'type `code here`' })
  214. })
  215. test('invalid page props #3944', async ({ page, block }) => {
  216. await createRandomPage(page)
  217. await block.mustFill('public:: true\nsize:: 65535')
  218. await page.press('textarea >> nth=0', 'Enter')
  219. // Force rendering property block
  220. await block.enterNext()
  221. })
  222. test('Scheduled date picker should point to the already specified Date #6985', async ({ page, block }) => {
  223. await createRandomPage(page)
  224. await block.mustFill('testTask \n SCHEDULED: <2000-05-06 Sat>')
  225. await block.enterNext()
  226. await page.waitForTimeout(500)
  227. await block.escapeEditing()
  228. // Open date picker
  229. await page.click('a.opacity-80')
  230. await page.waitForTimeout(500)
  231. await expect(page.locator('text=May 2000')).toBeVisible()
  232. await expect(page.locator('td:has-text("6").active')).toBeVisible()
  233. // Close date picker
  234. await page.click('a.opacity-80')
  235. await page.waitForTimeout(500)
  236. })
  237. test('Opening a second datepicker should close the first one #7341', async ({ page, block }) => {
  238. await createRandomPage(page)
  239. await block.mustFill('testTask \n SCHEDULED: <2000-05-06 Sat>')
  240. await block.enterNext();
  241. await block.mustFill('testTask \n SCHEDULED: <2000-06-07 Wed>')
  242. await block.enterNext();
  243. await page.click('#main-content-container')
  244. // Open date picker
  245. await page.waitForTimeout(500)
  246. await page.click('#main-content-container')
  247. await page.waitForTimeout(500)
  248. await page.click('a:has-text("2000-06-07 Wed").opacity-80')
  249. await page.waitForTimeout(50)
  250. await page.click('a:has-text("2000-05-06 Sat").opacity-80')
  251. await page.waitForTimeout(50)
  252. await expect(page.locator('text=May 2000')).toBeVisible()
  253. await expect(page.locator('td:has-text("6").active')).toBeVisible()
  254. await expect(page.locator('text=June 2000')).not.toBeVisible()
  255. await expect(page.locator('td:has-text("7").active')).not.toBeVisible()
  256. // Close date picker
  257. await page.click('a:has-text("2000-05-06 Sat").opacity-80')
  258. })