whiteboards.spec.ts 17 KB

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