|
|
|
@ -13,6 +13,14 @@ async function main() {
|
|
|
|
const browser = await chromium.launch({ channel: 'chrome', headless: true })
|
|
|
|
const browser = await chromium.launch({ channel: 'chrome', headless: true })
|
|
|
|
const context = await browser.newContext({ viewport: { width: 1440, height: 900 } })
|
|
|
|
const context = await browser.newContext({ viewport: { width: 1440, height: 900 } })
|
|
|
|
const page = await context.newPage()
|
|
|
|
const page = await context.newPage()
|
|
|
|
|
|
|
|
await page.addInitScript(() => {
|
|
|
|
|
|
|
|
window.qaDragTrace = []
|
|
|
|
|
|
|
|
for (const type of ['dragstart', 'dragover', 'drop', 'dragend']) document.addEventListener(type, event => {
|
|
|
|
|
|
|
|
const row = event.target.closest?.('[data-resource-node]')
|
|
|
|
|
|
|
|
window.qaDragTrace.push({ type, node: row?.getAttribute('data-resource-node'), target: event.target.className?.baseVal || event.target.className, y: event.clientY, top: row?.getBoundingClientRect().top, height: row?.getBoundingClientRect().height })
|
|
|
|
|
|
|
|
if (window.qaDragTrace.length > 50) window.qaDragTrace.shift()
|
|
|
|
|
|
|
|
}, true)
|
|
|
|
|
|
|
|
})
|
|
|
|
const result = { errors: [], warnings: [], passed: [] }
|
|
|
|
const result = { errors: [], warnings: [], passed: [] }
|
|
|
|
let rootId
|
|
|
|
let rootId
|
|
|
|
let token
|
|
|
|
let token
|
|
|
|
@ -35,6 +43,21 @@ async function main() {
|
|
|
|
await row(id).hover()
|
|
|
|
await row(id).hover()
|
|
|
|
await row(id).locator(`[data-node-action="${command}"]`).click()
|
|
|
|
await row(id).locator(`[data-node-action="${command}"]`).click()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function drag(id, targetId, position) {
|
|
|
|
|
|
|
|
currentStep = 'drag ' + position
|
|
|
|
|
|
|
|
await page.locator('.outline-tree').evaluate(async element => { await Promise.all(element.getAnimations({ subtree: true }).map(animation => animation.finished.catch(() => {}))) })
|
|
|
|
|
|
|
|
await row(targetId).scrollIntoViewIfNeeded()
|
|
|
|
|
|
|
|
const source = await row(id).boundingBox()
|
|
|
|
|
|
|
|
const target = await row(targetId).boundingBox()
|
|
|
|
|
|
|
|
await page.mouse.move(source.x + 100, source.y + source.height / 2)
|
|
|
|
|
|
|
|
await page.mouse.down()
|
|
|
|
|
|
|
|
await page.mouse.move(source.x + 110, source.y + source.height / 2, { steps: 4 })
|
|
|
|
|
|
|
|
await page.mouse.move(target.x + 100, target.y + (position === 'before' ? 2 : target.height - 2), { steps: 12 })
|
|
|
|
|
|
|
|
await page.mouse.up()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
async function childOrder() {
|
|
|
|
|
|
|
|
return (await api('/management')).nodes.filter(node => node.parentId === rootId).map(node => node.id)
|
|
|
|
|
|
|
|
}
|
|
|
|
async function triggerFocused(id) {
|
|
|
|
async function triggerFocused(id) {
|
|
|
|
await page.waitForFunction(id => document.activeElement?.closest('[data-resource-node]')?.getAttribute('data-resource-node') === String(id), id, { timeout: 5000 }).catch(async error => {
|
|
|
|
await page.waitForFunction(id => document.activeElement?.closest('[data-resource-node]')?.getAttribute('data-resource-node') === String(id), id, { timeout: 5000 }).catch(async error => {
|
|
|
|
result.focusDiagnostic = await page.evaluate(() => ({ active: document.activeElement?.outerHTML.slice(0, 1000) }))
|
|
|
|
result.focusDiagnostic = await page.evaluate(() => ({ active: document.activeElement?.outerHTML.slice(0, 1000) }))
|
|
|
|
@ -50,9 +73,10 @@ async function main() {
|
|
|
|
await page.waitForURL(url => !url.hash.includes('/login'))
|
|
|
|
await page.waitForURL(url => !url.hash.includes('/login'))
|
|
|
|
token = (await context.cookies()).find(cookie => cookie.name === 'Admin-Token').value
|
|
|
|
token = (await context.cookies()).find(cookie => cookie.name === 'Admin-Token').value
|
|
|
|
rootId = await api('/nodes', 'POST', { name: marker + '章' })
|
|
|
|
rootId = await api('/nodes', 'POST', { name: marker + '章' })
|
|
|
|
await api('/nodes', 'POST', { name: marker + '甲节', parentId: rootId })
|
|
|
|
const firstId = await api('/nodes', 'POST', { name: marker + '甲节', parentId: rootId })
|
|
|
|
const childId = await api('/nodes', 'POST', { name: marker + '乙节', parentId: rootId })
|
|
|
|
const childId = await api('/nodes', 'POST', { name: marker + '乙节', parentId: rootId })
|
|
|
|
await page.goto(origin + '/#/platform-course-resources/index')
|
|
|
|
const thirdId = await api('/nodes', 'POST', { name: marker + '丙节', parentId: rootId })
|
|
|
|
|
|
|
|
await page.goto(origin + '/#' + (process.env.QA_RESOURCE_ROUTE || '/platform-course-resources/index'))
|
|
|
|
await page.getByRole('heading', { name: '课程资源', exact: true }).waitFor()
|
|
|
|
await page.getByRole('heading', { name: '课程资源', exact: true }).waitFor()
|
|
|
|
await page.getByRole('button', { name: '展开全部', exact: true }).click()
|
|
|
|
await page.getByRole('button', { name: '展开全部', exact: true }).click()
|
|
|
|
await row(rootId).locator('.node-name').click()
|
|
|
|
await row(rootId).locator('.node-name').click()
|
|
|
|
@ -102,6 +126,47 @@ async function main() {
|
|
|
|
await triggerFocused(childId)
|
|
|
|
await triggerFocused(childId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.passed.push('inline move actions update numbering and preserve visible focus')
|
|
|
|
result.passed.push('inline move actions update numbering and preserve visible focus')
|
|
|
|
|
|
|
|
let loadedOrder = page.waitForResponse(response => response.url().endsWith('/course-resources/management') && response.request().method() === 'GET')
|
|
|
|
|
|
|
|
await drag(thirdId, firstId, 'before')
|
|
|
|
|
|
|
|
await loadedOrder
|
|
|
|
|
|
|
|
await page.locator('.el-loading-mask').first().waitFor({ state: 'hidden' })
|
|
|
|
|
|
|
|
assert.deepEqual(await childOrder(), [thirdId, firstId, childId])
|
|
|
|
|
|
|
|
await page.reload()
|
|
|
|
|
|
|
|
await page.getByRole('heading', { name: '课程资源', exact: true }).waitFor()
|
|
|
|
|
|
|
|
await page.getByRole('button', { name: '展开全部', exact: true }).click()
|
|
|
|
|
|
|
|
await row(thirdId).waitFor()
|
|
|
|
|
|
|
|
assert.equal(await row(thirdId).locator('.node-number').innerText(), (await row(rootId).locator('.node-number').innerText()) + '.1')
|
|
|
|
|
|
|
|
result.passed.push('dragging across two siblings persists the order after reload')
|
|
|
|
|
|
|
|
loadedOrder = page.waitForResponse(response => response.url().endsWith('/course-resources/management') && response.request().method() === 'GET')
|
|
|
|
|
|
|
|
await drag(thirdId, childId, 'after')
|
|
|
|
|
|
|
|
await loadedOrder
|
|
|
|
|
|
|
|
await page.locator('.el-loading-mask').first().waitFor({ state: 'hidden' })
|
|
|
|
|
|
|
|
assert.deepEqual(await childOrder(), [firstId, childId, thirdId])
|
|
|
|
|
|
|
|
const moveRoute = new RegExp('/api/course-resources/nodes/' + thirdId + '/move$')
|
|
|
|
|
|
|
|
let attempts = 0
|
|
|
|
|
|
|
|
await page.route(moveRoute, async route => {
|
|
|
|
|
|
|
|
if (++attempts === 2) return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ code: 400, msg: '验收:排序保存失败' }) })
|
|
|
|
|
|
|
|
return route.continue()
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
loadedOrder = page.waitForResponse(response => response.url().endsWith('/course-resources/management') && response.request().method() === 'GET')
|
|
|
|
|
|
|
|
await drag(thirdId, firstId, 'before')
|
|
|
|
|
|
|
|
await loadedOrder
|
|
|
|
|
|
|
|
await page.getByText('验收:排序保存失败', { exact: true }).waitFor()
|
|
|
|
|
|
|
|
await page.locator('.el-loading-mask').first().waitFor({ state: 'hidden' })
|
|
|
|
|
|
|
|
assert.deepEqual(await childOrder(), [firstId, thirdId, childId])
|
|
|
|
|
|
|
|
assert.equal(await row(thirdId).locator('.node-number').innerText(), (await row(rootId).locator('.node-number').innerText()) + '.2')
|
|
|
|
|
|
|
|
await page.unroute(moveRoute)
|
|
|
|
|
|
|
|
result.passed.push('interrupted sorting shows the rejection and reloads the actual saved order')
|
|
|
|
|
|
|
|
loadedOrder = page.waitForResponse(response => response.url().endsWith('/course-resources/management') && response.request().method() === 'GET')
|
|
|
|
|
|
|
|
await drag(thirdId, childId, 'after')
|
|
|
|
|
|
|
|
await loadedOrder
|
|
|
|
|
|
|
|
await page.locator('.el-loading-mask').first().waitFor({ state: 'hidden' })
|
|
|
|
|
|
|
|
await drag(firstId, leafId, 'before')
|
|
|
|
|
|
|
|
assert.deepEqual(await childOrder(), [firstId, childId, thirdId])
|
|
|
|
|
|
|
|
assert.equal((await api('/management')).nodes.find(node => node.id === leafId).parentId, childId)
|
|
|
|
|
|
|
|
result.passed.push('reverse drag works and cross-parent dropping preserves hierarchy')
|
|
|
|
|
|
|
|
await page.screenshot({ path: path.join(reports, 'drag-saved.png'), fullPage: true, animations: 'disabled' })
|
|
|
|
|
|
|
|
await page.locator('.outline-panel').screenshot({ path: path.join(reports, 'outline-actions.png'), animations: 'disabled' })
|
|
|
|
await action(childId, 'delete')
|
|
|
|
await action(childId, 'delete')
|
|
|
|
await page.locator('.el-message-box').getByRole('button', { name: '取消', exact: true }).click()
|
|
|
|
await page.locator('.el-message-box').getByRole('button', { name: '取消', exact: true }).click()
|
|
|
|
await triggerFocused(childId)
|
|
|
|
await triggerFocused(childId)
|
|
|
|
@ -117,6 +182,7 @@ async function main() {
|
|
|
|
console.log('PASS: selected/hover inline actions, empty badges, upload, add, rename, move and delete without browser warnings')
|
|
|
|
console.log('PASS: selected/hover inline actions, empty badges, upload, add, rename, move and delete without browser warnings')
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
result.failure = error.message
|
|
|
|
result.failure = error.message
|
|
|
|
|
|
|
|
result.dragTrace = await page.evaluate(() => window.qaDragTrace)
|
|
|
|
await page.screenshot({ path: path.join(reports, 'failure.png'), fullPage: true, animations: 'disabled' })
|
|
|
|
await page.screenshot({ path: path.join(reports, 'failure.png'), fullPage: true, animations: 'disabled' })
|
|
|
|
throw error
|
|
|
|
throw error
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
|