whiteboards.spec.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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('group the rectangles', async ({ page }) => {
  98. await page.keyboard.press(modKey + '+a')
  99. await page.keyboard.press(modKey + '+g')
  100. await expect(page.locator('.logseq-tldraw .tl-group-container')).toHaveCount(1)
  101. })
  102. test('deleting the group', async ({ page }) => {
  103. await page.keyboard.press(modKey + '+a')
  104. await page.keyboard.press(modKey + '+g')
  105. // should also delete the grouped shapes
  106. await expect(page.locator('.logseq-tldraw .tl-group-container')).toHaveCount(0)
  107. await expect(page.locator('.logseq-tldraw .tl-box-container')).toHaveCount(0)
  108. })
  109. test('undo the group deletion', async ({ page }) => {
  110. await page.keyboard.press(modKey + '+z')
  111. await expect(page.locator('.logseq-tldraw .tl-group-container')).toHaveCount(1)
  112. await expect(page.locator('.logseq-tldraw .tl-box-container')).toHaveCount(2)
  113. })
  114. test('undo the group cation', async ({ page }) => {
  115. await page.keyboard.press(modKey + '+z')
  116. await expect(page.locator('.logseq-tldraw .tl-group-container')).toHaveCount(0)
  117. await expect(page.locator('.logseq-tldraw .tl-box-container')).toHaveCount(2)
  118. })
  119. test('connect rectangles with an arrow', async ({ page }) => {
  120. const canvas = await page.waitForSelector('.logseq-tldraw')
  121. const bounds = (await canvas.boundingBox())!
  122. await page.keyboard.type('wc')
  123. await page.mouse.move(bounds.x + 20, bounds.y + 20)
  124. await page.mouse.down()
  125. await page.mouse.move(bounds.x + 100, bounds.y + 100, {steps: 5}) // will fail without steps
  126. await page.mouse.up()
  127. await page.keyboard.press('Escape')
  128. await expect(page.locator('.logseq-tldraw .tl-line-container')).toHaveCount(1)
  129. })
  130. test('delete the first rectangle', async ({ page }) => {
  131. await page.keyboard.press('Escape')
  132. await page.waitForTimeout(1000)
  133. await page.click('.logseq-tldraw .tl-box-container:first-of-type')
  134. await page.keyboard.press('Delete')
  135. await expect(page.locator('.logseq-tldraw .tl-box-container')).toHaveCount(1)
  136. await expect(page.locator('.logseq-tldraw .tl-line-container')).toHaveCount(0)
  137. })
  138. test('undo the delete action', async ({ page }) => {
  139. await page.keyboard.press(modKey + '+z')
  140. await expect(page.locator('.logseq-tldraw .tl-box-container')).toHaveCount(2)
  141. await expect(page.locator('.logseq-tldraw .tl-line-container')).toHaveCount(1)
  142. })
  143. test('convert the first rectangle to ellipse', async ({ page }) => {
  144. await page.keyboard.press('Escape')
  145. await page.waitForTimeout(1000)
  146. await page.click('.logseq-tldraw .tl-box-container:first-of-type')
  147. await page.mouse.move(0, 0) // move mouse to trigger a rerender of the context bar
  148. await page.click('.tl-context-bar .tl-geometry-tools-pane-anchor')
  149. await page.click('.tl-context-bar .tl-geometry-toolbar [data-tool=ellipse]')
  150. await expect(page.locator('.logseq-tldraw .tl-ellipse-container')).toHaveCount(1)
  151. await expect(page.locator('.logseq-tldraw .tl-box-container')).toHaveCount(1)
  152. })
  153. test('change the color of the ellipse', async ({ page }) => {
  154. await page.click('.tl-context-bar .tl-color-bg')
  155. await page.click('.tl-context-bar .tl-color-palette .bg-red-500')
  156. await expect(page.locator('.logseq-tldraw .tl-ellipse-container ellipse:last-of-type')).toHaveAttribute('fill', 'var(--ls-wb-background-color-red)')
  157. })
  158. test('undo the color switch', async ({ page }) => {
  159. await page.keyboard.press(modKey + '+z')
  160. await expect(page.locator('.logseq-tldraw .tl-ellipse-container ellipse:last-of-type')).toHaveAttribute('fill', 'var(--ls-wb-background-color-default)')
  161. })
  162. test('undo the shape conversion', async ({ page }) => {
  163. await page.keyboard.press(modKey + '+z')
  164. await expect(page.locator('.logseq-tldraw .tl-box-container')).toHaveCount(2)
  165. await expect(page.locator('.logseq-tldraw .tl-ellipse-container')).toHaveCount(0)
  166. })
  167. test('locked elements should not be removed', async ({ page }) => {
  168. await page.keyboard.press('Escape')
  169. await page.waitForTimeout(1000)
  170. await page.click('.logseq-tldraw .tl-box-container:first-of-type')
  171. await page.keyboard.press(`${modKey}+l`)
  172. await page.keyboard.press('Delete')
  173. await page.keyboard.press(`${modKey}+Shift+l`)
  174. await expect(page.locator('.logseq-tldraw .tl-box-container')).toHaveCount(2)
  175. })
  176. test('move arrow to back', async ({ page }) => {
  177. await page.keyboard.press('Escape')
  178. await page.waitForTimeout(1000)
  179. await page.click('.logseq-tldraw .tl-line-container')
  180. await page.keyboard.press('Shift+[')
  181. await expect(page.locator('.logseq-tldraw .tl-canvas .tl-layer > div:first-of-type > div:first-of-type')).toHaveClass('tl-line-container')
  182. })
  183. test('move arrow to front', async ({ page }) => {
  184. await page.keyboard.press('Escape')
  185. await page.waitForTimeout(1000)
  186. await page.click('.logseq-tldraw .tl-line-container')
  187. await page.keyboard.press('Shift+]')
  188. await expect(page.locator('.logseq-tldraw .tl-canvas .tl-layer > div:first-of-type > div:first-of-type')).not.toHaveClass('tl-line-container')
  189. })
  190. test('undo the move action', async ({ page }) => {
  191. await page.keyboard.press(modKey + '+z')
  192. await expect(page.locator('.logseq-tldraw .tl-canvas .tl-layer > div:first-of-type > div:first-of-type')).toHaveClass('tl-line-container')
  193. })
  194. test('cleanup the shapes', async ({ page }) => {
  195. await page.keyboard.press(`${modKey}+a`)
  196. await page.keyboard.press('Delete')
  197. await expect(page.locator('[data-type=Shape]')).toHaveCount(0)
  198. })
  199. test('create a block', async ({ page }) => {
  200. const canvas = await page.waitForSelector('.logseq-tldraw')
  201. const bounds = (await canvas.boundingBox())!
  202. await page.keyboard.type('ws')
  203. await page.mouse.dblclick(bounds.x + 5, bounds.y + 5)
  204. await page.waitForTimeout(100)
  205. await page.keyboard.type('a')
  206. await page.keyboard.press('Enter')
  207. await expect(page.locator('.logseq-tldraw .tl-logseq-portal-container')).toHaveCount(1)
  208. })
  209. test('expand the block', async ({ page }) => {
  210. await page.keyboard.press('Escape')
  211. await page.click('.logseq-tldraw .tl-context-bar .tie-object-expanded ')
  212. await page.waitForTimeout(100)
  213. await expect(page.locator('.logseq-tldraw .tl-logseq-portal-container .tl-logseq-portal-header')).toHaveCount(1)
  214. })
  215. test('undo the expand action', async ({ page }) => {
  216. await page.keyboard.press(modKey + '+z')
  217. await expect(page.locator('.logseq-tldraw .tl-logseq-portal-container .tl-logseq-portal-header')).toHaveCount(0)
  218. })
  219. test('undo the block action', async ({ page }) => {
  220. await page.keyboard.press(modKey + '+z')
  221. await expect(page.locator('.logseq-tldraw .tl-logseq-portal-container')).toHaveCount(0)
  222. })
  223. test('copy/paste url to create an iFrame shape', async ({ page }) => {
  224. const canvas = await page.waitForSelector('.logseq-tldraw')
  225. const bounds = (await canvas.boundingBox())!
  226. await page.keyboard.type('wt')
  227. await page.mouse.move(bounds.x + 5, bounds.y + 5)
  228. await page.mouse.down()
  229. await page.waitForTimeout(100)
  230. await page.keyboard.type('https://logseq.com')
  231. await page.keyboard.press(modKey + '+a')
  232. await page.keyboard.press(modKey + '+c')
  233. await page.keyboard.press('Escape')
  234. await page.keyboard.press(modKey + '+v')
  235. await expect( page.locator('.logseq-tldraw .tl-iframe-container')).toHaveCount(1)
  236. })
  237. test('copy/paste twitter status url to create a Tweet shape', async ({ page }) => {
  238. const canvas = await page.waitForSelector('.logseq-tldraw')
  239. const bounds = (await canvas.boundingBox())!
  240. await page.keyboard.type('wt')
  241. await page.mouse.move(bounds.x + 5, bounds.y + 5)
  242. await page.mouse.down()
  243. await page.waitForTimeout(100)
  244. await page.keyboard.type('https://twitter.com/logseq/status/1605224589046386689')
  245. await page.keyboard.press(modKey + '+a')
  246. await page.keyboard.press(modKey + '+c')
  247. await page.keyboard.press('Escape')
  248. await page.keyboard.press(modKey + '+v')
  249. await expect( page.locator('.logseq-tldraw .tl-tweet-container')).toHaveCount(1)
  250. })
  251. test('copy/paste youtube video url to create a Youtube shape', async ({ page }) => {
  252. const canvas = await page.waitForSelector('.logseq-tldraw')
  253. const bounds = (await canvas.boundingBox())!
  254. await page.keyboard.type('wt')
  255. await page.mouse.move(bounds.x + 5, bounds.y + 5)
  256. await page.mouse.down()
  257. await page.waitForTimeout(100)
  258. await page.keyboard.type('https://www.youtube.com/watch?v=hz2BacySDXE')
  259. await page.keyboard.press(modKey + '+a')
  260. await page.keyboard.press(modKey + '+c')
  261. await page.keyboard.press('Escape')
  262. await page.keyboard.press(modKey + '+v')
  263. await expect(page.locator('.logseq-tldraw .tl-youtube-container')).toHaveCount(1)
  264. })
  265. test('zoom in', async ({ page }) => {
  266. await page.keyboard.press('Shift+0') // reset zoom
  267. await page.waitForTimeout(1500) // wait for the zoom animation to finish
  268. await page.keyboard.press('Shift+=')
  269. await page.waitForTimeout(1500) // wait for the zoom animation to finish
  270. await expect(page.locator('#tl-zoom')).toContainText('125%')
  271. })
  272. test('zoom out', async ({ page }) => {
  273. await page.keyboard.press('Shift+0')
  274. await page.waitForTimeout(1500) // wait for the zoom animation to finish
  275. await page.keyboard.press('Shift+-')
  276. await page.waitForTimeout(1500) // wait for the zoom animation to finish
  277. await expect(page.locator('#tl-zoom')).toContainText('80%')
  278. })
  279. test('open context menu', async ({ page }) => {
  280. await page.locator('.logseq-tldraw').click({ button: 'right' })
  281. await expect(page.locator('.tl-context-menu')).toBeVisible()
  282. })
  283. test('close context menu on esc', async ({ page }) => {
  284. await page.keyboard.press('Escape')
  285. await expect(page.locator('.tl-context-menu')).toBeHidden()
  286. })
  287. test('quick add another whiteboard', async ({ page }) => {
  288. // create a new board first
  289. await page.click('.nav-header .whiteboard')
  290. await page.click('#tl-create-whiteboard')
  291. await page.click('.whiteboard-page-title')
  292. await page.fill('.whiteboard-page-title input', 'my-whiteboard-3')
  293. await page.keyboard.press('Enter')
  294. const canvas = await page.waitForSelector('.logseq-tldraw')
  295. await canvas.dblclick({
  296. position: {
  297. x: 100,
  298. y: 100,
  299. },
  300. })
  301. const quickAdd$ = page.locator('.tl-quick-search')
  302. await expect(quickAdd$).toBeVisible()
  303. await page.fill('.tl-quick-search input', 'my-whiteboard')
  304. await quickAdd$
  305. .locator('.tl-quick-search-option >> text=my-whiteboard-2')
  306. .first()
  307. .click()
  308. await expect(quickAdd$).toBeHidden()
  309. await expect(
  310. page.locator('.tl-logseq-portal-container >> text=my-whiteboard-2')
  311. ).toBeVisible()
  312. })
  313. test('go to another board and check reference', async ({ page }) => {
  314. await page
  315. .locator('.tl-logseq-portal-container >> text=my-whiteboard-2')
  316. .click()
  317. await expect(page.locator('.whiteboard-page-title .title')).toContainText(
  318. 'my-whiteboard-2'
  319. )
  320. const pageRefCount$ = page.locator('.whiteboard-page-refs-count')
  321. await expect(pageRefCount$.locator('.open-page-ref-link')).toContainText('1')
  322. })