Files
ComfyUI_frontend/browser_tests/fixtures/utils/pointerEventHelpers.ts
Glary-Bot fddbbcafe8 test: add Playwright coverage for Slider.vue pressed state
Add e2e tests exercising the slide-start/slide-end events on the
reka-ui Slider component so that the setPressed callback (lines 21-24)
is reached during coverage collection.

- New sliderWidget.spec.ts with two tests: cursor-grabbing assertion
  during pointer hold, and value-change assertion via dragTo.
- New assertBoundingBox() utility that replaces the never-null (!)
  pattern on boundingBox() results with a typed guard that throws a
  descriptive error.
- Fix litegraphUtils.ts dragHorizontal to use assertBoundingBox.
2026-04-20 01:10:33 +00:00

63 lines
1.9 KiB
TypeScript

import type { Page } from '@playwright/test'
/**
* Headless Chromium does not track pointer captures initiated by
* synthetic PointerEvents (created via `new PointerEvent()`).
* Reka-ui's SliderImpl gates `slideEnd` emission on
* `target.hasPointerCapture(pointerId)`, which returns false in this
* scenario, preventing the pressed-state from clearing.
*
* This patch adds a shadow WeakMap tracker so that
* `setPointerCapture` / `hasPointerCapture` / `releasePointerCapture`
* work correctly for synthetic pointer IDs.
*
* Call once per page, before any slider interactions.
*/
export async function patchPointerCapture(page: Page): Promise<void> {
await page.evaluate(() => {
const captures = new WeakMap<Element, Set<number>>()
const origSet = Element.prototype.setPointerCapture
const origRelease = Element.prototype.releasePointerCapture
const origHas = Element.prototype.hasPointerCapture
Element.prototype.setPointerCapture = function (id: number) {
let ids = captures.get(this)
if (!ids) captures.set(this, (ids = new Set()))
ids.add(id)
try {
origSet.call(this, id)
} catch {
/* synthetic pointerId not tracked by browser */
}
}
Element.prototype.hasPointerCapture = function (id: number) {
return captures.get(this)?.has(id) ?? origHas.call(this, id)
}
Element.prototype.releasePointerCapture = function (id: number) {
captures.get(this)?.delete(id)
try {
origRelease.call(this, id)
} catch {
/* synthetic pointerId not tracked by browser */
}
}
})
}
export function dispatchPointerEvent({
selector,
type
}: {
selector: string
type: string
}) {
const el = document.querySelector(selector)
el?.dispatchEvent(
new PointerEvent(type, {
bubbles: true,
cancelable: true,
pointerId: 1,
pointerType: 'mouse'
})
)
}