whiteboards.spec.ts 5.0 KB

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