feat: 全局撤销/重做(ADR-010)
This commit is contained in:
@@ -239,3 +239,44 @@ test('键盘方向键可以移动任务卡片', async ({ page }) => {
|
||||
await page.reload()
|
||||
await expect(page.locator('[data-column-id="todo"] article')).toHaveCount(1)
|
||||
})
|
||||
|
||||
test('Ctrl+Z 撤销创建、Ctrl+Shift+Z 重做,刷新后历史清空', async ({ page }) => {
|
||||
await addTask(page, '撤销测试 A')
|
||||
await addTask(page, '撤销测试 B')
|
||||
await expect(page.locator('article')).toHaveCount(2)
|
||||
|
||||
// 焦点从快速新增输入框移开,否则 Ctrl+Z 交给浏览器撤销文字
|
||||
await page.locator('body').click({ position: { x: 5, y: 5 } })
|
||||
|
||||
await page.keyboard.press('Control+z')
|
||||
await expect(page.locator('article')).toHaveCount(1)
|
||||
await expect(page.locator('article').filter({ hasText: '撤销测试 A' })).toBeVisible()
|
||||
|
||||
await page.keyboard.press('Control+z')
|
||||
await expect(page.locator('article')).toHaveCount(0)
|
||||
|
||||
await page.keyboard.press('Control+Shift+z')
|
||||
await expect(page.locator('article')).toHaveCount(1)
|
||||
|
||||
// 撤销结果真的落盘了
|
||||
await page.reload()
|
||||
await expect(page.locator('article')).toHaveCount(1)
|
||||
|
||||
// 但历史不落盘:刷新之后没有可撤销的步骤,卡片原地不动
|
||||
await page.locator('body').click({ position: { x: 5, y: 5 } })
|
||||
await page.keyboard.press('Control+z')
|
||||
await expect(page.getByText('没有可撤销的操作')).toBeVisible()
|
||||
await expect(page.locator('article')).toHaveCount(1)
|
||||
})
|
||||
|
||||
test('输入框内 Ctrl+Z 不劫持任务撤销', async ({ page }) => {
|
||||
await addTask(page, '不该被撤销')
|
||||
await expect(page.locator('article')).toHaveCount(1)
|
||||
|
||||
// 焦点停在快速新增输入框时,Ctrl+Z 属于文字输入,任务不该被撤销
|
||||
const input = page.getByLabel('添加任务').first()
|
||||
await input.click()
|
||||
await page.keyboard.press('Control+z')
|
||||
|
||||
await expect(page.locator('article')).toHaveCount(1)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user