fix(course-resources): match inline directory actions to reference

dev-QQq
chenyuan 4 weeks ago
parent 2c2f1be695
commit 73680c1070

@ -15,25 +15,20 @@
<div class="panel-head"><h2>课程大纲</h2><el-input v-model="keyword" :prefix-icon="Search" clearable placeholder="搜索目录或资源" /></div> <div class="panel-head"><h2>课程大纲</h2><el-input v-model="keyword" :prefix-icon="Search" clearable placeholder="搜索目录或资源" /></div>
<el-tree ref="treeRef" class="outline-tree" :data="tree" node-key="id" :props="{ label: 'name', children: 'children' }" :expand-on-click-node="false" :filter-node-method="filterNode" :current-node-key="selectedId" :default-expanded-keys="expandedKeys" highlight-current @node-click="selectNode" @node-expand="rememberExpand" @node-collapse="rememberCollapse"> <el-tree ref="treeRef" class="outline-tree" :data="tree" node-key="id" :props="{ label: 'name', children: 'children' }" :expand-on-click-node="false" :filter-node-method="filterNode" :current-node-key="selectedId" :default-expanded-keys="expandedKeys" highlight-current @node-click="selectNode" @node-expand="rememberExpand" @node-collapse="rememberCollapse">
<template #default="{ data }"> <template #default="{ data }">
<div class="outline-row" :data-resource-node="data.id"> <div class="outline-row" :class="{ 'is-selected': selectedId === data.id }" :data-resource-node="data.id">
<span class="node-number">{{ data.number }}</span> <span class="node-number">{{ data.number }}</span>
<span class="node-name" :title="data.name">{{ data.name }}</span> <span class="node-name" :title="data.name">{{ data.name }}</span>
<el-tag v-if="isTeacher && !data.ownerId" size="small" type="info">内置</el-tag> <el-tag v-if="isTeacher && !data.ownerId" size="small" type="info">内置</el-tag>
<span v-if="data.files.length" class="file-count">{{ data.files.length }}</span> <span class="file-count" :class="{ 'is-empty': !data.files.length }" :aria-label="`${data.name}本级资源${data.files.length}个`"><el-icon v-if="data.files.length"><Paperclip /></el-icon>{{ data.files.length || '空' }}</span>
<div class="node-actions" @click.stop> <div class="node-actions" @click.stop>
<el-button link :icon="Upload" title="上传资源" :aria-label="`上传资源到${data.name}`" @click="pickFiles(data)" /> <el-button link :icon="Paperclip" data-node-action="upload" title="上传资源" :aria-label="`上传资源到${data.name}`" @click="pickFiles(data)" />
<el-dropdown v-if="data.depth < 3 || data.editable" trigger="click" @command="command => queueNodeCommand(command, data)" @visible-change="visible => nodeMenuVisibility(visible, data)"> <el-button v-if="data.depth < 3" link :icon="Plus" data-node-action="add" title="新增下级目录" :aria-label="`在${data.name}下新增目录`" @click="addNode(data)" />
<el-button link :icon="MoreFilled" :aria-label="`${data.name}的目录操作`" />
<template #dropdown><el-dropdown-menu @pointerleave.capture="ignoreHiddenMenuLeave">
<el-dropdown-item v-if="data.depth < 3" command="add">新增下级目录</el-dropdown-item>
<template v-if="data.editable"> <template v-if="data.editable">
<el-dropdown-item command="rename">重命名</el-dropdown-item> <el-button link :icon="EditPen" data-node-action="rename" title="重命名" :aria-label="`重命名${data.name}`" @click="nodeAction('rename', data)" />
<el-dropdown-item command="up" :disabled="!canMove(data, -1)">上移</el-dropdown-item> <el-button link :icon="Top" data-node-action="up" title="上移" :aria-label="`上移${data.name}`" :disabled="!canMove(data, -1)" @click="nodeAction('up', data)" />
<el-dropdown-item command="down" :disabled="!canMove(data, 1)">下移</el-dropdown-item> <el-button link :icon="Bottom" data-node-action="down" title="下移" :aria-label="`下移${data.name}`" :disabled="!canMove(data, 1)" @click="nodeAction('down', data)" />
<el-dropdown-item command="delete" divided>删除</el-dropdown-item> <el-button link :icon="Delete" data-node-action="delete" title="删除目录" :aria-label="`删除${data.name}`" @click="nodeAction('delete', data)" />
</template> </template>
</el-dropdown-menu></template>
</el-dropdown>
</div> </div>
</div> </div>
</template> </template>
@ -76,7 +71,7 @@
<script setup> <script setup>
import { ref, computed, watch, nextTick, onActivated } from 'vue' import { ref, computed, watch, nextTick, onActivated } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import { Plus, Search, Upload, UploadFilled, MoreFilled } from '@element-plus/icons-vue' import { Plus, Search, Upload, UploadFilled, Paperclip, EditPen, Top, Bottom, Delete } from '@element-plus/icons-vue'
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
import * as api from '@/api/courseResource' import * as api from '@/api/courseResource'
import { buildResourceTree, flattenResourceTree, resourceType, resourceMatches, formatResourceSize, formatResourceDate, visibleForClass, downloadCourseFile } from '@/utils/courseResource' import { buildResourceTree, flattenResourceTree, resourceType, resourceMatches, formatResourceSize, formatResourceDate, visibleForClass, downloadCourseFile } from '@/utils/courseResource'
@ -160,31 +155,8 @@ function canMove(node, direction) {
const target = siblings.findIndex(item => item.id === node.id) + direction const target = siblings.findIndex(item => item.id === node.id) + direction
return target >= 0 && target < siblings.length return target >= 0 && target < siblings.length
} }
let pendingNodeCommand = null
function ignoreHiddenMenuLeave(event) {
// Element Plus focuses the menu on item leave, even during its exit transition.
if (event.currentTarget.closest('[aria-hidden="true"]')) event.stopPropagation()
}
function queueNodeCommand(command, node) {
pendingNodeCommand = { command, node }
// Closing is delayed by the dropdown; release its focused item immediately.
document.activeElement?.blur()
}
async function nodeMenuVisibility(visible, node) {
if (visible) return
const trigger = treeRef.value?.$el.querySelector(`[data-resource-node="${node.id}"] .el-dropdown button`)
const active = document.activeElement
const menuFocused = active?.closest('.el-dropdown-menu')?.getAttribute('aria-labelledby') === trigger?.id
const pending = pendingNodeCommand?.node.id === node.id ? pendingNodeCommand : null
if (pending) pendingNodeCommand = null
// Blur before aria-hidden changes; focus after the menu releases its focus trap.
if (menuFocused) active.blur()
await nextTick()
if (menuFocused || pending) trigger?.focus()
if (pending) await nodeAction(pending.command, pending.node)
}
async function nodeAction(command, node) { async function nodeAction(command, node) {
if (command === 'add') return addNode(node) selectNode(node)
try { try {
if (command === 'rename') { if (command === 'rename') {
const { value } = await ElMessageBox.prompt('请输入目录名称', '重命名', { inputValue: node.name, inputValidator: value => !!value?.trim() && value.trim().length <= 200 || '请输入1至200个字符', confirmButtonText: '确定', cancelButtonText: '取消' }) const { value } = await ElMessageBox.prompt('请输入目录名称', '重命名', { inputValue: node.name, inputValidator: value => !!value?.trim() && value.trim().length <= 200 || '请输入1至200个字符', confirmButtonText: '确定', cancelButtonText: '取消' })
@ -197,7 +169,8 @@ async function nodeAction(command, node) {
await api.deleteCourseResourceNode(node.id) await api.deleteCourseResourceNode(node.id)
} }
await load() await load()
treeRef.value?.$el.querySelector(`[data-resource-node="${node.id}"] .el-dropdown button`)?.focus() const row = treeRef.value?.$el.querySelector(`[data-resource-node="${node.id}"]`)
;(row?.querySelector(`[data-node-action="${command}"]:not(:disabled)`) || row?.querySelector('.node-actions button:not(:disabled)'))?.focus()
ElMessage.success('操作成功') ElMessage.success('操作成功')
} catch (error) { if (error !== 'cancel' && error !== 'close') console.error(error) } } catch (error) { if (error !== 'cancel' && error !== 'close') console.error(error) }
} }
@ -282,18 +255,18 @@ async function saveVisibility() {
h1 { margin: 0; font-size: var(--fs-page, 18px); font-weight: 600; } h1 { margin: 0; font-size: var(--fs-page, 18px); font-weight: 600; }
h2 { margin: 0; font-size: var(--fs-card, 14px); font-weight: 600; } h2 { margin: 0; font-size: var(--fs-card, 14px); font-weight: 600; }
.actions { flex-wrap: wrap; gap: 8px; :deep(.el-button + .el-button) { margin-left: 0; } } .actions { flex-wrap: wrap; gap: 8px; :deep(.el-button + .el-button) { margin-left: 0; } }
.management-columns { display: grid; grid-template-columns: minmax(340px, 38%) minmax(0, 1fr); gap: 16px; align-items: start; } .management-columns { display: grid; grid-template-columns: minmax(520px, 60%) minmax(0, 1fr); gap: 16px; align-items: start; }
.outline-panel, .resources-panel { background: #fff; border: 1px solid var(--border-color, #e5e7eb); border-radius: var(--r-card, 12px); min-width: 0; overflow: hidden; } .outline-panel, .resources-panel { background: #fff; border: 1px solid var(--border-color, #e5e7eb); border-radius: var(--r-card, 12px); min-width: 0; overflow: hidden; }
.panel-head { padding: 16px; gap: 12px; border-bottom: 1px solid #edf0f4; justify-content: space-between; } .panel-head { padding: 16px; gap: 12px; border-bottom: 1px solid #edf0f4; justify-content: space-between; }
.panel-head > h2 { white-space: nowrap; flex-shrink: 0; } .panel-head > h2 { white-space: nowrap; flex-shrink: 0; }
.panel-head :deep(.el-input) { width: 190px; min-width: 0; } .panel-head :deep(.el-input) { width: 190px; min-width: 0; }
.outline-tree { min-height: 480px; max-height: calc(100vh - 236px); overflow: auto; padding: 12px 6px; :deep(.el-tree-node__content) { height: 40px; border-radius: 6px; } :deep(.el-tree-node.is-current > .el-tree-node__content) { background: var(--edu-primary-soft, #eff6ff); } } .outline-tree { min-height: 480px; max-height: calc(100vh - 236px); overflow: auto; padding: 12px 6px; :deep(.el-tree-node__content) { height: 40px; border-radius: 6px; } :deep(.el-tree-node.is-current > .el-tree-node__content) { background: #e8f2fd; box-shadow: inset 3px 0 #3b658f; } }
.outline-row { flex: 1; min-width: 0; gap: 7px; padding-right: 8px; } .outline-row { flex: 1; min-width: 0; gap: 8px; padding-right: 10px; }
.node-number { font-size: 11px; color: #64748b; font-variant-numeric: tabular-nums; } .node-number { flex-shrink: 0; padding: 1px 7px; border: 1px solid #f1dca7; border-radius: 5px; background: #fcf5e5; font-size: 11px; font-weight: 600; color: #ad821e; font-variant-numeric: tabular-nums; }
.node-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; } .node-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.file-count { color: #94a3b8; font-size: 11px; } .file-count { display: inline-flex; flex-shrink: 0; align-items: center; justify-content: center; gap: 3px; min-width: 34px; padding: 2px 8px; border-radius: 12px; background: #e8f2fd; color: #3b658f; font-size: 11px; font-weight: 600; line-height: 16px; &.is-empty { color: #94a3b8; background: #f0f4f8; } }
.node-actions { display: flex; align-items: center; gap: 4px; opacity: 0; :deep(.el-button) { padding: 5px; margin: 0; } } .node-actions { display: none; flex-shrink: 0; align-items: center; gap: 1px; :deep(.el-button) { width: 25px; height: 26px; padding: 4px; margin: 0; color: #94a3b8; font-size: 15px; &:hover, &:focus-visible { color: #3b658f; background: #dceaf8; } &.is-disabled { color: #cbd5e1; } } :deep([data-node-action="rename"]) { color: #f07859; } }
.outline-row:hover .node-actions, .outline-row:focus-within .node-actions { opacity: 1; } .outline-row.is-selected .node-actions, .outline-row:hover .node-actions, .outline-row:focus-within .node-actions, .outline-tree :deep(.el-tree-node:focus > .el-tree-node__content .node-actions) { display: flex; }
.resources-panel { min-height: 530px; padding-bottom: 16px; } .resources-panel { min-height: 530px; padding-bottom: 16px; }
.detail-head { align-items: flex-start; } .detail-head { align-items: flex-start; }
.detail-head > div { flex: 1; min-width: 0; } .detail-head > div { flex: 1; min-width: 0; }
@ -310,6 +283,7 @@ h2 { margin: 0; font-size: var(--fs-card, 14px); font-weight: 600; }
.visibility-note { color: #64748b; font-size: 12px; margin-bottom: 14px; } .visibility-note { color: #64748b; font-size: 12px; margin-bottom: 14px; }
.visibility-table { font-size: 12px; } .visibility-table { font-size: 12px; }
.inherited { color: #94a3b8; font-size: 11px; } .inherited { color: #94a3b8; font-size: 11px; }
@media (max-width: 1100px) { .management-columns { grid-template-columns: minmax(290px, 36%) minmax(0, 1fr); } .course-management { padding: 16px; } .node-actions { opacity: 1; } } @media (max-width: 1200px) { .management-columns { grid-template-columns: 1fr; } .course-management { padding: 16px; } .outline-tree { min-height: 280px; max-height: 440px; } }
@media (max-width: 760px) { .page-head { align-items: flex-start; flex-direction: column; } .management-columns { grid-template-columns: 1fr; } .outline-tree { min-height: 200px; max-height: 350px; } } @media (max-width: 760px) { .page-head { align-items: flex-start; flex-direction: column; } .management-columns { grid-template-columns: 1fr; } .outline-tree { min-height: 200px; max-height: 350px; } }
@media (max-width: 540px) { .outline-tree :deep(.el-tree-node__content) { height: auto; min-height: 40px; } .outline-row { flex-wrap: wrap; gap: 5px; padding-top: 6px; padding-bottom: 6px; } .node-name { min-width: 55px; } .node-actions { flex-basis: 100%; justify-content: flex-end; } .panel-head { padding: 12px; gap: 8px; } }
</style> </style>

@ -7,7 +7,7 @@ const origin = process.env.QA_ORIGIN
const username = process.env.QA_ADMIN_USERNAME const username = process.env.QA_ADMIN_USERNAME
const password = process.env.QA_ADMIN_PASSWORD const password = process.env.QA_ADMIN_PASSWORD
assert(origin && username && password, 'Provide the authorized QA origin and admin credentials') 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 }) fs.mkdirSync(reports, { recursive: true })
async function main() { async function main() {
const browser = await chromium.launch({ channel: 'chrome', headless: true }) const browser = await chromium.launch({ channel: 'chrome', headless: true })
@ -17,7 +17,7 @@ async function main() {
let rootId let rootId
let token let token
let currentStep = 'login' 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('pageerror', error => result.errors.push(error.message))
page.on('console', message => { page.on('console', message => {
if (['warning', 'error'].includes(message.type())) result.warnings.push({ step: currentStep, message: message.text() }) 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) assert.equal(response.status(), 200, method + ' ' + endpoint)
return (await response.json()).data 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 currentStep = command
await page.locator(`[data-resource-node="${id}"] .el-dropdown`).click() await row(id).hover()
await page.locator('.el-dropdown-menu:visible').getByText(command, { exact: true }).click() await row(id).locator(`[data-node-action="${command}"]`).click()
} }
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(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 throw error
}) })
assert(await page.locator(`[data-resource-node="${id}"] .el-dropdown button`).isVisible()) assert(await row(id).locator('.node-actions').isVisible())
} }
try { try {
await page.goto(origin + '/#/login') await page.goto(origin + '/#/login')
@ -54,39 +55,66 @@ async function main() {
await page.goto(origin + '/#/platform-course-resources/index') await page.goto(origin + '/#/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 page.locator(`[data-resource-node="${childId}"] .el-dropdown`).click() await row(rootId).locator('.node-name').click()
await page.locator('.el-dropdown-menu:visible').waitFor() await page.getByRole('heading', { name: '课程资源', exact: true }).hover()
await page.locator('.el-dropdown-menu:visible').getByText('重命名', { exact: true }).focus() assert.equal(await row(rootId).locator('.node-actions button:visible').count(), 6)
await page.keyboard.press('Escape') assert.equal(await row(childId).locator('.file-count').innerText(), '空')
await page.locator('.el-dropdown-menu:visible').waitFor({ state: 'hidden' }) assert.equal(await row(childId).locator('.node-actions').isVisible(), false)
await triggerFocused(childId) result.passed.push('selected row retains six inline actions; unselected empty rows retain their empty badge')
result.passed.push('Escape closes the menu and restores focus') await row(childId).hover()
await menu(childId, '重命名') 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.getByRole('textbox', { name: '请输入目录名称', exact: true }).fill(marker + '改名节')
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 page.locator(`[data-resource-node="${childId}"] .node-name`).filter({ hasText: marker + '改名节' }).waitFor() await page.locator(`[data-resource-node="${childId}"] .node-name`).filter({ hasText: marker + '改名节' }).waitFor()
await triggerFocused(childId) await triggerFocused(childId)
result.passed.push('rename dialog restores focus to the visible trigger') result.passed.push('rename dialog restores focus to the inline action')
for (const command of ['上移', '下移']) { for (const command of ['up', 'down']) {
const oldNumber = await page.locator(`[data-resource-node="${childId}"] .node-number`).innerText() 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 page.waitForFunction(({ id, oldNumber }) => document.querySelector(`[data-resource-node="${id}"] .node-number`)?.textContent !== oldNumber, { id: childId, oldNumber })
await triggerFocused(childId) await triggerFocused(childId)
} }
result.passed.push('move commands preserve focus outside the hidden menu') result.passed.push('inline move actions update numbering and preserve visible focus')
await menu(childId, '删除') 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)
assert((await api('/management')).nodes.some(node => node.id === childId)) assert((await api('/management')).nodes.some(node => node.id === childId))
result.passed.push('cancel deletion restores focus and preserves the directory') 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 page.screenshot({ path: path.join(reports, 'inline-focus-restored.png'), fullPage: true, animations: 'disabled' })
await menu(childId, '删除') 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 page.locator(`[data-resource-node="${childId}"]`).waitFor({ state: 'hidden' }) await page.locator(`[data-resource-node="${childId}"]`).waitFor({ state: 'hidden' })
result.passed.push('confirmed deletion still removes the directory') result.passed.push('confirmed deletion still removes the directory')
assert.deepEqual(result.errors, []) assert.deepEqual(result.errors, [])
assert.deepEqual(result.warnings, []) 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) { } catch (error) {
result.failure = error.message result.failure = error.message
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' })

@ -83,16 +83,18 @@ async function main() {
if (role !== 4) { if (role !== 4) {
await page.getByRole('button', { name: '展开全部', exact: true }).click() await page.getByRole('button', { name: '展开全部', exact: true }).click()
await page.locator('[data-resource-node="3"]').waitFor({ state: 'visible' }) await page.locator('[data-resource-node="3"]').waitFor({ state: 'visible' })
assert.equal(await page.locator('[data-resource-node="2"] .file-count').innerText(), '空')
assert.equal(await page.locator('[data-resource-node="3"] .file-count').innerText(), '1')
assert.equal(await page.locator('[data-resource-node="3"] .file-count .el-icon').count(), 1)
await page.locator('[data-resource-node="3"]').hover()
assert.equal(await page.getByRole('button', { name: '上传资源到用户访谈方法', exact: true }).count(), 1) assert.equal(await page.getByRole('button', { name: '上传资源到用户访谈方法', exact: true }).count(), 1)
if (role === 3) { if (role === 3) {
const builtin = page.locator('[data-resource-node="1"]') const builtin = page.locator('[data-resource-node="1"]')
await builtin.hover() await builtin.hover()
await builtin.getByRole('button', { name: '互联网产品开发基础的目录操作' }).click() assert.equal(await builtin.locator('[data-node-action="delete"]').count(), 0)
const menu = page.locator('.el-dropdown-menu:visible') assert.equal(await builtin.locator('[data-node-action="rename"]').count(), 0)
await menu.waitFor() assert.equal(await builtin.locator('[data-node-action="add"]').count(), 1)
assert(!await menu.getByText('删除', { exact: true }).count()) assert.equal(await builtin.locator('[data-node-action="upload"]').count(), 1)
assert(!await menu.getByText('重命名', { exact: true }).count())
await page.keyboard.press('Escape')
const publicFile = page.locator('.el-table__row').filter({ hasText: '第一章学习讲义.pdf' }) const publicFile = page.locator('.el-table__row').filter({ hasText: '第一章学习讲义.pdf' })
assert.equal(await publicFile.getByRole('button', { name: '删除', exact: true }).count(), 0) assert.equal(await publicFile.getByRole('button', { name: '删除', exact: true }).count(), 0)
const ownFile = page.locator('.el-table__row').filter({ hasText: '课堂补充资料.txt' }) const ownFile = page.locator('.el-table__row').filter({ hasText: '课堂补充资料.txt' })

@ -285,14 +285,14 @@ async function main() {
pass('教师可删除本人上传资源') pass('教师可删除本人上传资源')
await adminPage.reload() await adminPage.reload()
await adminPage.locator(`[data-resource-node="${root}"]`).waitFor() await adminPage.locator(`[data-resource-node="${root}"]`).waitFor()
await adminPage.locator(`[data-resource-node="${root}"] .el-dropdown`).click() await adminPage.locator(`[data-resource-node="${root}"]`).hover()
await adminPage.locator('.el-dropdown-menu:visible').getByText('重命名', { exact: true }).click() await adminPage.locator(`[data-resource-node="${root}"] [data-node-action="rename"]`).click()
await adminPage.locator('.el-message-box__input input').fill(prefix + '重命名验收章') await adminPage.locator('.el-message-box__input input').fill(prefix + '重命名验收章')
await adminPage.locator('.el-message-box').getByRole('button', { name: '确定', exact: true }).click() await adminPage.locator('.el-message-box').getByRole('button', { name: '确定', exact: true }).click()
await adminPage.locator('.detail-head h2').filter({ hasText: prefix + '重命名验收章' }).waitFor() await adminPage.locator('.detail-head h2').filter({ hasText: prefix + '重命名验收章' }).waitFor()
for (const confirm of [false, true]) { for (const confirm of [false, true]) {
await adminPage.locator(`[data-resource-node="${root}"] .el-dropdown`).click() await adminPage.locator(`[data-resource-node="${root}"]`).hover()
await adminPage.locator('.el-dropdown-menu:visible').getByText('删除', { exact: true }).click() await adminPage.locator(`[data-resource-node="${root}"] [data-node-action="delete"]`).click()
await adminPage.locator('.el-message-box').getByText(/包括教师在其下新增的目录和资源/).waitFor() await adminPage.locator('.el-message-box').getByText(/包括教师在其下新增的目录和资源/).waitFor()
await adminPage.locator('.el-message-box').getByRole('button', { name: confirm ? '确认删除' : '取消', exact: true }).click() await adminPage.locator('.el-message-box').getByRole('button', { name: confirm ? '确认删除' : '取消', exact: true }).click()
if (!confirm) assert((await api('admin', '/management')).nodes.some(node => node.id === root)) if (!confirm) assert((await api('admin', '/management')).nodes.some(node => node.id === root))

Loading…
Cancel
Save