basic.spec.ts 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import { expect } from '@playwright/test'
  2. import { test } from './fixtures'
  3. import { randomString, createRandomPage, openSidebar, newBlock, lastBlock } from './utils'
  4. test('render app', async ({ page }) => {
  5. // Direct Electron console to Node terminal.
  6. // page.on('console', console.log)
  7. // NOTE: part of app startup tests is moved to `fixtures.ts`.
  8. expect(await page.title()).toMatch(/^Logseq.*?/)
  9. })
  10. test('open sidebar', async ({ page }) => {
  11. await openSidebar(page)
  12. await page.waitForSelector('#sidebar-nav-wrapper a:has-text("New page")', { state: 'visible' })
  13. await page.waitForSelector('#sidebar-nav-wrapper >> text=Journals', { state: 'visible' })
  14. })
  15. test('search', async ({ page }) => {
  16. await page.click('#search-button')
  17. await page.waitForSelector('[placeholder="Search or create page"]')
  18. await page.fill('[placeholder="Search or create page"]', 'welcome')
  19. await page.waitForTimeout(500)
  20. const results = await page.$$('#ui__ac-inner .block')
  21. expect(results.length).toBeGreaterThanOrEqual(1)
  22. })
  23. test('create page and blocks', async ({ page }) => {
  24. await createRandomPage(page)
  25. // do editing
  26. await page.fill(':nth-match(textarea, 1)', 'this is my first bullet')
  27. await page.press(':nth-match(textarea, 1)', 'Enter')
  28. // first block
  29. expect(await page.$$('.block-content')).toHaveLength(1)
  30. await page.fill(':nth-match(textarea, 1)', 'this is my second bullet')
  31. await page.press(':nth-match(textarea, 1)', 'Enter')
  32. await page.fill(':nth-match(textarea, 1)', 'this is my third bullet')
  33. await page.press(':nth-match(textarea, 1)', 'Tab')
  34. await page.press(':nth-match(textarea, 1)', 'Enter')
  35. await page.keyboard.type('continue editing test')
  36. await page.keyboard.press('Shift+Enter')
  37. await page.keyboard.type('continue')
  38. await page.keyboard.press('Enter')
  39. await page.keyboard.press('Shift+Tab')
  40. await page.keyboard.press('Shift+Tab')
  41. await page.keyboard.type('test ok')
  42. await page.keyboard.press('Escape')
  43. const blocks = await page.$$('.ls-block')
  44. expect(blocks).toHaveLength(5)
  45. // active edit
  46. await page.click('.ls-block >> nth=-1')
  47. await page.press('textarea >> nth=0', 'Enter')
  48. await page.fill('textarea >> nth=0', 'test')
  49. for (let i = 0; i < 5; i++) {
  50. await page.keyboard.press('Backspace')
  51. }
  52. await page.keyboard.press('Escape')
  53. await page.waitForTimeout(500)
  54. expect(await page.$$('.ls-block')).toHaveLength(5)
  55. })
  56. test('delete and backspace', async ({ page }) => {
  57. await createRandomPage(page)
  58. await page.fill(':nth-match(textarea, 1)', 'test')
  59. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('test')
  60. // backspace
  61. await page.keyboard.press('Backspace')
  62. await page.keyboard.press('Backspace')
  63. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('te')
  64. // refill
  65. await page.fill(':nth-match(textarea, 1)', 'test')
  66. await page.keyboard.press('ArrowLeft')
  67. await page.keyboard.press('ArrowLeft')
  68. // delete
  69. await page.keyboard.press('Delete')
  70. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('tet')
  71. await page.keyboard.press('Delete')
  72. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('te')
  73. await page.keyboard.press('Delete')
  74. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('te')
  75. // TODO: test delete & backspace across blocks
  76. })
  77. test('selection', async ({ page }) => {
  78. await createRandomPage(page)
  79. await page.fill(':nth-match(textarea, 1)', 'line 1')
  80. await page.press(':nth-match(textarea, 1)', 'Enter')
  81. await page.fill(':nth-match(textarea, 1)', 'line 2')
  82. await page.press(':nth-match(textarea, 1)', 'Enter')
  83. await page.press(':nth-match(textarea, 1)', 'Tab')
  84. await page.fill(':nth-match(textarea, 1)', 'line 3')
  85. await page.press(':nth-match(textarea, 1)', 'Enter')
  86. await page.fill(':nth-match(textarea, 1)', 'line 4')
  87. await page.press(':nth-match(textarea, 1)', 'Tab')
  88. await page.press(':nth-match(textarea, 1)', 'Enter')
  89. await page.fill(':nth-match(textarea, 1)', 'line 5')
  90. await page.keyboard.down('Shift')
  91. await page.keyboard.press('ArrowUp')
  92. await page.keyboard.press('ArrowUp')
  93. await page.keyboard.press('ArrowUp')
  94. await page.keyboard.up('Shift')
  95. await page.waitForTimeout(500)
  96. await page.keyboard.press('Backspace')
  97. expect(await page.$$('.ls-block')).toHaveLength(2)
  98. })
  99. test('template', async ({ page }) => {
  100. const randomTemplate = randomString(10)
  101. await createRandomPage(page)
  102. await page.fill(':nth-match(textarea, 1)', 'template')
  103. await page.press(':nth-match(textarea, 1)', 'Shift+Enter')
  104. await page.type(':nth-match(textarea, 1)', 'template:: ' + randomTemplate)
  105. await page.press(':nth-match(textarea, 1)', 'Enter')
  106. await page.press(':nth-match(textarea, 1)', 'Enter')
  107. await page.press(':nth-match(textarea, 1)', 'Tab')
  108. await page.fill(':nth-match(textarea, 1)', 'line1')
  109. await page.press(':nth-match(textarea, 1)', 'Enter')
  110. await page.fill(':nth-match(textarea, 1)', 'line2')
  111. await page.press(':nth-match(textarea, 1)', 'Enter')
  112. await page.press(':nth-match(textarea, 1)', 'Tab')
  113. await page.fill(':nth-match(textarea, 1)', 'line3')
  114. await page.press(':nth-match(textarea, 1)', 'Enter')
  115. await page.press(':nth-match(textarea, 1)', 'Enter')
  116. await page.press(':nth-match(textarea, 1)', 'Enter')
  117. expect(await page.$$('.ls-block')).toHaveLength(5)
  118. await page.type(':nth-match(textarea, 1)', '/template')
  119. await page.click('[title="Insert a created template here"]')
  120. // type to search template name
  121. await page.keyboard.type(randomTemplate.substring(0, 3))
  122. await page.click('.absolute >> text=' + randomTemplate)
  123. await page.waitForTimeout(500)
  124. expect(await page.$$('.ls-block')).toHaveLength(8)
  125. })
  126. test('auto completion square brackets', async ({ page }) => {
  127. await createRandomPage(page)
  128. await page.fill(':nth-match(textarea, 1)', 'Auto-completion test')
  129. await page.press(':nth-match(textarea, 1)', 'Enter')
  130. // [[]]
  131. await page.type(':nth-match(textarea, 1)', 'This is a [')
  132. await page.inputValue(':nth-match(textarea, 1)').then(text => {
  133. expect(text).toBe('This is a []')
  134. })
  135. await page.type(':nth-match(textarea, 1)', '[')
  136. // wait for search popup
  137. await page.waitForSelector('text="Search for a page"')
  138. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('This is a [[]]')
  139. // re-enter edit mode
  140. await page.press(':nth-match(textarea, 1)', 'Escape')
  141. await page.click('.ls-block >> nth=-1')
  142. await page.waitForSelector(':nth-match(textarea, 1)', { state: 'visible' })
  143. // #3253
  144. await page.press(':nth-match(textarea, 1)', 'ArrowLeft')
  145. await page.press(':nth-match(textarea, 1)', 'ArrowLeft')
  146. await page.press(':nth-match(textarea, 1)', 'Enter')
  147. await page.waitForSelector('text="Search for a page"', { state: 'visible' })
  148. // type more `]`s
  149. await page.type(':nth-match(textarea, 1)', ']')
  150. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('This is a [[]]')
  151. await page.type(':nth-match(textarea, 1)', ']')
  152. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('This is a [[]]')
  153. await page.type(':nth-match(textarea, 1)', ']')
  154. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('This is a [[]]]')
  155. })
  156. test('auto completion and auto pair', async ({ page }) => {
  157. await createRandomPage(page)
  158. await page.fill(':nth-match(textarea, 1)', 'Auto-completion test')
  159. await page.press(':nth-match(textarea, 1)', 'Enter')
  160. // {}
  161. await page.type(':nth-match(textarea, 1)', 'type {{')
  162. // FIXME: keycode seq is wrong
  163. // expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('type {{}}')
  164. // (()
  165. await newBlock(page)
  166. await page.type(':nth-match(textarea, 1)', 'type (')
  167. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('type ()')
  168. await page.type(':nth-match(textarea, 1)', '(')
  169. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('type (())')
  170. // ``
  171. await newBlock(page)
  172. await page.type(':nth-match(textarea, 1)', 'type `')
  173. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('type ``')
  174. await page.type(':nth-match(textarea, 1)', 'code here')
  175. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('type `code here`')
  176. })
  177. // FIXME: Electron with filechooser is not working
  178. test.skip('open directory', async ({ page }) => {
  179. await page.click('#sidebar-nav-wrapper >> text=Journals')
  180. await page.waitForSelector('h1:has-text("Open a local directory")')
  181. await page.click('h1:has-text("Open a local directory")')
  182. // await page.waitForEvent('filechooser')
  183. await page.keyboard.press('Escape')
  184. await page.click('#sidebar-nav-wrapper >> text=Journals')
  185. })