whiteboards.spec.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { expect } from '@playwright/test'
  2. import { test } from './fixtures'
  3. test('enable whiteboards', async ({ page }) => {
  4. await expect(page.locator('.nav-header .whiteboard')).toBeHidden()
  5. await page.click('#head .toolbar-dots-btn')
  6. await page.click('#head .dropdown-wrapper >> text=Settings')
  7. await page.click('.settings-modal a[data-id=features]')
  8. await page.click('text=Whiteboards >> .. >> .ui__toggle')
  9. await page.keyboard.press('Escape')
  10. await expect(page.locator('.nav-header .whiteboard')).toBeVisible()
  11. })
  12. test('create new whiteboard', async ({ page }) => {
  13. await page.click('.nav-header .whiteboard')
  14. await page.click('#tl-create-whiteboard')
  15. await expect(page.locator('.logseq-tldraw')).toBeVisible()
  16. })
  17. test('set whiteboard title', async ({ page }) => {
  18. const title = "my-whiteboard"
  19. // Newly created whiteboard should have a default title
  20. await expect(page.locator('.whiteboard-page-title .title')).toContainText("Untitled");
  21. await page.click('.whiteboard-page-title')
  22. await page.type('.whiteboard-page-title .title', title)
  23. await page.keyboard.press('Enter')
  24. await expect(page.locator('.whiteboard-page-title .title')).toContainText(title);
  25. await page.click('.whiteboard-page-title')
  26. await page.type('.whiteboard-page-title .title', "-2")
  27. await page.keyboard.press('Enter')
  28. // Updating non-default title should pop up a confirmation dialog
  29. await expect(page.locator('.ui__confirm-modal >> .headline')).toContainText(`Do you really want to change the page name to “${title}-2”?`);
  30. await page.click('.ui__confirm-modal button')
  31. await expect(page.locator('.whiteboard-page-title .title')).toContainText(title + "-2");
  32. })
  33. test('select rectangle tool', async ({ page }) => {
  34. await page.keyboard.press('8')
  35. await expect(page.locator('.tl-geometry-tools-pane-anchor [title*="Rectangle"]')).toHaveAttribute('data-selected', 'true')
  36. })
  37. test('draw a rectangle', async ({ page }) => {
  38. const canvas = await page.waitForSelector('.logseq-tldraw');
  39. const bounds = (await canvas.boundingBox())!;
  40. await page.keyboard.press('8')
  41. await page.mouse.move(bounds.x, bounds.y);
  42. await page.mouse.down();
  43. await page.mouse.move(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
  44. await page.mouse.up();
  45. await expect(page.locator('.logseq-tldraw .tl-positioned-svg rect')).not.toHaveCount(0);
  46. })
  47. test('zoom in', async ({ page }) => {
  48. await page.click('#tl-zoom-in')
  49. await expect(page.locator('#tl-zoom')).toContainText('125%');
  50. })
  51. test('zoom out', async ({ page }) => {
  52. await page.click('#tl-zoom-out')
  53. await expect(page.locator('#tl-zoom')).toContainText('100%');
  54. })
  55. test('open context menu', async ({ page }) => {
  56. await page.locator('.logseq-tldraw').click({ button: "right" })
  57. await expect(page.locator('.tl-context-menu')).toBeVisible()
  58. })
  59. test('close context menu on esc', async ({ page }) => {
  60. await page.keyboard.press('Escape')
  61. await expect(page.locator('.tl-context-menu')).toBeHidden()
  62. })
  63. test('quick add another whiteboard', async ({ page }) => {
  64. // create a new board first
  65. await page.click('.nav-header .whiteboard')
  66. await page.click('#tl-create-whiteboard')
  67. await page.click('.whiteboard-page-title')
  68. await page.type('.whiteboard-page-title .title', "my-whiteboard-3")
  69. await page.keyboard.press('Enter')
  70. const canvas = await page.waitForSelector('.logseq-tldraw');
  71. await canvas.dblclick({
  72. position: {
  73. x: 100,
  74. y: 100
  75. }
  76. })
  77. const quickAdd$ = page.locator('.tl-quick-search')
  78. await expect(quickAdd$).toBeVisible()
  79. await page.type('.tl-quick-search input', 'my-whiteboard')
  80. await quickAdd$.locator('.tl-quick-search-option >> text=my-whiteboard-2').first().click()
  81. await expect(quickAdd$).toBeHidden()
  82. await expect(page.locator('.tl-logseq-portal-container >> text=my-whiteboard-2')).toBeVisible()
  83. })
  84. test('go to another board and check reference', async ({ page }) => {
  85. await page.locator('.tl-logseq-portal-container >> text=my-whiteboard-2').click()
  86. await expect(page.locator('.whiteboard-page-title .title')).toContainText("my-whiteboard-2");
  87. const pageRefCount$ = page.locator('.whiteboard-page-refs-count')
  88. await expect(pageRefCount$.locator('.open-page-ref-link')).toContainText('1')
  89. await pageRefCount$.click()
  90. await expect(page.locator('.references-blocks')).toBeVisible()
  91. await expect(page.locator('.references-blocks >> .page-ref >> text=my-whiteboard-3')).toBeVisible()
  92. })