logseq/e2e-tests/context-menu.spec.ts

61 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-08-18 13:34:04 +00:00
import { expect } from '@playwright/test'
import { test } from './fixtures'
import { createRandomPage } from './utils'
test('open context menu', async ({ page }) => {
await createRandomPage(page)
await page.locator('span.bullet-container >> nth=0').click({button: "right"})
await expect(page.locator('#custom-context-menu')).toBeVisible()
})
test('close context menu on esc', async ({ page }) => {
await createRandomPage(page)
2022-08-22 10:52:36 +00:00
2022-08-18 13:34:04 +00:00
await page.locator('span.bullet-container >> nth=0').click({button: "right"})
await page.keyboard.press('Escape')
2022-08-22 10:52:36 +00:00
2022-08-18 13:34:04 +00:00
await expect(page.locator('#custom-context-menu')).toHaveCount(0)
})
test('close context menu by left clicking on empty space', async ({ page }) => {
await createRandomPage(page)
2022-08-22 10:52:36 +00:00
2022-08-18 13:34:04 +00:00
await page.locator('span.bullet-container >> nth=0').click({button: "right"})
await page.mouse.click(0, 200, {button: "left"})
2022-08-22 10:52:36 +00:00
2022-08-18 13:34:04 +00:00
await expect(page.locator('#custom-context-menu')).toHaveCount(0)
})
test('close context menu by clicking on a menu item', async ({ page }) => {
await createRandomPage(page)
await page.locator('span.bullet-container >> nth=0').click({button: "right"})
2022-08-22 10:52:36 +00:00
await page.locator('#custom-context-menu .menu-link >> nth=1').click()
2022-08-18 13:34:04 +00:00
await expect(page.locator('#custom-context-menu')).toHaveCount(0)
})
2022-08-22 10:52:36 +00:00
test('close context menu by clicking on a block', async ({ page, block }) => {
2022-08-18 13:34:04 +00:00
await createRandomPage(page)
2022-08-22 10:52:36 +00:00
await block.mustType('fist Block')
await block.enterNext()
2022-08-18 13:34:04 +00:00
2022-08-22 10:52:36 +00:00
await page.locator('span.bullet-container >> nth=-1').click({button: "right"})
2022-08-18 13:34:04 +00:00
2022-08-22 10:52:36 +00:00
const elementHandle = page.locator('.block-content >> nth=0');
2022-08-18 13:34:04 +00:00
2022-08-22 10:52:36 +00:00
const box = await elementHandle.boundingBox();
expect(box).toBeTruthy()
if (box) {
await page.mouse.click(box.x + box.width - 5, box.y + box.height / 2);
}
2022-08-18 13:34:04 +00:00
await expect(page.locator('#custom-context-menu')).toHaveCount(0)
})