whiteboards.spec.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import { expect } from '@playwright/test'
  2. import { test } from './fixtures'
  3. import { modKey } from './utils'
  4. test('enable whiteboards', async ({ page }) => {
  5. await expect(page.locator('.nav-header .whiteboard')).toBeHidden()
  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. await expect(page.locator('.nav-header .whiteboard')).toBeVisible()
  13. })
  14. test('create new whiteboard', async ({ page }) => {
  15. await page.click('.nav-header .whiteboard')
  16. await page.click('#tl-create-whiteboard')
  17. await expect(page.locator('.logseq-tldraw')).toBeVisible()
  18. })
  19. test('can right click title to show context menu', async ({ page }) => {
  20. await page.click('.whiteboard-page-title', {
  21. button: 'right',
  22. })
  23. await expect(page.locator('#custom-context-menu')).toBeVisible()
  24. await page.keyboard.press('Escape')
  25. await expect(page.locator('#custom-context-menu')).toHaveCount(0)
  26. })
  27. test('newly created whiteboard should have a default title', async ({ page }) => {
  28. await expect(page.locator('.whiteboard-page-title .title')).toContainText(
  29. 'Untitled'
  30. )
  31. })
  32. test('set whiteboard title', async ({ page }) => {
  33. const title = 'my-whiteboard'
  34. await page.click('.nav-header .whiteboard')
  35. await page.click('#tl-create-whiteboard')
  36. await page.click('.whiteboard-page-title')
  37. await page.fill('.whiteboard-page-title input', title)
  38. await page.keyboard.press('Enter')
  39. await expect(page.locator('.whiteboard-page-title .title')).toContainText(
  40. title
  41. )
  42. })
  43. test('update whiteboard title', async ({ page }) => {
  44. const title = 'my-whiteboard'
  45. await page.click('.whiteboard-page-title')
  46. await page.fill('.whiteboard-page-title input', title + '-2')
  47. await page.keyboard.press('Enter')
  48. // Updating non-default title should pop up a confirmation dialog
  49. await expect(page.locator('.ui__confirm-modal >> .headline')).toContainText(
  50. `Do you really want to change the page name to “${title}-2”?`
  51. )
  52. await page.click('.ui__confirm-modal button')
  53. await expect(page.locator('.whiteboard-page-title .title')).toContainText(
  54. title + '-2'
  55. )
  56. })
  57. test('draw a rectangle', async ({ page }) => {
  58. const canvas = await page.waitForSelector('.logseq-tldraw')
  59. const bounds = (await canvas.boundingBox())!
  60. await page.keyboard.press('r')
  61. await page.mouse.move(bounds.x + 5, bounds.y + 5)
  62. await page.mouse.down()
  63. await page.mouse.move(
  64. bounds.x + bounds.width / 2,
  65. bounds.y + bounds.height / 2
  66. )
  67. await page.mouse.up()
  68. await expect(
  69. page.locator('.logseq-tldraw .tl-positioned-svg rect')
  70. ).not.toHaveCount(0)
  71. })
  72. test('copy/paste url to create an iFrame shape', async ({ page }) => {
  73. const canvas = await page.waitForSelector('.logseq-tldraw')
  74. const bounds = (await canvas.boundingBox())!
  75. await page.keyboard.press('t')
  76. await page.mouse.move(bounds.x + 5, bounds.y + 5)
  77. await page.mouse.down()
  78. await page.waitForTimeout(100)
  79. await page.keyboard.type('https://logseq.com')
  80. await page.keyboard.press(modKey + '+a')
  81. await page.keyboard.press(modKey + '+c')
  82. await page.keyboard.press('Escape')
  83. await page.keyboard.press(modKey + '+v')
  84. await expect( page.locator('.logseq-tldraw .tl-iframe-container')).toHaveCount(1)
  85. })
  86. test('copy/paste twitter status url to create a Tweet shape', async ({ page }) => {
  87. const canvas = await page.waitForSelector('.logseq-tldraw')
  88. const bounds = (await canvas.boundingBox())!
  89. await page.keyboard.press('t')
  90. await page.mouse.move(bounds.x + 5, bounds.y + 5)
  91. await page.mouse.down()
  92. await page.waitForTimeout(100)
  93. await page.keyboard.type('https://twitter.com/logseq/status/1605224589046386689')
  94. await page.keyboard.press(modKey + '+a')
  95. await page.keyboard.press(modKey + '+c')
  96. await page.keyboard.press('Escape')
  97. await page.keyboard.press(modKey + '+v')
  98. await expect( page.locator('.logseq-tldraw .tl-tweet-container')).toHaveCount(1)
  99. })
  100. test('copy/paste youtube video url to create a Youtube shape', async ({ page }) => {
  101. const canvas = await page.waitForSelector('.logseq-tldraw')
  102. const bounds = (await canvas.boundingBox())!
  103. await page.keyboard.press('t')
  104. await page.mouse.move(bounds.x + 5, bounds.y + 5)
  105. await page.mouse.down()
  106. await page.waitForTimeout(100)
  107. await page.keyboard.type('https://www.youtube.com/watch?v=hz2BacySDXE')
  108. await page.keyboard.press(modKey + '+a')
  109. await page.keyboard.press(modKey + '+c')
  110. await page.keyboard.press('Escape')
  111. await page.keyboard.press(modKey + '+v')
  112. await expect( page.locator('.logseq-tldraw .tl-youtube-container')).toHaveCount(1)
  113. })
  114. test('cleanup the shapes', async ({ page }) => {
  115. await page.keyboard.press(`${modKey}+a`)
  116. await page.keyboard.press('Delete')
  117. await expect(page.locator('[data-type=Shape]')).toHaveCount(0)
  118. })
  119. test('zoom in', async ({ page }) => {
  120. await page.keyboard.press('Shift+0') // reset zoom
  121. await page.waitForTimeout(1500) // wait for the zoom animation to finish
  122. await page.click('#tl-zoom-in')
  123. await expect(page.locator('#tl-zoom')).toContainText('125%')
  124. })
  125. test('zoom out', async ({ page }) => {
  126. await page.keyboard.press('Shift+0')
  127. await page.waitForTimeout(1500)
  128. await page.click('#tl-zoom-out')
  129. await expect(page.locator('#tl-zoom')).toContainText('80%')
  130. })
  131. test('open context menu', async ({ page }) => {
  132. await page.locator('.logseq-tldraw').click({ button: 'right' })
  133. await expect(page.locator('.tl-context-menu')).toBeVisible()
  134. })
  135. test('close context menu on esc', async ({ page }) => {
  136. await page.keyboard.press('Escape')
  137. await expect(page.locator('.tl-context-menu')).toBeHidden()
  138. })
  139. test('quick add another whiteboard', async ({ page }) => {
  140. // create a new board first
  141. await page.click('.nav-header .whiteboard')
  142. await page.click('#tl-create-whiteboard')
  143. await page.click('.whiteboard-page-title')
  144. await page.fill('.whiteboard-page-title input', 'my-whiteboard-3')
  145. await page.keyboard.press('Enter')
  146. const canvas = await page.waitForSelector('.logseq-tldraw')
  147. await canvas.dblclick({
  148. position: {
  149. x: 100,
  150. y: 100,
  151. },
  152. })
  153. const quickAdd$ = page.locator('.tl-quick-search')
  154. await expect(quickAdd$).toBeVisible()
  155. await page.fill('.tl-quick-search input', 'my-whiteboard')
  156. await quickAdd$
  157. .locator('.tl-quick-search-option >> text=my-whiteboard-2')
  158. .first()
  159. .click()
  160. await expect(quickAdd$).toBeHidden()
  161. await expect(
  162. page.locator('.tl-logseq-portal-container >> text=my-whiteboard-2')
  163. ).toBeVisible()
  164. })
  165. test('go to another board and check reference', async ({ page }) => {
  166. await page
  167. .locator('.tl-logseq-portal-container >> text=my-whiteboard-2')
  168. .click()
  169. await expect(page.locator('.whiteboard-page-title .title')).toContainText(
  170. 'my-whiteboard-2'
  171. )
  172. const pageRefCount$ = page.locator('.whiteboard-page-refs-count')
  173. await expect(pageRefCount$.locator('.open-page-ref-link')).toContainText('1')
  174. })