suggestion-menu.spec.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { expect, test } from "@playwright/test"
  2. test.describe("Suggestion menu", () => {
  3. test.beforeEach(async ({ page }) => {
  4. await page.goto("/editor?e2e=true")
  5. })
  6. test("typing / opens the suggestion menu", async ({ page }) => {
  7. const firstBlock = page.locator("[data-block-id]").first()
  8. await firstBlock.focus()
  9. await page.keyboard.type("/")
  10. await expect(page.locator("[data-command-palette]")).toBeVisible({
  11. timeout: 3000,
  12. })
  13. })
  14. test("suggestion menu shows items with data-menu-item-index", async ({ page }) => {
  15. const firstBlock = page.locator("[data-block-id]").first()
  16. await firstBlock.focus()
  17. await page.keyboard.type("/")
  18. const menu = page.locator("[data-command-palette]")
  19. await expect(menu).toBeVisible({ timeout: 3000 })
  20. const items = menu.locator("[data-menu-item-index]")
  21. const count = await items.count()
  22. expect(count).toBeGreaterThan(0)
  23. })
  24. test("Escape closes the suggestion menu", async ({ page }) => {
  25. const firstBlock = page.locator("[data-block-id]").first()
  26. await firstBlock.focus()
  27. await page.keyboard.type("/")
  28. const menu = page.locator("[data-command-palette]")
  29. await expect(menu).toBeVisible({ timeout: 3000 })
  30. await page.keyboard.press("Escape")
  31. await expect(menu).not.toBeVisible()
  32. })
  33. test("ArrowDown highlights next item", async ({ page }) => {
  34. const firstBlock = page.locator("[data-block-id]").first()
  35. await firstBlock.focus()
  36. await page.keyboard.type("/")
  37. const menu = page.locator("[data-command-palette]")
  38. await expect(menu).toBeVisible({ timeout: 3000 })
  39. // First item should be highlighted initially
  40. const firstItem = menu.locator('[data-menu-item-index="0"]')
  41. await expect(firstItem).toHaveAttribute("data-highlighted")
  42. await page.keyboard.press("ArrowDown")
  43. // Second item should now be highlighted
  44. const secondItem = menu.locator('[data-menu-item-index="1"]')
  45. await expect(secondItem).toHaveAttribute("data-highlighted")
  46. })
  47. test("ArrowUp wraps to last item", async ({ page }) => {
  48. const firstBlock = page.locator("[data-block-id]").first()
  49. await firstBlock.focus()
  50. await page.keyboard.type("/")
  51. const menu = page.locator("[data-command-palette]")
  52. await expect(menu).toBeVisible({ timeout: 3000 })
  53. await page.keyboard.press("ArrowUp")
  54. const items = menu.locator("[data-menu-item-index]")
  55. const lastIndex = (await items.count()) - 1
  56. const lastItem = menu.locator(`[data-menu-item-index="${lastIndex}"]`)
  57. await expect(lastItem).toHaveAttribute("data-highlighted")
  58. })
  59. test("Enter selects the highlighted item and closes menu", async ({ page }) => {
  60. const firstBlock = page.locator("[data-block-id]").first()
  61. await firstBlock.focus()
  62. await page.keyboard.type("/")
  63. const menu = page.locator("[data-command-palette]")
  64. await expect(menu).toBeVisible({ timeout: 3000 })
  65. // Slash commands insert content — just verify the menu closes
  66. await page.keyboard.press("Enter")
  67. await expect(menu).not.toBeVisible()
  68. })
  69. })