whiteboards.spec.ts 5.1 KB

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