2
0

prompt-drop-file.spec.ts 1.0 KB

123456789101112131415161718192021222324252627282930
  1. import { test, expect } from "../fixtures"
  2. import { promptSelector } from "../selectors"
  3. test("dropping an image file adds an attachment", async ({ page, gotoSession }) => {
  4. await gotoSession()
  5. const prompt = page.locator(promptSelector)
  6. await prompt.click()
  7. const png = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO3+4uQAAAAASUVORK5CYII="
  8. const dt = await page.evaluateHandle((b64) => {
  9. const dt = new DataTransfer()
  10. const bytes = Uint8Array.from(atob(b64), (c) => c.charCodeAt(0))
  11. const file = new File([bytes], "drop.png", { type: "image/png" })
  12. dt.items.add(file)
  13. return dt
  14. }, png)
  15. await page.dispatchEvent("body", "drop", { dataTransfer: dt })
  16. const img = page.locator('img[alt="drop.png"]').first()
  17. await expect(img).toBeVisible()
  18. const remove = page.getByRole("button", { name: "Remove attachment" }).first()
  19. await expect(remove).toBeVisible()
  20. await img.hover()
  21. await remove.click()
  22. await expect(page.locator('img[alt="drop.png"]')).toHaveCount(0)
  23. })