whiteboards.spec.ts 17 KB

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