whiteboards.spec.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 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('cleanup the shapes', async ({ page }) => {
  73. if (IsMac) {
  74. await page.keyboard.press('Meta+a')
  75. } else {
  76. await page.keyboard.press('Control+a')
  77. }
  78. await page.keyboard.press('Delete')
  79. await expect(page.locator('[data-type=Shape]')).toHaveCount(0)
  80. })
  81. test('zoom in', async ({ page }) => {
  82. await page.keyboard.press('Shift+0') // reset zoom
  83. await page.waitForTimeout(1500) // wait for the zoom animation to finish
  84. await page.click('#tl-zoom-in')
  85. await expect(page.locator('#tl-zoom')).toContainText('125%')
  86. })
  87. test('zoom out', async ({ page }) => {
  88. await page.keyboard.press('Shift+0')
  89. await page.waitForTimeout(1500)
  90. await page.click('#tl-zoom-out')
  91. await expect(page.locator('#tl-zoom')).toContainText('80%')
  92. })
  93. test('open context menu', async ({ page }) => {
  94. await page.locator('.logseq-tldraw').click({ button: 'right' })
  95. await expect(page.locator('.tl-context-menu')).toBeVisible()
  96. })
  97. test('close context menu on esc', async ({ page }) => {
  98. await page.keyboard.press('Escape')
  99. await expect(page.locator('.tl-context-menu')).toBeHidden()
  100. })
  101. test('quick add another whiteboard', async ({ page }) => {
  102. // create a new board first
  103. await page.click('.nav-header .whiteboard')
  104. await page.click('#tl-create-whiteboard')
  105. await page.click('.whiteboard-page-title')
  106. await page.fill('.whiteboard-page-title input', 'my-whiteboard-3')
  107. await page.keyboard.press('Enter')
  108. const canvas = await page.waitForSelector('.logseq-tldraw')
  109. await canvas.dblclick({
  110. position: {
  111. x: 100,
  112. y: 100,
  113. },
  114. })
  115. const quickAdd$ = page.locator('.tl-quick-search')
  116. await expect(quickAdd$).toBeVisible()
  117. await page.fill('.tl-quick-search input', 'my-whiteboard')
  118. await quickAdd$
  119. .locator('.tl-quick-search-option >> text=my-whiteboard-2')
  120. .first()
  121. .click()
  122. await expect(quickAdd$).toBeHidden()
  123. await expect(
  124. page.locator('.tl-logseq-portal-container >> text=my-whiteboard-2')
  125. ).toBeVisible()
  126. })
  127. test('go to another board and check reference', async ({ page }) => {
  128. await page
  129. .locator('.tl-logseq-portal-container >> text=my-whiteboard-2')
  130. .click()
  131. await expect(page.locator('.whiteboard-page-title .title')).toContainText(
  132. 'my-whiteboard-2'
  133. )
  134. const pageRefCount$ = page.locator('.whiteboard-page-refs-count')
  135. await expect(pageRefCount$.locator('.open-page-ref-link')).toContainText('1')
  136. })