|
|
|
|
@ -7,7 +7,7 @@ const origin = process.env.QA_ORIGIN
|
|
|
|
|
const username = process.env.QA_ADMIN_USERNAME
|
|
|
|
|
const password = process.env.QA_ADMIN_PASSWORD
|
|
|
|
|
assert(origin && username && password, 'Provide the authorized QA origin and admin credentials')
|
|
|
|
|
const reports = path.resolve(process.env.QA_REPORT_DIR || 'tests/e2e/reports/course-resource-menu-focus')
|
|
|
|
|
const reports = path.resolve(process.env.QA_REPORT_DIR || 'tests/e2e/reports/course-resource-row-actions')
|
|
|
|
|
fs.mkdirSync(reports, { recursive: true })
|
|
|
|
|
async function main() {
|
|
|
|
|
const browser = await chromium.launch({ channel: 'chrome', headless: true })
|
|
|
|
|
@ -17,7 +17,7 @@ async function main() {
|
|
|
|
|
let rootId
|
|
|
|
|
let token
|
|
|
|
|
let currentStep = 'login'
|
|
|
|
|
const marker = 'QA_MENU_FOCUS_' + Date.now() + '_'
|
|
|
|
|
const marker = 'QA_ROW_ACTIONS_' + Date.now() + '_'
|
|
|
|
|
page.on('pageerror', error => result.errors.push(error.message))
|
|
|
|
|
page.on('console', message => {
|
|
|
|
|
if (['warning', 'error'].includes(message.type())) result.warnings.push({ step: currentStep, message: message.text() })
|
|
|
|
|
@ -29,17 +29,18 @@ async function main() {
|
|
|
|
|
assert.equal(response.status(), 200, method + ' ' + endpoint)
|
|
|
|
|
return (await response.json()).data
|
|
|
|
|
}
|
|
|
|
|
async function menu(id, command) {
|
|
|
|
|
const row = id => page.locator(`[data-resource-node="${id}"]`)
|
|
|
|
|
async function action(id, command) {
|
|
|
|
|
currentStep = command
|
|
|
|
|
await page.locator(`[data-resource-node="${id}"] .el-dropdown`).click()
|
|
|
|
|
await page.locator('.el-dropdown-menu:visible').getByText(command, { exact: true }).click()
|
|
|
|
|
await row(id).hover()
|
|
|
|
|
await row(id).locator(`[data-node-action="${command}"]`).click()
|
|
|
|
|
}
|
|
|
|
|
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 => {
|
|
|
|
|
result.focusDiagnostic = await page.evaluate(id => ({ active: document.activeElement?.outerHTML.slice(0, 2000), trigger: document.querySelector(`[data-resource-node="${id}"] .el-dropdown`)?.outerHTML, menus: [...document.querySelectorAll('.el-dropdown-menu')].map(menu => ({ id: menu.id, labelledBy: menu.getAttribute('aria-labelledby') })) }), id)
|
|
|
|
|
result.focusDiagnostic = await page.evaluate(() => ({ active: document.activeElement?.outerHTML.slice(0, 1000) }))
|
|
|
|
|
throw error
|
|
|
|
|
})
|
|
|
|
|
assert(await page.locator(`[data-resource-node="${id}"] .el-dropdown button`).isVisible())
|
|
|
|
|
assert(await row(id).locator('.node-actions').isVisible())
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
await page.goto(origin + '/#/login')
|
|
|
|
|
@ -54,39 +55,66 @@ async function main() {
|
|
|
|
|
await page.goto(origin + '/#/platform-course-resources/index')
|
|
|
|
|
await page.getByRole('heading', { name: '课程资源', exact: true }).waitFor()
|
|
|
|
|
await page.getByRole('button', { name: '展开全部', exact: true }).click()
|
|
|
|
|
await page.locator(`[data-resource-node="${childId}"] .el-dropdown`).click()
|
|
|
|
|
await page.locator('.el-dropdown-menu:visible').waitFor()
|
|
|
|
|
await page.locator('.el-dropdown-menu:visible').getByText('重命名', { exact: true }).focus()
|
|
|
|
|
await page.keyboard.press('Escape')
|
|
|
|
|
await page.locator('.el-dropdown-menu:visible').waitFor({ state: 'hidden' })
|
|
|
|
|
await triggerFocused(childId)
|
|
|
|
|
result.passed.push('Escape closes the menu and restores focus')
|
|
|
|
|
await menu(childId, '重命名')
|
|
|
|
|
await row(rootId).locator('.node-name').click()
|
|
|
|
|
await page.getByRole('heading', { name: '课程资源', exact: true }).hover()
|
|
|
|
|
assert.equal(await row(rootId).locator('.node-actions button:visible').count(), 6)
|
|
|
|
|
assert.equal(await row(childId).locator('.file-count').innerText(), '空')
|
|
|
|
|
assert.equal(await row(childId).locator('.node-actions').isVisible(), false)
|
|
|
|
|
result.passed.push('selected row retains six inline actions; unselected empty rows retain their empty badge')
|
|
|
|
|
await row(childId).hover()
|
|
|
|
|
assert.equal(await row(childId).locator('.node-actions button:visible').count(), 6)
|
|
|
|
|
result.passed.push('hover reveals actions on an unselected row')
|
|
|
|
|
await row(childId).locator('.node-name').click()
|
|
|
|
|
for (const width of [1440, 1280, 1024]) {
|
|
|
|
|
await page.setViewportSize({ width, height: 900 })
|
|
|
|
|
await page.getByRole('heading', { name: '课程资源', exact: true }).hover()
|
|
|
|
|
assert.equal(await row(childId).locator('.node-actions button:visible').count(), 6)
|
|
|
|
|
assert(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth))
|
|
|
|
|
const outline = await page.locator('.outline-panel').boundingBox()
|
|
|
|
|
const last = await row(childId).locator('[data-node-action="delete"]').boundingBox()
|
|
|
|
|
assert(last.x >= outline.x && last.x + last.width <= outline.x + outline.width)
|
|
|
|
|
await page.screenshot({ path: path.join(reports, 'inline-actions-' + width + '.png'), fullPage: true, animations: 'disabled' })
|
|
|
|
|
}
|
|
|
|
|
result.passed.push('selected actions remain visible and inside the outline at 1440, 1280 and 1024 widths')
|
|
|
|
|
const chooser = page.waitForEvent('filechooser')
|
|
|
|
|
await action(childId, 'upload')
|
|
|
|
|
await (await chooser).setFiles([])
|
|
|
|
|
result.passed.push('inline attachment action opens the file chooser for its directory')
|
|
|
|
|
await action(childId, 'add')
|
|
|
|
|
await page.getByRole('textbox', { name: '请输入目录名称', exact: true }).fill(marker + '知识点')
|
|
|
|
|
const managementReload = page.waitForResponse(response => response.url().endsWith('/course-resources/management') && response.request().method() === 'GET')
|
|
|
|
|
await page.locator('.el-message-box').getByRole('button', { name: '确定', exact: true }).click()
|
|
|
|
|
const leaf = await (await managementReload).json()
|
|
|
|
|
const leafId = leaf.data.nodes.find(node => node.name === marker + '知识点').id
|
|
|
|
|
await row(leafId).locator('.node-name').waitFor()
|
|
|
|
|
assert.equal(await row(leafId).locator('[data-node-action="add"]').count(), 0)
|
|
|
|
|
result.passed.push('inline add creates a child and stops at the existing three-level limit')
|
|
|
|
|
await action(childId, 'rename')
|
|
|
|
|
await page.getByRole('textbox', { name: '请输入目录名称', exact: true }).fill(marker + '改名节')
|
|
|
|
|
await page.locator('.el-message-box').getByRole('button', { name: '确定', exact: true }).click()
|
|
|
|
|
await page.locator(`[data-resource-node="${childId}"] .node-name`).filter({ hasText: marker + '改名节' }).waitFor()
|
|
|
|
|
await triggerFocused(childId)
|
|
|
|
|
result.passed.push('rename dialog restores focus to the visible trigger')
|
|
|
|
|
for (const command of ['上移', '下移']) {
|
|
|
|
|
result.passed.push('rename dialog restores focus to the inline action')
|
|
|
|
|
for (const command of ['up', 'down']) {
|
|
|
|
|
const oldNumber = await page.locator(`[data-resource-node="${childId}"] .node-number`).innerText()
|
|
|
|
|
await menu(childId, command)
|
|
|
|
|
await action(childId, command)
|
|
|
|
|
await page.waitForFunction(({ id, oldNumber }) => document.querySelector(`[data-resource-node="${id}"] .node-number`)?.textContent !== oldNumber, { id: childId, oldNumber })
|
|
|
|
|
await triggerFocused(childId)
|
|
|
|
|
}
|
|
|
|
|
result.passed.push('move commands preserve focus outside the hidden menu')
|
|
|
|
|
await menu(childId, '删除')
|
|
|
|
|
result.passed.push('inline move actions update numbering and preserve visible focus')
|
|
|
|
|
await action(childId, 'delete')
|
|
|
|
|
await page.locator('.el-message-box').getByRole('button', { name: '取消', exact: true }).click()
|
|
|
|
|
await triggerFocused(childId)
|
|
|
|
|
assert((await api('/management')).nodes.some(node => node.id === childId))
|
|
|
|
|
result.passed.push('cancel deletion restores focus and preserves the directory')
|
|
|
|
|
await page.screenshot({ path: path.join(reports, 'menu-focus-restored.png'), fullPage: true, animations: 'disabled' })
|
|
|
|
|
await menu(childId, '删除')
|
|
|
|
|
await page.screenshot({ path: path.join(reports, 'inline-focus-restored.png'), fullPage: true, animations: 'disabled' })
|
|
|
|
|
await action(childId, 'delete')
|
|
|
|
|
await page.locator('.el-message-box').getByRole('button', { name: '确认删除', exact: true }).click()
|
|
|
|
|
await page.locator(`[data-resource-node="${childId}"]`).waitFor({ state: 'hidden' })
|
|
|
|
|
result.passed.push('confirmed deletion still removes the directory')
|
|
|
|
|
assert.deepEqual(result.errors, [])
|
|
|
|
|
assert.deepEqual(result.warnings, [])
|
|
|
|
|
console.log('PASS: rename, move and deletion focus restoration without browser warnings')
|
|
|
|
|
console.log('PASS: selected/hover inline actions, empty badges, upload, add, rename, move and delete without browser warnings')
|
|
|
|
|
} catch (error) {
|
|
|
|
|
result.failure = error.message
|
|
|
|
|
await page.screenshot({ path: path.join(reports, 'failure.png'), fullPage: true, animations: 'disabled' })
|