import { captureScreenshot, expect, test } from './fixtures' import { loginAsAdmin } from './helpers' const pages = [ ['/system/users', '用户管理', 'system-users', '.users-table .el-table__body-wrapper .el-table__row'], ['/system/departments', '部门管理', 'system-departments', '.department-table .el-table__body-wrapper .el-table__row'], ['/system/roles', '角色管理', 'system-roles', '.roles-table .el-table__body-wrapper .el-table__row'], ['/system/menus', '菜单管理', 'system-menus', '.menu-table-panel .el-table__body-wrapper .el-table__row'], ['/system/audit', '审计日志', 'system-audit', '.el-table__body-wrapper .el-table__row'], ['/system/interfaces', '平台服务配置', 'system-interfaces', '.interfaces-table .el-table__body-wrapper .el-table__row'], ] as const test('系统管理页面均可加载且权限配置收口到角色抽屉', async ({ page }, testInfo) => { await loginAsAdmin(page) for (const [path, heading, screenshotLabel, readySelector] of pages) { await test.step(heading, async () => { await page.goto(path) await expect(page).toHaveURL(new RegExp(`${path.replaceAll('/', '\\/')}(?:\\?|$)`)) // 系统管理页面已去掉 SystemPageHeader,页面身份由页面标签栏承担 await expect(page.locator('.system-page-header')).toHaveCount(0) await expect(page.getByRole('tab', { name: heading, exact: true })).toBeVisible() await expect(page.locator(readySelector).first()).toBeVisible({ timeout: 15_000 }) await expect(page.locator('.system-page .el-loading-mask:visible')).toHaveCount(0) if (['/system/users', '/system/departments', '/system/roles', '/system/menus', '/system/audit', '/system/interfaces'].includes(path)) { await expect(page.getByRole('button', { name: '搜索', exact: true })).toBeVisible() await expect(page.getByRole('button', { name: '重置', exact: true })).toBeVisible() // 关键词框统一 260px const keywordWidth = await page.locator('.system-list-toolbar .el-input').first() .evaluate((element) => element.getBoundingClientRect().width) expect(keywordWidth).toBeGreaterThan(230) expect(keywordWidth).toBeLessThanOrEqual(270) } // 页级动作落在工具条右端,不再出现在页头 for (const [actionPath, actionName] of [ ['/system/users', '新增用户'], ['/system/departments', '新增部门'], ['/system/roles', '新增角色'], ['/system/audit', '导出日志'], ] as const) { if (path !== actionPath) continue const action = page.locator('.system-list-toolbar').getByRole('button', { name: actionName, exact: true }) await expect(action).toBeVisible() const [toolbarBox, actionBox] = await Promise.all([ page.locator('.system-list-toolbar').first().boundingBox(), action.boundingBox(), ]) expect(actionBox!.x + actionBox!.width).toBeGreaterThan(toolbarBox!.x + toolbarBox!.width - 40) } if (path === '/system/departments') { await expect(page.locator('.department-stats')).toHaveCount(0) await expect(page.getByTestId('department-inline-statistics')).toContainText('个部门') await expect(page.getByTestId('department-inline-statistics')).toContainText('启用') } if (path === '/system/roles') { await expect(page.locator('.role-statistics')).toHaveCount(0) await expect(page.getByTestId('role-inline-statistics')).toContainText('个角色') await expect(page.getByTestId('role-inline-statistics')).toContainText('内置') const permissionButton = page.locator('.roles-table .role-table-actions').first().getByRole('button', { name: '配置权限' }) await permissionButton.click() await expect(page.locator('.role-permission-drawer')).toBeVisible() await page.locator('.role-permission-drawer .el-drawer__close-btn').click() } if (path === '/system/menus') { await expect(page.locator('.menu-statistics')).toHaveCount(0) await expect(page.getByTestId('menu-inline-statistics')).toContainText('个节点') await expect(page.getByTestId('menu-inline-statistics')).toContainText('页面') } if (path === '/system/interfaces') { // 卡片式展示已改为搜索栏 + 表格 + 分页 await expect(page.locator('.interface-card')).toHaveCount(0) await expect(page.locator('.interfaces-table')).toHaveClass(/el-table--border/) await expect(page.locator('.interfaces-table')).toHaveClass(/el-table--striped/) await expect(page.getByTestId('interface-inline-statistics')).toContainText('个服务') await expect(page.locator('.system-pagination-total')).toBeVisible() } await captureScreenshot(page, testInfo, screenshotLabel) }) } })