import type { Page } from '@playwright/test' /** 在「待办」列的快速新增输入框里录入一条任务 */ export async function addTask(page: Page, title: string): Promise { const input = page.getByLabel('添加任务').first() await input.fill(title) await input.press('Enter') } /** * 把指定标题的卡片拖到目标列。 * * SortableJS 用的是 pointer/mouse 事件而不是 HTML5 拖放, * 且依赖拖动过程中的 pointermove 来判定落点,因此必须分步移动鼠标, * 不能只做一次「按下 → 移动 → 抬起」。 */ export async function dragCardToColumn( page: Page, title: string, columnId: string, ): Promise { const card = page.locator('article').filter({ hasText: title }).first() const target = page.locator(`[data-column-id="${columnId}"]`) const sourceBox = await card.boundingBox() const targetBox = await target.boundingBox() if (!sourceBox || !targetBox) throw new Error('无法定位拖拽源或目标元素') const startX = sourceBox.x + sourceBox.width / 2 const startY = sourceBox.y + sourceBox.height / 2 await page.mouse.move(startX, startY) await page.mouse.down() // 先小幅移动,让 Sortable 进入拖拽状态 await page.mouse.move(startX, startY + 12, { steps: 5 }) await page.mouse.move(targetBox.x + targetBox.width / 2, targetBox.y + 30, { steps: 20 }) await page.mouse.up() } /** 打开「备份与恢复」面板 */ export async function openBackupPanel(page: Page): Promise { await page.getByRole('button', { name: '备份' }).click() }