cursor-boundary.spec.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { expect, test } from "@playwright/test"
  2. test.describe("Cursor boundary behavior", () => {
  3. test.beforeEach(async ({ page }) => {
  4. await page.goto("/editor?e2e=true")
  5. })
  6. test("typing after bold delimiter does not trap cursor", async ({ page }) => {
  7. const blockIds = await page.evaluate(() => window.__testUtils__?.getBlockIds())
  8. // Second block contains "**block**" in its content
  9. const id = blockIds![1]
  10. // Position cursor after "**block**" (14 chars into the paragraph text)
  11. await page.evaluate(
  12. ({ bid, from, to }: { bid: string; from: number; to: number }) =>
  13. window.__testUtils__?.selectText(bid, from, to),
  14. { bid: id, from: 14, to: 14 },
  15. )
  16. await page.keyboard.type("XX")
  17. const content = await page.evaluate(() => window.__testUtils__?.getContent())
  18. expect(content).toContain("XX")
  19. })
  20. test("typing before bold delimiter flows continuously", async ({ page }) => {
  21. const blockIds = await page.evaluate(() => window.__testUtils__?.getBlockIds())
  22. const id = blockIds![1]
  23. // Position cursor right before "**block**" — "Each **" = 5 chars
  24. await page.evaluate(
  25. ({ bid, from, to }: { bid: string; from: number; to: number }) =>
  26. window.__testUtils__?.selectText(bid, from, to),
  27. { bid: id, from: 5, to: 5 },
  28. )
  29. await page.keyboard.type("YY")
  30. const content = await page.evaluate(() => window.__testUtils__?.getContent())
  31. expect(content).toContain("YY")
  32. })
  33. test("typing after strikethrough delimiter does not trap cursor", async ({ page }) => {
  34. // The initial content doesn't have ~~strikethrough~~, so use replaceContent
  35. const blockIds = await page.evaluate(() => window.__testUtils__?.getBlockIds())
  36. const id = blockIds![0]
  37. await page.evaluate(
  38. ({ bid }: { bid: string }) =>
  39. window.__testUtils__?.replaceContent(bid, "hello ~~world~~ test"),
  40. { bid: id },
  41. )
  42. await page.evaluate(
  43. ({ bid, from, to }: { bid: string; from: number; to: number }) =>
  44. window.__testUtils__?.selectText(bid, from, to),
  45. { bid: id, from: 16, to: 16 },
  46. )
  47. await page.keyboard.type("ZZ")
  48. const content = await page.evaluate(() => window.__testUtils__?.getContent())
  49. expect(content).toContain("ZZ")
  50. })
  51. })