context-menu.spec.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { expect } from '@playwright/test'
  2. import { test } from './fixtures'
  3. import { createRandomPage } from './utils'
  4. test('open context menu', async ({ page }) => {
  5. await createRandomPage(page)
  6. await page.locator('span.bullet-container >> nth=0').click({button: "right"})
  7. await expect(page.locator('#custom-context-menu')).toBeVisible()
  8. })
  9. test('close context menu on esc', async ({ page }) => {
  10. await createRandomPage(page)
  11. await page.locator('span.bullet-container >> nth=0').click({button: "right"})
  12. await page.keyboard.press('Escape')
  13. await expect(page.locator('#custom-context-menu')).toHaveCount(0)
  14. })
  15. test('close context menu by left clicking on empty space', async ({ page }) => {
  16. await createRandomPage(page)
  17. await page.locator('span.bullet-container >> nth=0').click({button: "right"})
  18. await page.mouse.click(0, 200, {button: "left"})
  19. await expect(page.locator('#custom-context-menu')).toHaveCount(0)
  20. })
  21. test('close context menu by clicking on a menu item', async ({ page }) => {
  22. await createRandomPage(page)
  23. await page.locator('span.bullet-container >> nth=0').click({button: "right"})
  24. await page.locator('#custom-context-menu .menu-link >> nth=1').click()
  25. await expect(page.locator('#custom-context-menu')).toHaveCount(0)
  26. })
  27. test('close context menu by clicking on a block', async ({ page, block }) => {
  28. await createRandomPage(page)
  29. await block.mustType('fist Block')
  30. await block.enterNext()
  31. await page.locator('span.bullet-container >> nth=-1').click({button: "right"})
  32. const elementHandle = page.locator('.block-content >> nth=0');
  33. const box = await elementHandle.boundingBox();
  34. expect(box).toBeTruthy()
  35. if (box) {
  36. await page.mouse.click(box.x + box.width - 5, box.y + box.height / 2);
  37. }
  38. await expect(page.locator('#custom-context-menu')).toHaveCount(0)
  39. })