context-menu.spec.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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=0').click()
  25. await expect(page.locator('#custom-context-menu')).toHaveCount(0)
  26. })
  27. test('close context menu by clicking on a block', async ({ page }) => {
  28. await createRandomPage(page)
  29. await page.locator('span.bullet-container >> nth=0').click({button: "right"})
  30. const elementHandle = await page.$('.block-content >> nth=0');
  31. const box = await elementHandle.boundingBox();
  32. await page.mouse.click(box.x + box.width - 5, box.y + box.height / 2);
  33. await expect(page.locator('#custom-context-menu')).toHaveCount(0)
  34. })