test(e2e): add drag and drop test skeleton

pull/4591/head
Andelf 2022-03-10 17:25:56 +08:00 committed by Tienson Qin
parent 1b163d7bff
commit d985501186
1 changed files with 76 additions and 0 deletions

76
e2e-tests/dnd.spec.ts Normal file
View File

@ -0,0 +1,76 @@
import { expect } from '@playwright/test'
import { test } from './fixtures'
import { createRandomPage } from './utils'
/**
* Drag and Drop tests.
*
* NOTE: x = 30 is an estimation of left position of the drop target.
*/
test('drop to left center', async ({ page }) => {
await createRandomPage(page)
await page.fill(':nth-match(textarea, 1)', 'block a')
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.fill(':nth-match(textarea, 1)', 'block b')
await page.press(':nth-match(textarea, 1)', 'Escape')
const bullet = page.locator('span.bullet-container >> nth=-1')
const where = page.locator('div.ls-block >> nth=0')
await bullet.dragTo(where, {
targetPosition: {
x: 30,
y: (await where.boundingBox()).height * 0.5
}
})
expect.soft(await page.locator('div.ls-block >> nth=0').innerText()).toBe("block b")
expect.soft(await page.locator('div.ls-block >> nth=1').innerText()).toBe("block a")
})
test('drop to upper left', async ({ page }) => {
await createRandomPage(page)
await page.fill(':nth-match(textarea, 1)', 'block a')
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.fill(':nth-match(textarea, 1)', 'block b')
await page.press(':nth-match(textarea, 1)', 'Escape')
const bullet = page.locator('span.bullet-container >> nth=-1')
const where = page.locator('div.ls-block >> nth=0')
await bullet.dragTo(where, {
targetPosition: {
x: 30,
y: 5
}
})
expect.soft(await page.locator('div.ls-block >> nth=0').innerText()).toBe("block b")
expect.soft(await page.locator('div.ls-block >> nth=1').innerText()).toBe("block a")
})
test('drop to bottom left', async ({ page }) => {
await createRandomPage(page)
await page.fill(':nth-match(textarea, 1)', 'block a')
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.fill(':nth-match(textarea, 1)', 'block b')
await page.press(':nth-match(textarea, 1)', 'Escape')
const bullet = page.locator('span.bullet-container >> nth=-1')
const where = page.locator('div.ls-block >> nth=0')
await bullet.dragTo(where, {
targetPosition: {
x: 30,
y: (await where.boundingBox()).height * 0.75
}
})
expect.soft(await page.locator('div.ls-block >> nth=0').innerText()).toBe("block a")
expect.soft(await page.locator('div.ls-block >> nth=1').innerText()).toBe("block b")
})