manager.cy.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import {
  2. beforeSetup,
  3. exportIntercept,
  4. generateNetworkResult,
  5. intercept,
  6. intoMenu,
  7. normalIntercept,
  8. selectAllFilters,
  9. successIntercept,
  10. tableBtnClick,
  11. validateDelete,
  12. validateDialog,
  13. validateExport,
  14. validateMessageContent,
  15. validateModalBtnGroup,
  16. validatePut,
  17. validateTableList,
  18. validateTableSearch,
  19. } from './utils';
  20. const basicData = {
  21. id: '83',
  22. code: 'YH000083',
  23. userName: 'admin2',
  24. password: 'F6BE46C2F900E518',
  25. newPassword: null,
  26. realName: '测试2',
  27. email: '1211@163.com',
  28. landline: null,
  29. phone: '1336131680',
  30. department: '采购中心(公共) ',
  31. role: 'test账户',
  32. roleId: '11',
  33. departmentId: '00029999',
  34. createTime: '2023-04-03 14:01:45',
  35. token: null,
  36. modifyUser: 'admin',
  37. modifyTime: '2023-04-03 14:18:21',
  38. page: 0,
  39. limit: 0,
  40. menu: '78,93,88,79,',
  41. menuBefore: '78,93,88,79,',
  42. };
  43. const TABLE_NAME = 'user_table',
  44. MODAL_NAME = 'user_add_modal',
  45. LABEL = '用户',
  46. TOOL_ID = 'user_filter';
  47. describe('首页', function() {
  48. beforeEach(function() {
  49. beforeSetup();
  50. intoMenu('系统设置', '用户管理');
  51. });
  52. beforeEach(function() {
  53. intercept('/user/getAllUser', function({search, reply}) {
  54. generateNetworkResult({search, reply, basicData, title: 'code'});
  55. });
  56. exportIntercept('/user/resetPassword');
  57. successIntercept([
  58. '/user/addUser',
  59. '/user/updateUser',
  60. '/user/delUser',
  61. '/user/resetPassword',
  62. ]);
  63. normalIntercept('/menu/getMenu', 'menu/all');
  64. });
  65. it('table', function() {
  66. selectAllFilters(TOOL_ID, 8);
  67. validateTableList(TABLE_NAME);
  68. validateTableSearch(
  69. TABLE_NAME,
  70. [
  71. 'userName',
  72. 'realName',
  73. 'code',
  74. {id: 'department', type: 'select', value: '00029999'},
  75. 'role',
  76. 'email',
  77. 'phone',
  78. 'modifyUser',
  79. ],
  80. {toolId: TOOL_ID, url: '/user/getAllUser'},
  81. );
  82. });
  83. it('operation', function() {
  84. validateExport(TABLE_NAME);
  85. const {validateAdd, validateEdit} = validatePut(MODAL_NAME, TABLE_NAME, {
  86. label: LABEL,
  87. });
  88. validateAdd([
  89. 'userName',
  90. 'userRealName',
  91. 'userPassword',
  92. {id: 'userDepartment', type: 'select'},
  93. {id: 'userRole', type: 'select'},
  94. 'userEmail',
  95. 'userPhone',
  96. ]);
  97. validateEdit([
  98. {id: 'userName', type: 'field', value: basicData.userName},
  99. {id: 'userRealName', type: 'field', value: basicData.realName},
  100. {id: 'userDepartment', type: 'select', value: basicData.department},
  101. {id: 'userRole', type: 'select', value: basicData.role},
  102. {id: 'userEmail', type: 'field', value: basicData.email},
  103. {id: 'userPhone', type: 'field', value: basicData.phone},
  104. ]);
  105. // 设置菜单权限
  106. tableBtnClick(TABLE_NAME, 1);
  107. cy.getTestId('user_tree_modal')
  108. .find('h3')
  109. .should('include.html', '菜单权限');
  110. cy.getTestId('user_tree_modal').should('exist').and('be.visible');
  111. cy.getTestId('user_tree')
  112. .find('.ant-tree-list-holder-inner')
  113. .find('.ant-tree-treenode')
  114. .each(function(res, idx) {
  115. idx <= 3
  116. ? expect(res.hasClass('ant-tree-treenode-checkbox-checked')).to.true
  117. : expect(res.hasClass('ant-tree-treenode-checkbox-checked')).to.false;
  118. })
  119. .should('have.length', 17);
  120. cy.getTestId('user_tree_modal').find('form').submit();
  121. validateModalBtnGroup('user_tree_modal');
  122. cy.get('.ant-message-notice-content').should('include.text', '设置成功');
  123. cy.getTestId('user_tree_modal').should('not.exist');
  124. // 重置密码
  125. const resetBtn = tableBtnClick(TABLE_NAME, 2);
  126. validateDialog('重置密码', '你确定要将测试2的密码重置为123456吗?');
  127. resetBtn().should('have.class', 'ant-btn-loading');
  128. validateMessageContent('重置成功');
  129. validateDelete(TABLE_NAME, LABEL, {eq: 3, title: 'admin2'});
  130. });
  131. });