dnd.spec.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { expect } from '@playwright/test'
  2. import { test } from './fixtures'
  3. import { createRandomPage } from './utils'
  4. /**
  5. * Drag and Drop tests.
  6. *
  7. * NOTE: x = 30 is an estimation of left position of the drop target.
  8. */
  9. test('drop to left center', async ({ page }) => {
  10. await createRandomPage(page)
  11. await page.fill(':nth-match(textarea, 1)', 'block a')
  12. await page.press(':nth-match(textarea, 1)', 'Enter')
  13. await page.fill(':nth-match(textarea, 1)', 'block b')
  14. await page.press(':nth-match(textarea, 1)', 'Escape')
  15. const bullet = page.locator('span.bullet-container >> nth=-1')
  16. const where = page.locator('div.ls-block >> nth=0')
  17. await bullet.dragTo(where, {
  18. targetPosition: {
  19. x: 30,
  20. y: (await where.boundingBox()).height * 0.5
  21. }
  22. })
  23. expect.soft(await page.locator('div.ls-block >> nth=0').innerText()).toBe("block b")
  24. expect.soft(await page.locator('div.ls-block >> nth=1').innerText()).toBe("block a")
  25. })
  26. test('drop to upper left', async ({ page }) => {
  27. await createRandomPage(page)
  28. await page.fill(':nth-match(textarea, 1)', 'block a')
  29. await page.press(':nth-match(textarea, 1)', 'Enter')
  30. await page.fill(':nth-match(textarea, 1)', 'block b')
  31. await page.press(':nth-match(textarea, 1)', 'Escape')
  32. const bullet = page.locator('span.bullet-container >> nth=-1')
  33. const where = page.locator('div.ls-block >> nth=0')
  34. await bullet.dragTo(where, {
  35. targetPosition: {
  36. x: 30,
  37. y: 5
  38. }
  39. })
  40. expect.soft(await page.locator('div.ls-block >> nth=0').innerText()).toBe("block b")
  41. expect.soft(await page.locator('div.ls-block >> nth=1').innerText()).toBe("block a")
  42. })
  43. test('drop to bottom left', async ({ page }) => {
  44. await createRandomPage(page)
  45. await page.fill(':nth-match(textarea, 1)', 'block a')
  46. await page.press(':nth-match(textarea, 1)', 'Enter')
  47. await page.fill(':nth-match(textarea, 1)', 'block b')
  48. await page.press(':nth-match(textarea, 1)', 'Escape')
  49. const bullet = page.locator('span.bullet-container >> nth=-1')
  50. const where = page.locator('div.ls-block >> nth=0')
  51. await bullet.dragTo(where, {
  52. targetPosition: {
  53. x: 30,
  54. y: (await where.boundingBox()).height * 0.75
  55. }
  56. })
  57. expect.soft(await page.locator('div.ls-block >> nth=0').innerText()).toBe("block a")
  58. expect.soft(await page.locator('div.ls-block >> nth=1').innerText()).toBe("block b")
  59. })