import type { Page, Route } from '@playwright/test' import { captureScreenshot, expect, test } from './fixtures' const json = (route: Route, data: unknown) => route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ code: 0, message: '成功', data, timestamp: Date.now(), requestId: 'zentao-system-ui-regression' }), }) const roles = [ { id: '10', code: 'teacher', name: '教员', shortName: '教', description: '教员业务角色', enabled: true, builtIn: true, isSuperAdmin: false, dataScopeCode: 'SYSTEM', linkedUserCount: 3, permissionCount: 4, sortOrder: 10, version: 1, }, { id: '1', code: 'admin', name: '管理员', shortName: '管', description: '系统管理员', enabled: true, builtIn: true, isSuperAdmin: true, dataScopeCode: 'ALL', linkedUserCount: 1, permissionCount: 40, sortOrder: 20, version: 1, }, ] const departments = [{ id: '100', code: 'ORG-100', name: '某类装备维修实训数字车间', parentId: null, enabled: true, builtIn: true, isRoot: true, sortOrder: 10, directUserCount: 1, directChildCount: 1, descendantCount: 1, version: 1, updatedAt: '2026-08-16T10:00:00+08:00', children: [{ id: '110', code: 'ORG-110', name: '维修教研室', parentId: '100', enabled: true, builtIn: false, isRoot: false, sortOrder: 10, directUserCount: 3, directChildCount: 0, descendantCount: 0, version: 1, updatedAt: '2026-08-16T10:00:00+08:00', children: [], }], }] const permissionSections = Array.from({ length: 6 }, (_, sectionIndex) => ({ id: `section-${sectionIndex}`, label: `权限分组 ${sectionIndex + 1}`, items: Array.from({ length: 8 }, (_, itemIndex) => ({ code: `mock.section${sectionIndex}.action${itemIndex}`, label: `业务权限 ${sectionIndex + 1}-${itemIndex + 1}`, description: '用于验证长权限目录中的底部操作栏', type: 'ACTION', })), })) async function mockSystemApi(page: Page) { await page.route(/\/api\/(?:auth|tran)\//, async (route) => { const path = new URL(route.request().url()).pathname if (path.endsWith('/auth/me')) return json(route, { userId: '1', username: 'admin', displayName: '系统管理员', departmentId: '100', departmentName: '数字车间', activeRoleId: '1', roles: [roles[1]], authorizationMode: 'SINGLE_ACTIVE', mustChangePassword: false, permissions: ['system.departments', 'system.permissions', 'system.permissions.update'], }) if (path.endsWith('/departments/tree')) return json(route, departments) if (path.endsWith('/departments/stats')) return json(route, { total: 2, enabled: 2, maxDepth: 2, assignedUsers: 4 }) if (path.endsWith('/roles/all')) return json(route, roles) if (path.endsWith('/permissions/catalog')) return json(route, { sections: permissionSections }) if (/\/permissions\/roles\/\d+$/.test(path)) return json(route, { permissionCodes: [], version: 1 }) if (path.endsWith('/menus/navigation')) return json(route, []) if (path.endsWith('/system-config/public')) return json(route, { systemName: '某类装备维修实训数字车间' }) if (path.endsWith('/auth/ping')) return json(route, { service: 'ut-auth', status: 'UP' }) if (path.endsWith('/tran/ping')) return json(route, { service: 'ut-tran', status: 'UP' }) return json(route, {}) }) await page.addInitScript(() => { window.sessionStorage.setItem('unreal-tran:web:access-token:v1', 'zentao-system-ui-regression-token') }) } test('Bug 850:无匹配部门时只保留工具栏重置入口', async ({ page }, testInfo) => { await mockSystemApi(page) await page.goto('/system/departments') await page.getByPlaceholder('请输入部门、编码或负责人').fill('绝对不存在的部门') await page.getByRole('button', { name: '搜索', exact: true }).click() const empty = page.locator('.department-table-body .el-empty') await expect(empty).toBeVisible() await expect(empty).toContainText('没有符合当前筛选条件的部门') await expect(empty.getByRole('button', { name: '清除筛选' })).toHaveCount(0) await expect(page.locator('.department-toolbar').getByRole('button', { name: '重置', exact: true })).toBeVisible() await captureScreenshot(page, testInfo, 'bug-850-empty-without-duplicate-reset') }) test('Bug 853:权限操作栏在内容滚动过程中固定于可视区底部', async ({ page }, testInfo) => { await mockSystemApi(page) await page.setViewportSize({ width: 1440, height: 760 }) await page.goto('/system/permissions') const routeView = page.locator('.route-view') const footer = page.locator('.permission-actions') await expect(page.locator('.permission-group')).toHaveCount(permissionSections.length) await expect(footer).toBeVisible() await routeView.evaluate((element) => { element.scrollTop = Math.round(element.scrollHeight * 0.45) }) await expect.poll(() => routeView.evaluate((element) => element.scrollTop)).toBeGreaterThan(100) const [routeBox, footerBox, position] = await Promise.all([ routeView.boundingBox(), footer.boundingBox(), footer.evaluate((element) => getComputedStyle(element).position), ]) expect(routeBox).not.toBeNull() expect(footerBox).not.toBeNull() expect(position).toBe('sticky') expect(Math.abs((routeBox!.y + routeBox!.height) - (footerBox!.y + footerBox!.height))).toBeLessThanOrEqual(20) await captureScreenshot(page, testInfo, 'bug-853-sticky-permission-actions') })