mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 14:38:24 +00:00
* feat(provider): vendor and adapt pi model generator - Vendor generate-models.ts, model-data.ts, and models-dev-reasoning-options.ts from @earendil-works/pi tag v0.82.1 - Adapt imports to use @earendil-works/pi-ai and expose generateModels programmatic function - Add compare.test.ts to verify vendored generator against original built-in catalog - Add packages/core/src/provider/generator to eslint ignores * feat(provider): add provider and model sync api and ui * feat(webui): add checkbox for existing providers and clean dialog description * feat(webui): add expand all and collapse all to sync providers dialog * refactor(provider): remove compare.test.ts and cli overhead from generate-models * fix(provider): add 30s timeout and strict error handling to sync catalog fetching * fix(e2e): eliminate drag-and-drop race condition on webkit Allow requestAnimationFrame collision updates to settle in dragCard helper before releasing pointer, and scope fileCard locator via data-testid to avoid matching sidebar tree items.
56 lines
2.1 KiB
TypeScript
56 lines
2.1 KiB
TypeScript
import type { Locator, Page } from '@playwright/test'
|
|
|
|
/**
|
|
* Performs a pointer drag from one card to another. dnd-kit v6 uses a
|
|
* `PointerSensor` with a 10px distance activation constraint, and WebKit only
|
|
* reliably starts the drag when pointer moves are delivered in separate,
|
|
* awaited batches (a single fast `mouse.move(steps)` can be coalesced before
|
|
* the drag activates, losing the drop). Moves are therefore chunked with
|
|
* intermediate waits so the activation and drag move handlers run between
|
|
* batches on every browser.
|
|
*/
|
|
export async function dragCard(page: Page, source: Locator, target: Locator): Promise<void> {
|
|
const sourceBox = (await source.boundingBox())!
|
|
const targetBox = (await target.boundingBox())!
|
|
if (!sourceBox || !targetBox) {
|
|
throw new Error('Drag source or target has no bounding box')
|
|
}
|
|
|
|
const fromX = sourceBox.x + sourceBox.width / 2
|
|
const fromY = sourceBox.y + sourceBox.height / 2
|
|
const toX = targetBox.x + targetBox.width / 2
|
|
const toY = targetBox.y + targetBox.height / 2
|
|
|
|
await page.mouse.move(fromX, fromY)
|
|
await page.mouse.down()
|
|
|
|
const dx = toX - fromX
|
|
const dy = toY - fromY
|
|
const dist = Math.hypot(dx, dy)
|
|
|
|
// Step past the 10px activation constraint to trigger drag activation
|
|
// and give the browser a brief moment for status to become 'dragging'
|
|
const activationRatio = dist > 0 ? Math.min(1, 15 / dist) : 1
|
|
await page.mouse.move(fromX + dx * activationRatio, fromY + dy * activationRatio)
|
|
await page.waitForTimeout(50)
|
|
|
|
// Move in several chunks so the intermediate dragmove handlers run
|
|
const chunks = 8
|
|
for (let i = 1; i <= chunks; i++) {
|
|
const x = fromX + (dx * i) / chunks
|
|
const y = fromY + (dy * i) / chunks
|
|
await page.mouse.move(x, y)
|
|
await page.waitForTimeout(20)
|
|
}
|
|
|
|
// Ensure pointer is directly over target center and allow requestAnimationFrame
|
|
// and collision microtasks to settle before triggering drop
|
|
await page.mouse.move(toX, toY)
|
|
await page.evaluate(
|
|
() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))),
|
|
)
|
|
await page.waitForTimeout(100)
|
|
|
|
await page.mouse.up()
|
|
}
|