1
0

basic.spec.ts 9.5 KB

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