Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

109 lignes
5.3 KiB

  1. import type { Page, Route } from '@playwright/test'
  2. import { captureScreenshot, expect, test } from './fixtures'
  3. const json = (route: Route, data: unknown) => route.fulfill({
  4. status: 200,
  5. contentType: 'application/json',
  6. body: JSON.stringify({ code: 0, message: '成功', data, timestamp: Date.now(), requestId: 'zentao-system-ui-regression' }),
  7. })
  8. const roles = [
  9. {
  10. id: '10', code: 'teacher', name: '教员', shortName: '教', description: '教员业务角色', enabled: true,
  11. builtIn: true, isSuperAdmin: false, dataScopeCode: 'SYSTEM', linkedUserCount: 3, permissionCount: 4,
  12. sortOrder: 10, version: 1,
  13. },
  14. {
  15. id: '1', code: 'admin', name: '管理员', shortName: '管', description: '系统管理员', enabled: true,
  16. builtIn: true, isSuperAdmin: true, dataScopeCode: 'ALL', linkedUserCount: 1, permissionCount: 40,
  17. sortOrder: 20, version: 1,
  18. },
  19. ]
  20. const departments = [{
  21. id: '100', code: 'ORG-100', name: '某类装备维修实训数字车间', parentId: null, enabled: true,
  22. builtIn: true, isRoot: true, sortOrder: 10, directUserCount: 1, directChildCount: 1,
  23. descendantCount: 1, version: 1, updatedAt: '2026-08-16T10:00:00+08:00',
  24. children: [{
  25. id: '110', code: 'ORG-110', name: '维修教研室', parentId: '100', enabled: true,
  26. builtIn: false, isRoot: false, sortOrder: 10, directUserCount: 3, directChildCount: 0,
  27. descendantCount: 0, version: 1, updatedAt: '2026-08-16T10:00:00+08:00', children: [],
  28. }],
  29. }]
  30. const permissionSections = Array.from({ length: 6 }, (_, sectionIndex) => ({
  31. id: `section-${sectionIndex}`,
  32. label: `权限分组 ${sectionIndex + 1}`,
  33. items: Array.from({ length: 8 }, (_, itemIndex) => ({
  34. code: `mock.section${sectionIndex}.action${itemIndex}`,
  35. label: `业务权限 ${sectionIndex + 1}-${itemIndex + 1}`,
  36. description: '用于验证长权限目录中的底部操作栏',
  37. type: 'ACTION',
  38. })),
  39. }))
  40. async function mockSystemApi(page: Page) {
  41. await page.route(/\/api\/(?:auth|tran)\//, async (route) => {
  42. const path = new URL(route.request().url()).pathname
  43. if (path.endsWith('/auth/me')) return json(route, {
  44. userId: '1', username: 'admin', displayName: '系统管理员', departmentId: '100', departmentName: '数字车间',
  45. activeRoleId: '1', roles: [roles[1]], authorizationMode: 'SINGLE_ACTIVE', mustChangePassword: false,
  46. permissions: ['system.departments', 'system.permissions', 'system.permissions.update'],
  47. })
  48. if (path.endsWith('/departments/tree')) return json(route, departments)
  49. if (path.endsWith('/departments/stats')) return json(route, { total: 2, enabled: 2, maxDepth: 2, assignedUsers: 4 })
  50. if (path.endsWith('/roles/all')) return json(route, roles)
  51. if (path.endsWith('/permissions/catalog')) return json(route, { sections: permissionSections })
  52. if (/\/permissions\/roles\/\d+$/.test(path)) return json(route, { permissionCodes: [], version: 1 })
  53. if (path.endsWith('/menus/navigation')) return json(route, [])
  54. if (path.endsWith('/system-config/public')) return json(route, { systemName: '某类装备维修实训数字车间' })
  55. if (path.endsWith('/auth/ping')) return json(route, { service: 'ut-auth', status: 'UP' })
  56. if (path.endsWith('/tran/ping')) return json(route, { service: 'ut-tran', status: 'UP' })
  57. return json(route, {})
  58. })
  59. await page.addInitScript(() => {
  60. window.sessionStorage.setItem('unreal-tran:web:access-token:v1', 'zentao-system-ui-regression-token')
  61. })
  62. }
  63. test('Bug 850:无匹配部门时只保留工具栏重置入口', async ({ page }, testInfo) => {
  64. await mockSystemApi(page)
  65. await page.goto('/system/departments')
  66. await page.getByPlaceholder('请输入部门、编码或负责人').fill('绝对不存在的部门')
  67. await page.getByRole('button', { name: '搜索', exact: true }).click()
  68. const empty = page.locator('.department-table-body .el-empty')
  69. await expect(empty).toBeVisible()
  70. await expect(empty).toContainText('没有符合当前筛选条件的部门')
  71. await expect(empty.getByRole('button', { name: '清除筛选' })).toHaveCount(0)
  72. await expect(page.locator('.department-toolbar').getByRole('button', { name: '重置', exact: true })).toBeVisible()
  73. await captureScreenshot(page, testInfo, 'bug-850-empty-without-duplicate-reset')
  74. })
  75. test('Bug 853:权限操作栏在内容滚动过程中固定于可视区底部', async ({ page }, testInfo) => {
  76. await mockSystemApi(page)
  77. await page.setViewportSize({ width: 1440, height: 760 })
  78. await page.goto('/system/permissions')
  79. const routeView = page.locator('.route-view')
  80. const footer = page.locator('.permission-actions')
  81. await expect(page.locator('.permission-group')).toHaveCount(permissionSections.length)
  82. await expect(footer).toBeVisible()
  83. await routeView.evaluate((element) => { element.scrollTop = Math.round(element.scrollHeight * 0.45) })
  84. await expect.poll(() => routeView.evaluate((element) => element.scrollTop)).toBeGreaterThan(100)
  85. const [routeBox, footerBox, position] = await Promise.all([
  86. routeView.boundingBox(),
  87. footer.boundingBox(),
  88. footer.evaluate((element) => getComputedStyle(element).position),
  89. ])
  90. expect(routeBox).not.toBeNull()
  91. expect(footerBox).not.toBeNull()
  92. expect(position).toBe('sticky')
  93. expect(Math.abs((routeBox!.y + routeBox!.height) - (footerBox!.y + footerBox!.height))).toBeLessThanOrEqual(20)
  94. await captureScreenshot(page, testInfo, 'bug-853-sticky-permission-actions')
  95. })