40 lines
2.2 KiB
JavaScript
40 lines
2.2 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
|
|
// Call with a fresh Playwright page and the local Vite fixture; all API calls
|
|
// are intercepted, so this check cannot modify a deployed backend.
|
|
export async function runPurgeFailureChecks(page, failure = 'http') {
|
|
await page.route('**/*', route => {
|
|
const url = new URL(route.request().url())
|
|
return url.hostname === '127.0.0.1' ? route.continue() : route.abort()
|
|
})
|
|
await page.route('**/admin/**', async route => {
|
|
const url = new URL(route.request().url())
|
|
const headers = { 'access-control-allow-origin': '*', 'access-control-allow-headers': '*', 'access-control-allow-methods': '*' }
|
|
if (route.request().method() === 'OPTIONS') return route.fulfill({ status: 204, headers })
|
|
if (url.pathname === '/admin/trash/list') {
|
|
return route.fulfill({ json: { code: 200, detail: {
|
|
page: 1, size: 20, total: 1,
|
|
data: [{ id: 900001, name: 'isolated-check.txt', code: 'CHECK001', size: 16,
|
|
isTrashPurged: false, isTrashPermanent: true, trashReason: 'manual' }],
|
|
capabilities: { batch: true, filters: true, customRetention: true },
|
|
summary: { total: 1, recoverable: 1, purged: 0 }
|
|
} }, headers })
|
|
}
|
|
if (url.pathname === '/admin/trash/batch') {
|
|
assert.deepEqual(route.request().postDataJSON(), { action: 'purge', ids: [900001] })
|
|
return failure === 'network' ? route.abort() : route.fulfill({ status: 500, json: { detail: '测试服务暂时不可用' }, headers })
|
|
}
|
|
throw new Error(`Unexpected API request: ${url.pathname}`)
|
|
})
|
|
await page.goto('http://127.0.0.1:5180/theme-assets/tests/trash-workflow.html')
|
|
await page.getByRole('button', { name: '彻底删除', exact: true }).click()
|
|
const dialog = page.getByRole('dialog')
|
|
await dialog.getByRole('button', { name: '确认清理 1 项' }).click()
|
|
await dialog.getByRole('alert').waitFor({ state: 'visible', timeout: 4000 })
|
|
assert.ok((await dialog.getByRole('alert').textContent()).trim())
|
|
assert.equal(await page.locator('article').count(), 1)
|
|
await dialog.getByRole('button', { name: '取消', exact: true }).click()
|
|
await page.getByRole('button', { name: '彻底删除', exact: true }).click()
|
|
assert.equal(await page.getByRole('dialog').getByRole('alert').count(), 0)
|
|
}
|