whiteboards.spec.ts 17 KB

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