dnd.spec.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. * When we drag and drop a block, it should always be moved under the target element,
  8. * unless the targer is the first element of its container. In that case, if we drop
  9. * it at the top half of the target, it should be moved on top of it.
  10. */
  11. test('drop "block b" to the upper left area of "block a", which is the first element of a container', async ({ page, block }) => {
  12. await createRandomPage(page)
  13. await block.mustFill('block a')
  14. await block.enterNext()
  15. await block.mustFill('block b')
  16. await block.escapeEditing()
  17. const bullet = page.locator('span.bullet-container >> nth=-1')
  18. const where = page.locator('.ls-block >> nth=0')
  19. await bullet.dragTo(where, {
  20. targetPosition: {
  21. x: 0,
  22. y: 0
  23. }
  24. })
  25. await page.keyboard.press('Escape')
  26. const pageElem = page.locator('.page-blocks-inner')
  27. await expect(pageElem).toHaveText('block b\nblock a', {useInnerText: true})
  28. })
  29. test('drop "block b" to the bottom left area of "block a", which is the first element of a container', async ({ page, block }) => {
  30. await createRandomPage(page)
  31. await page.fill('textarea >> nth=0', 'block a')
  32. await enterNextBlock(page)
  33. await page.fill('textarea >> nth=0', 'block b')
  34. await page.press('textarea >> nth=0', 'Escape')
  35. const bullet = page.locator('span.bullet-container >> nth=-1')
  36. const where = page.locator('.ls-block >> nth=0')
  37. await bullet.dragTo(where, {
  38. targetPosition: {
  39. x: 0,
  40. y: (await where.boundingBox())!.height * 0.75
  41. }
  42. })
  43. await page.keyboard.press('Escape')
  44. const pageElem = page.locator('.page-blocks-inner')
  45. await expect(pageElem).toHaveText('block a\nblock b', {useInnerText: true})
  46. })
  47. test('drop "block c" to the upper left area of "block b", which is the second element of a container', async ({ page, block }) => {
  48. await createRandomPage(page)
  49. await block.mustFill('block a')
  50. await block.enterNext()
  51. await block.mustFill('block b')
  52. await block.enterNext()
  53. await block.mustFill('block c')
  54. await block.escapeEditing()
  55. const bullet = page.locator('span.bullet-container >> nth=-1')
  56. const where = page.locator('.ls-block >> nth=1')
  57. await bullet.dragTo(where, {
  58. targetPosition: {
  59. x: 0,
  60. y: 0
  61. }
  62. })
  63. await page.keyboard.press('Escape')
  64. const pageElem = page.locator('.page-blocks-inner')
  65. await expect(pageElem).toHaveText('block a\nblock b\nblock c', {useInnerText: true})
  66. })
  67. test('drop "block c" to the bottom left area of "block a", which is the first element of a container', async ({ page, block }) => {
  68. await createRandomPage(page)
  69. await block.mustFill('block a')
  70. await block.enterNext()
  71. await block.mustFill('block b')
  72. await block.enterNext()
  73. await block.mustFill('block c')
  74. await block.escapeEditing()
  75. const bullet = page.locator('span.bullet-container >> nth=-1')
  76. const where = page.locator('.ls-block >> nth=0')
  77. await bullet.dragTo(where, {
  78. targetPosition: {
  79. x: 0,
  80. y: 0
  81. }
  82. })
  83. await page.keyboard.press('Escape')
  84. const pageElem = page.locator('.page-blocks-inner')
  85. await expect(pageElem).toHaveText('block c\nblock a\nblock b', {useInnerText: true})
  86. })