Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

94 rindas
5.6 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: 'inline-statistics-mock' }),
  7. })
  8. const departments = [{
  9. id: '100', code: 'ORG-100', name: '某类装备维修实训数字车间', parentId: null, enabled: true, isRoot: true,
  10. sortOrder: 10, directUserCount: 1, directChildCount: 1, version: 1,
  11. children: [{
  12. id: '110', code: 'ORG-110', name: '信息中心', parentId: '100', enabled: true,
  13. sortOrder: 10, directUserCount: 3, directChildCount: 0, version: 1, children: [],
  14. }],
  15. }]
  16. const roles = [
  17. { id: '1', code: 'admin', name: '管理员', shortName: '管', enabled: true, builtIn: true, isSuperAdmin: true, dataScopeCode: 'ALL', linkedUserCount: 1, permissionCount: 30, version: 1 },
  18. { id: '2', code: 'teacher', name: '教员', shortName: '教', enabled: true, builtIn: true, isSuperAdmin: false, dataScopeCode: 'SYSTEM', linkedUserCount: 3, permissionCount: 12, version: 1 },
  19. ]
  20. const menus = [{
  21. id: 'group-system', parentId: null, code: 'group.system', name: '系统管理', description: '平台与权限配置',
  22. type: 'GROUP', sortOrder: 10, enabled: true, builtIn: true, dataVersion: 1,
  23. children: [
  24. { id: 'system-users', parentId: 'group-system', code: 'system.users', name: '用户管理', description: '管理用户', type: 'PAGE', sortOrder: 10, enabled: true, builtIn: true, dataVersion: 1, children: [] },
  25. { id: 'system-roles', parentId: 'group-system', code: 'system.roles', name: '角色管理', description: '管理角色', type: 'PAGE', sortOrder: 20, enabled: true, builtIn: true, dataVersion: 1, children: [] },
  26. ],
  27. }]
  28. async function mockSystemPageApi(page: Page) {
  29. await page.route(/\/api\/(?:auth|tran)\//, async (route) => {
  30. const path = new URL(route.request().url()).pathname
  31. if (path.endsWith('/auth/me')) return json(route, {
  32. userId: '1', username: 'admin', displayName: '系统管理员', departmentId: '110', departmentName: '信息中心',
  33. activeRoleId: '1', roles, authorizationMode: 'SINGLE_ACTIVE', mustChangePassword: false,
  34. permissions: ['system.departments', 'system.roles', 'system.menus', 'system.permissions', 'system.departments.create', 'system.roles.create', 'system.roles.update', 'system.roles.delete', 'system.menus.update'],
  35. })
  36. if (path.endsWith('/departments/tree')) return json(route, departments)
  37. if (path.endsWith('/departments/stats')) return json(route, { total: 2, enabled: 2, maxDepth: 2, assignedUsers: 4 })
  38. if (path.endsWith('/roles/all')) return json(route, roles)
  39. if (path.endsWith('/roles/stats')) return json(route, { total: 2, enabled: 2, builtIn: 2, assignedUsers: 4 })
  40. if (path.endsWith('/menus/tree') || path.endsWith('/menus/navigation')) return json(route, menus)
  41. if (path.endsWith('/system-config/public')) return json(route, { systemName: '某类装备维修实训数字车间', logoConfigured: false, faviconConfigured: false })
  42. if (path.endsWith('/auth/ping')) return json(route, { service: 'ut-auth', status: 'UP' })
  43. if (path.endsWith('/tran/ping')) return json(route, { service: 'ut-tran', status: 'UP' })
  44. return json(route, {})
  45. })
  46. await page.addInitScript(() => {
  47. window.sessionStorage.setItem('unreal-tran:web:access-token:v1', 'inline-statistics-token')
  48. })
  49. }
  50. test('部门、角色、菜单统计收进列表工具栏', async ({ page }, testInfo) => {
  51. await mockSystemPageApi(page)
  52. const cases = [
  53. { path: '/system/departments', testId: 'department-inline-statistics', removed: '.department-stats', texts: ['共 2 个部门', '启用 2', '2 级组织', '归属 4 人'] },
  54. { path: '/system/roles', testId: 'role-inline-statistics', removed: '.role-statistics', texts: ['共 2 个角色', '启用 2', '内置 2', '已分配 4 人'] },
  55. { path: '/system/menus', testId: 'menu-inline-statistics', removed: '.menu-statistics', texts: ['共 3 个节点', '分组 1', '页面 2'] },
  56. ] as const
  57. for (const item of cases) {
  58. await page.goto(item.path)
  59. const statistics = page.getByTestId(item.testId)
  60. await expect(statistics).toBeVisible()
  61. await expect(page.locator(item.removed)).toHaveCount(0)
  62. for (const text of item.texts) await expect(statistics).toContainText(text)
  63. await expect(statistics.locator('.is-danger')).toHaveCount(0)
  64. const toolbarHeight = await statistics.locator('xpath=ancestor::*[contains(@class, "system-list-toolbar")]').evaluate((toolbar) => toolbar.getBoundingClientRect().height)
  65. expect(toolbarHeight).toBeLessThanOrEqual(64)
  66. if (item.path === '/system/roles') {
  67. const table = page.locator('.roles-table')
  68. await expect(page.locator('.role-card')).toHaveCount(0)
  69. await expect(table).toHaveClass(/el-table--border/)
  70. await expect(table).toHaveClass(/el-table--striped/)
  71. await expect(table.locator('.el-table__body-wrapper .el-table__row')).toHaveCount(2)
  72. const actions = table.locator('.role-table-actions').first()
  73. await expect(actions.getByRole('button', { name: '配置权限' })).toBeVisible()
  74. await expect(actions.getByRole('button', { name: '编辑' })).toBeVisible()
  75. const actionLayout = await actions.evaluate((element) => {
  76. const style = getComputedStyle(element)
  77. return { justifyContent: style.justifyContent, columnGap: style.columnGap }
  78. })
  79. expect(actionLayout.justifyContent).toBe('flex-start')
  80. expect(actionLayout.columnGap).toBe('12px')
  81. }
  82. await captureScreenshot(page, testInfo, item.testId)
  83. }
  84. })