whiteboards.spec.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. import { expect } from '@playwright/test'
  2. import { test } from './fixtures'
  3. import { modKey } from './utils'
  4. test('enable whiteboards', async ({ page }) => {
  5. if (await page.$('.nav-header .whiteboard') === null) {
  6. await page.click('#head .toolbar-dots-btn')
  7. await page.click('#head .dropdown-wrapper >> text=Settings')
  8. await page.click('.settings-modal a[data-id=features]')
  9. await page.click('text=Whiteboards >> .. >> .ui__toggle')
  10. await page.waitForTimeout(1000)
  11. await page.keyboard.press('Escape')
  12. }
  13. await expect(page.locator('.nav-header .whiteboard')).toBeVisible()
  14. })
  15. test('should display onboarding tour', async ({ page }) => {
  16. // ensure onboarding tour is going to be triggered locally
  17. await page.evaluate(`window.localStorage.removeItem('whiteboard-onboarding-tour?')`)
  18. await page.click('.nav-header .whiteboard')
  19. await expect(page.locator('.cp__whiteboard-welcome')).toBeVisible()
  20. await page.click('.cp__whiteboard-welcome button.bg-gray-600')
  21. await expect(page.locator('.cp__whiteboard-welcome')).toBeHidden()
  22. })
  23. test('create new whiteboard', async ({ page }) => {
  24. await page.click('#tl-create-whiteboard')
  25. await expect(page.locator('.logseq-tldraw')).toBeVisible()
  26. })
  27. test('can right click title to show context menu', async ({ page }) => {
  28. await page.click('.whiteboard-page-title', {
  29. button: 'right',
  30. })
  31. await expect(page.locator('#custom-context-menu')).toBeVisible()
  32. await page.keyboard.press('Escape')
  33. await expect(page.locator('#custom-context-menu')).toHaveCount(0)
  34. })
  35. test('newly created whiteboard should have a default title', async ({ page }) => {
  36. await expect(page.locator('.whiteboard-page-title .title')).toContainText(
  37. 'Untitled'
  38. )
  39. })
  40. test('set whiteboard title', async ({ page }) => {
  41. const title = 'my-whiteboard'
  42. await page.click('.nav-header .whiteboard')
  43. await page.click('#tl-create-whiteboard')
  44. await page.click('.whiteboard-page-title')
  45. await page.fill('.whiteboard-page-title input', title)
  46. await page.keyboard.press('Enter')
  47. await expect(page.locator('.whiteboard-page-title .title')).toContainText(
  48. title
  49. )
  50. })
  51. test('update whiteboard title', async ({ page }) => {
  52. const title = 'my-whiteboard'
  53. await page.click('.whiteboard-page-title')
  54. await page.fill('.whiteboard-page-title input', title + '-2')
  55. await page.keyboard.press('Enter')
  56. // Updating non-default title should pop up a confirmation dialog
  57. await expect(page.locator('.ui__confirm-modal >> .headline')).toContainText(
  58. `Do you really want to change the page name to “${title}-2”?`
  59. )
  60. await page.click('.ui__confirm-modal button')
  61. await expect(page.locator('.whiteboard-page-title .title')).toContainText(
  62. title + '-2'
  63. )
  64. })
  65. test('draw a rectangle', async ({ page }) => {
  66. const canvas = await page.waitForSelector('.logseq-tldraw')
  67. const bounds = (await canvas.boundingBox())!
  68. await page.keyboard.type('wr')
  69. await page.mouse.move(bounds.x + 5, bounds.y + 5)
  70. await page.mouse.down()
  71. await page.mouse.move(bounds.x + 50, bounds.y + 50 )
  72. await page.mouse.up()
  73. await page.keyboard.press('Escape')
  74. await expect(page.locator('.logseq-tldraw .tl-box-container')).toHaveCount(1)
  75. })
  76. test('undo the rectangle action', async ({ page }) => {
  77. await page.keyboard.press(modKey + '+z')
  78. await expect(page.locator('.logseq-tldraw .tl-positioned-svg rect')).toHaveCount(0)
  79. })
  80. test('redo the rectangle action', async ({ page }) => {
  81. await page.keyboard.press(modKey + '+Shift+z')
  82. await page.keyboard.press('Escape')
  83. await page.waitForTimeout(100)
  84. await expect(page.locator('.logseq-tldraw .tl-box-container')).toHaveCount(1)
  85. })
  86. test('clone the rectangle', async ({ page }) => {
  87. const canvas = await page.waitForSelector('.logseq-tldraw')
  88. const bounds = (await canvas.boundingBox())!
  89. await page.mouse.move(bounds.x + 20, bounds.y + 20, {steps: 5})
  90. await page.keyboard.down('Alt')
  91. await page.mouse.down()
  92. await page.mouse.move(bounds.x + 100, bounds.y + 100, {steps: 5})
  93. await page.mouse.up()
  94. await page.keyboard.up('Alt')
  95. await expect(page.locator('.logseq-tldraw .tl-box-container')).toHaveCount(2)
  96. })
  97. test('connect rectangles with an arrow', async ({ page }) => {
  98. const canvas = await page.waitForSelector('.logseq-tldraw')
  99. const bounds = (await canvas.boundingBox())!
  100. await page.keyboard.type('wc')
  101. await page.mouse.move(bounds.x + 20, bounds.y + 20)
  102. await page.mouse.down()
  103. await page.mouse.move(bounds.x + 100, bounds.y + 100, {steps: 5}) // will fail without steps
  104. await page.mouse.up()
  105. await page.keyboard.press('Escape')
  106. await expect(page.locator('.logseq-tldraw .tl-line-container')).toHaveCount(1)
  107. })
  108. test('delete the first rectangle', async ({ page }) => {
  109. await page.keyboard.press('Escape')
  110. await page.waitForTimeout(1000)
  111. await page.click('.logseq-tldraw .tl-box-container:first-of-type')
  112. await page.keyboard.press('Delete')
  113. await expect(page.locator('.logseq-tldraw .tl-box-container')).toHaveCount(1)
  114. await expect(page.locator('.logseq-tldraw .tl-line-container')).toHaveCount(0)
  115. })
  116. test('undo the delete action', async ({ page }) => {
  117. await page.keyboard.press(modKey + '+z')
  118. await expect(page.locator('.logseq-tldraw .tl-box-container')).toHaveCount(2)
  119. await expect(page.locator('.logseq-tldraw .tl-line-container')).toHaveCount(1)
  120. })
  121. test('convert the first rectangle to ellipse', async ({ page }) => {
  122. await page.keyboard.press('Escape')
  123. await page.waitForTimeout(1000)
  124. await page.click('.logseq-tldraw .tl-box-container:first-of-type')
  125. await page.mouse.move(0, 0) // move mouse to trigger a rerender of the context bar
  126. await page.click('.tl-context-bar .tl-geometry-tools-pane-anchor')
  127. await page.click('.tl-context-bar .tl-geometry-toolbar [data-tool=ellipse]')
  128. await expect(page.locator('.logseq-tldraw .tl-ellipse-container')).toHaveCount(1)
  129. await expect(page.locator('.logseq-tldraw .tl-box-container')).toHaveCount(1)
  130. })
  131. test('change the color of the ellipse', async ({ page }) => {
  132. await page.click('.tl-context-bar .tl-color-bg')
  133. await page.click('.tl-context-bar .tl-color-palette .bg-red-500')
  134. await expect(page.locator('.logseq-tldraw .tl-ellipse-container ellipse:last-of-type')).toHaveAttribute('fill', 'var(--ls-wb-background-color-red)')
  135. })
  136. test('undo the color switch', async ({ page }) => {
  137. await page.keyboard.press(modKey + '+z')
  138. await expect(page.locator('.logseq-tldraw .tl-ellipse-container ellipse:last-of-type')).toHaveAttribute('fill', 'var(--ls-wb-background-color-default)')
  139. })
  140. test('undo the shape conversion', async ({ page }) => {
  141. await page.keyboard.press(modKey + '+z')
  142. await expect(page.locator('.logseq-tldraw .tl-box-container')).toHaveCount(2)
  143. await expect(page.locator('.logseq-tldraw .tl-ellipse-container')).toHaveCount(0)
  144. })
  145. test('locked elements should not be removed', async ({ page }) => {
  146. await page.keyboard.press('Escape')
  147. await page.waitForTimeout(1000)
  148. await page.click('.logseq-tldraw .tl-box-container:first-of-type')
  149. await page.keyboard.press(`${modKey}+l`)
  150. await page.keyboard.press('Delete')
  151. await page.keyboard.press(`${modKey}+Shift+l`)
  152. await expect(page.locator('.logseq-tldraw .tl-box-container')).toHaveCount(2)
  153. })
  154. test('move arrow to back', async ({ page }) => {
  155. await page.keyboard.press('Escape')
  156. await page.waitForTimeout(1000)
  157. await page.click('.logseq-tldraw .tl-line-container')
  158. await page.keyboard.press('Shift+[')
  159. await expect(page.locator('.logseq-tldraw .tl-canvas .tl-layer > div:first-of-type > div:first-of-type')).toHaveClass('tl-line-container')
  160. })
  161. test('move arrow to front', async ({ page }) => {
  162. await page.keyboard.press('Escape')
  163. await page.waitForTimeout(1000)
  164. await page.click('.logseq-tldraw .tl-line-container')
  165. await page.keyboard.press('Shift+]')
  166. await expect(page.locator('.logseq-tldraw .tl-canvas .tl-layer > div:first-of-type > div:first-of-type')).not.toHaveClass('tl-line-container')
  167. })
  168. test('undo the move action', async ({ page }) => {
  169. await page.keyboard.press(modKey + '+z')
  170. await expect(page.locator('.logseq-tldraw .tl-canvas .tl-layer > div:first-of-type > div:first-of-type')).toHaveClass('tl-line-container')
  171. })
  172. test('cleanup the shapes', async ({ page }) => {
  173. await page.keyboard.press(`${modKey}+a`)
  174. await page.keyboard.press('Delete')
  175. await expect(page.locator('[data-type=Shape]')).toHaveCount(0)
  176. })
  177. test('create a block', async ({ page }) => {
  178. const canvas = await page.waitForSelector('.logseq-tldraw')
  179. const bounds = (await canvas.boundingBox())!
  180. await page.keyboard.type('ws')
  181. await page.mouse.dblclick(bounds.x + 5, bounds.y + 5)
  182. await page.waitForTimeout(100)
  183. await page.keyboard.type('a')
  184. await page.keyboard.press('Enter')
  185. await expect(page.locator('.logseq-tldraw .tl-logseq-portal-container')).toHaveCount(1)
  186. })
  187. test('expand the block', async ({ page }) => {
  188. await page.keyboard.press('Escape')
  189. await page.click('.logseq-tldraw .tl-context-bar .tie-object-expanded ')
  190. await page.waitForTimeout(100)
  191. await expect(page.locator('.logseq-tldraw .tl-logseq-portal-container .tl-logseq-portal-header')).toHaveCount(1)
  192. })
  193. test('undo the expand action', async ({ page }) => {
  194. await page.keyboard.press(modKey + '+z')
  195. await expect(page.locator('.logseq-tldraw .tl-logseq-portal-container .tl-logseq-portal-header')).toHaveCount(0)
  196. })
  197. test('undo the block action', async ({ page }) => {
  198. await page.keyboard.press(modKey + '+z')
  199. await expect(page.locator('.logseq-tldraw .tl-logseq-portal-container')).toHaveCount(0)
  200. })
  201. test('copy/paste url to create an iFrame shape', async ({ page }) => {
  202. const canvas = await page.waitForSelector('.logseq-tldraw')
  203. const bounds = (await canvas.boundingBox())!
  204. await page.keyboard.type('wt')
  205. await page.mouse.move(bounds.x + 5, bounds.y + 5)
  206. await page.mouse.down()
  207. await page.waitForTimeout(100)
  208. await page.keyboard.type('https://logseq.com')
  209. await page.keyboard.press(modKey + '+a')
  210. await page.keyboard.press(modKey + '+c')
  211. await page.keyboard.press('Escape')
  212. await page.keyboard.press(modKey + '+v')
  213. await expect( page.locator('.logseq-tldraw .tl-iframe-container')).toHaveCount(1)
  214. })
  215. test('copy/paste twitter status url to create a Tweet shape', async ({ page }) => {
  216. const canvas = await page.waitForSelector('.logseq-tldraw')
  217. const bounds = (await canvas.boundingBox())!
  218. await page.keyboard.type('wt')
  219. await page.mouse.move(bounds.x + 5, bounds.y + 5)
  220. await page.mouse.down()
  221. await page.waitForTimeout(100)
  222. await page.keyboard.type('https://twitter.com/logseq/status/1605224589046386689')
  223. await page.keyboard.press(modKey + '+a')
  224. await page.keyboard.press(modKey + '+c')
  225. await page.keyboard.press('Escape')
  226. await page.keyboard.press(modKey + '+v')
  227. await expect( page.locator('.logseq-tldraw .tl-tweet-container')).toHaveCount(1)
  228. })
  229. test('copy/paste youtube video url to create a Youtube shape', async ({ page }) => {
  230. const canvas = await page.waitForSelector('.logseq-tldraw')
  231. const bounds = (await canvas.boundingBox())!
  232. await page.keyboard.type('wt')
  233. await page.mouse.move(bounds.x + 5, bounds.y + 5)
  234. await page.mouse.down()
  235. await page.waitForTimeout(100)
  236. await page.keyboard.type('https://www.youtube.com/watch?v=hz2BacySDXE')
  237. await page.keyboard.press(modKey + '+a')
  238. await page.keyboard.press(modKey + '+c')
  239. await page.keyboard.press('Escape')
  240. await page.keyboard.press(modKey + '+v')
  241. await expect(page.locator('.logseq-tldraw .tl-youtube-container')).toHaveCount(1)
  242. })
  243. test('zoom in', async ({ page }) => {
  244. await page.keyboard.press('Shift+0') // reset zoom
  245. await page.waitForTimeout(1500) // wait for the zoom animation to finish
  246. await page.keyboard.press('Shift+=')
  247. await page.waitForTimeout(1500) // wait for the zoom animation to finish
  248. await expect(page.locator('#tl-zoom')).toContainText('125%')
  249. })
  250. test('zoom out', async ({ page }) => {
  251. await page.keyboard.press('Shift+0')
  252. await page.waitForTimeout(1500) // wait for the zoom animation to finish
  253. await page.keyboard.press('Shift+-')
  254. await page.waitForTimeout(1500) // wait for the zoom animation to finish
  255. await expect(page.locator('#tl-zoom')).toContainText('80%')
  256. })
  257. test('open context menu', async ({ page }) => {
  258. await page.locator('.logseq-tldraw').click({ button: 'right' })
  259. await expect(page.locator('.tl-context-menu')).toBeVisible()
  260. })
  261. test('close context menu on esc', async ({ page }) => {
  262. await page.keyboard.press('Escape')
  263. await expect(page.locator('.tl-context-menu')).toBeHidden()
  264. })
  265. test('quick add another whiteboard', async ({ page }) => {
  266. // create a new board first
  267. await page.click('.nav-header .whiteboard')
  268. await page.click('#tl-create-whiteboard')
  269. await page.click('.whiteboard-page-title')
  270. await page.fill('.whiteboard-page-title input', 'my-whiteboard-3')
  271. await page.keyboard.press('Enter')
  272. const canvas = await page.waitForSelector('.logseq-tldraw')
  273. await canvas.dblclick({
  274. position: {
  275. x: 100,
  276. y: 100,
  277. },
  278. })
  279. const quickAdd$ = page.locator('.tl-quick-search')
  280. await expect(quickAdd$).toBeVisible()
  281. await page.fill('.tl-quick-search input', 'my-whiteboard')
  282. await quickAdd$
  283. .locator('.tl-quick-search-option >> text=my-whiteboard-2')
  284. .first()
  285. .click()
  286. await expect(quickAdd$).toBeHidden()
  287. await expect(
  288. page.locator('.tl-logseq-portal-container >> text=my-whiteboard-2')
  289. ).toBeVisible()
  290. })
  291. test('go to another board and check reference', async ({ page }) => {
  292. await page
  293. .locator('.tl-logseq-portal-container >> text=my-whiteboard-2')
  294. .click()
  295. await expect(page.locator('.whiteboard-page-title .title')).toContainText(
  296. 'my-whiteboard-2'
  297. )
  298. const pageRefCount$ = page.locator('.whiteboard-page-refs-count')
  299. await expect(pageRefCount$.locator('.open-page-ref-link')).toContainText('1')
  300. })