whiteboards.spec.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import { expect } from '@playwright/test'
  2. import { test } from './fixtures'
  3. import { IsMac } from './utils'
  4. test('enable whiteboards', async ({ page }) => {
  5. await page.evaluate(() => {
  6. window.localStorage.setItem('ls-onboarding-whiteboard?', "true")
  7. })
  8. await expect(page.locator('.nav-header .whiteboard')).toBeHidden()
  9. await page.click('#head .toolbar-dots-btn')
  10. await page.click('#head .dropdown-wrapper >> text=Settings')
  11. await page.click('.settings-modal a[data-id=features]')
  12. await page.click('text=Whiteboards >> .. >> .ui__toggle')
  13. await page.keyboard.press('Escape')
  14. await expect(page.locator('.nav-header .whiteboard')).toBeVisible()
  15. })
  16. test('create new whiteboard', async ({ page }) => {
  17. await page.click('.nav-header .whiteboard')
  18. await page.click('#tl-create-whiteboard')
  19. await page.waitForTimeout(1000)
  20. await expect(page.locator('.logseq-tldraw')).toBeVisible()
  21. })
  22. test('can right click title to show context menu', async ({ page }) => {
  23. await page.click('.whiteboard-page-title', {
  24. button: 'right',
  25. })
  26. await expect(page.locator('#custom-context-menu')).toBeVisible()
  27. await page.keyboard.press('Escape')
  28. await expect(page.locator('#custom-context-menu')).toHaveCount(0)
  29. })
  30. test('set whiteboard title', async ({ page }) => {
  31. const title = 'my-whiteboard'
  32. // Newly created whiteboard should have a default title
  33. await expect(page.locator('.whiteboard-page-title .title')).toContainText(
  34. 'Untitled'
  35. )
  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. await page.click('.whiteboard-page-title')
  43. await page.fill('.whiteboard-page-title input', title + '-2')
  44. await page.keyboard.press('Enter')
  45. // Updating non-default title should pop up a confirmation dialog
  46. await expect(page.locator('.ui__confirm-modal >> .headline')).toContainText(
  47. `Do you really want to change the page name to “${title}-2”?`
  48. )
  49. await page.click('.ui__confirm-modal button')
  50. await expect(page.locator('.whiteboard-page-title .title')).toContainText(
  51. title + '-2'
  52. )
  53. })
  54. test('draw a rectangle', async ({ page }) => {
  55. const canvas = await page.waitForSelector('.logseq-tldraw')
  56. const bounds = (await canvas.boundingBox())!
  57. await page.keyboard.press('r')
  58. await page.mouse.move(bounds.x + 5, bounds.y + 5)
  59. await page.mouse.down()
  60. await page.mouse.move(
  61. bounds.x + bounds.width / 2,
  62. bounds.y + bounds.height / 2
  63. )
  64. await page.mouse.up()
  65. await expect(
  66. page.locator('.logseq-tldraw .tl-positioned-svg rect')
  67. ).not.toHaveCount(0)
  68. })
  69. test('cleanup the shapes', async ({ page }) => {
  70. if (IsMac) {
  71. await page.keyboard.press('Meta+a')
  72. } else {
  73. await page.keyboard.press('Control+a')
  74. }
  75. await page.keyboard.press('Delete')
  76. await expect(page.locator('[data-type=Shape]')).toHaveCount(0)
  77. })
  78. test('zoom in', async ({ page }) => {
  79. await page.keyboard.press('Shift+0') // reset zoom
  80. await page.waitForTimeout(1500) // wait for the zoom animation to finish
  81. await page.click('#tl-zoom-in')
  82. await expect(page.locator('#tl-zoom')).toContainText('125%')
  83. })
  84. test('zoom out', async ({ page }) => {
  85. await page.keyboard.press('Shift+0')
  86. await page.waitForTimeout(1500)
  87. await page.click('#tl-zoom-out')
  88. await expect(page.locator('#tl-zoom')).toContainText('80%')
  89. })
  90. test('open context menu', async ({ page }) => {
  91. await page.locator('.logseq-tldraw').click({ button: 'right' })
  92. await expect(page.locator('.tl-context-menu')).toBeVisible()
  93. })
  94. test('close context menu on esc', async ({ page }) => {
  95. await page.keyboard.press('Escape')
  96. await expect(page.locator('.tl-context-menu')).toBeHidden()
  97. })
  98. test('quick add another whiteboard', async ({ page }) => {
  99. // create a new board first
  100. await page.click('.nav-header .whiteboard')
  101. await page.click('#tl-create-whiteboard')
  102. await page.click('.whiteboard-page-title')
  103. await page.fill('.whiteboard-page-title input', 'my-whiteboard-3')
  104. await page.keyboard.press('Enter')
  105. const canvas = await page.waitForSelector('.logseq-tldraw')
  106. await canvas.dblclick({
  107. position: {
  108. x: 100,
  109. y: 100,
  110. },
  111. })
  112. const quickAdd$ = page.locator('.tl-quick-search')
  113. await expect(quickAdd$).toBeVisible()
  114. await page.fill('.tl-quick-search input', 'my-whiteboard')
  115. await quickAdd$
  116. .locator('.tl-quick-search-option >> text=my-whiteboard-2')
  117. .first()
  118. .click()
  119. await expect(quickAdd$).toBeHidden()
  120. await expect(
  121. page.locator('.tl-logseq-portal-container >> text=my-whiteboard-2')
  122. ).toBeVisible()
  123. })
  124. test('go to another board and check reference', async ({ page }) => {
  125. await page
  126. .locator('.tl-logseq-portal-container >> text=my-whiteboard-2')
  127. .click()
  128. await expect(page.locator('.whiteboard-page-title .title')).toContainText(
  129. 'my-whiteboard-2'
  130. )
  131. const pageRefCount$ = page.locator('.whiteboard-page-refs-count')
  132. await expect(pageRefCount$.locator('.open-page-ref-link')).toContainText('1')
  133. })