dnd.spec.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { expect } from '@playwright/test'
  2. import { test } from './fixtures'
  3. import { createRandomPage, enterNextBlock } 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('textarea >> nth=0', 'block a')
  12. await enterNextBlock(page)
  13. await page.fill('textarea >> nth=0', 'block b')
  14. await page.press('textarea >> nth=0', 'Escape')
  15. const bullet = page.locator('span.bullet-container >> nth=-1')
  16. const where = page.locator('.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. await page.keyboard.press('Escape')
  24. const pageElem = page.locator('.page-blocks-inner')
  25. await expect(pageElem).toHaveText('block b\nblock a', {useInnerText: true})
  26. })
  27. test('drop to upper left', async ({ page, block }) => {
  28. await createRandomPage(page)
  29. await block.mustFill('block a')
  30. await block.enterNext()
  31. await block.mustFill('block b')
  32. await block.escapeEditing()
  33. const bullet = page.locator('span.bullet-container >> nth=-1')
  34. const where = page.locator('.ls-block >> nth=0')
  35. await bullet.dragTo(where, {
  36. targetPosition: {
  37. x: 0,
  38. y: 0
  39. }
  40. })
  41. await page.keyboard.press('Escape')
  42. const pageElem = page.locator('.page-blocks-inner')
  43. await expect(pageElem).toHaveText('block b\nblock a', {useInnerText: true})
  44. })
  45. test('drop to bottom left', async ({ page }) => {
  46. await createRandomPage(page)
  47. await page.fill('textarea >> nth=0', 'block a')
  48. await enterNextBlock(page)
  49. await page.fill('textarea >> nth=0', 'block b')
  50. await page.press('textarea >> nth=0', 'Escape')
  51. const bullet = page.locator('span.bullet-container >> nth=-1')
  52. const where = page.locator('.ls-block >> nth=0')
  53. await bullet.dragTo(where, {
  54. targetPosition: {
  55. x: 30,
  56. y: (await where.boundingBox()).height * 0.75
  57. }
  58. })
  59. await page.keyboard.press('Escape')
  60. const pageElem = page.locator('.page-blocks-inner')
  61. await expect(pageElem).toHaveText('block a\nblock b', {useInnerText: true})
  62. })