role.cy.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import {
  2. loginIntercept,
  3. menuIntercept,
  4. loginSetup,
  5. menuTrigger,
  6. validateDelete,
  7. validatePut,
  8. validateTableList,
  9. validateTableSearch,
  10. successIntercept,
  11. normalIntercept,
  12. intercept,
  13. tableBtnClick,
  14. exportIntercept,
  15. validateExport,
  16. validateModalBtnGroup,
  17. } from './utils';
  18. describe('角色管理', function() {
  19. beforeEach(function() {
  20. loginIntercept();
  21. menuIntercept();
  22. loginSetup();
  23. menuTrigger(1, 1);
  24. });
  25. beforeEach(function() {
  26. intercept('/role/getRole', function({url: reqUrl, reply}) {
  27. const url = new URL(reqUrl);
  28. const search = new URLSearchParams(url.search);
  29. if (search.has('roleName') && search.get('roleName').length)
  30. return reply({fixture: 'role/search'});
  31. const page = search.get('page');
  32. reply({fixture: page === '1' ? 'role/list1' : 'role/list2'});
  33. });
  34. intercept('/menu/getPage', function({reply}) {
  35. reply({fixture: 'menu/pda'});
  36. });
  37. successIntercept('/role/addRole');
  38. successIntercept('/role/updateRole');
  39. successIntercept('/role/delRole');
  40. normalIntercept('/menu/getMenu', 'menu/all');
  41. exportIntercept('/role/export');
  42. });
  43. const TABLE_NAME = 'role_table',
  44. MODAL_NAME = 'role_modal',
  45. LABEL = '角色';
  46. it('角色列表', function() {
  47. validateTableList(TABLE_NAME);
  48. });
  49. it('搜索', function() {
  50. const validate = validateTableSearch(TABLE_NAME, 'roleSearch');
  51. cy.get('#filter_roleName').type('roleName');
  52. validate();
  53. });
  54. const {validateAdd, validateEdit} = validatePut(
  55. MODAL_NAME,
  56. LABEL,
  57. );
  58. it('新增操作', function() {
  59. validateAdd(function() {
  60. cy.get('#operation_roleName').type('roleName');
  61. cy.get('#operation_roleRemarks').type('roleRemarks');
  62. });
  63. });
  64. it('修改操作', function() {
  65. validateEdit(TABLE_NAME, function() {
  66. cy.get('#operation_roleName').should('have.value', '仓库管理员');
  67. cy.get('#operation_roleRemarks').should('have.value', 'cangk');
  68. });
  69. });
  70. it('删除操作', function() {
  71. validateDelete(TABLE_NAME, LABEL);
  72. });
  73. it('设置菜单权限', function() {
  74. tableBtnClick(TABLE_NAME, 2);
  75. cy.getTestId('role_tree_modal').find('h3')
  76. .should('include.html', '菜单权限');
  77. cy.getTestId('role_tree_modal').should('exist').and('be.visible');
  78. cy.getTestId('role_tree').find('.ant-tree-list-holder-inner')
  79. .find('.ant-tree-treenode').each(function(res, idx) {
  80. idx <= 3
  81. ? expect(res.hasClass('ant-tree-treenode-checkbox-checked')).to.true
  82. : expect(res.hasClass('ant-tree-treenode-checkbox-checked')).to.false;
  83. }).should('have.length', 9);
  84. cy.getTestId('role_tree_modal').find('form').submit();
  85. validateModalBtnGroup('role_tree_modal');
  86. cy.get('.ant-message-notice-content').should('include.text', '设置成功');
  87. cy.getTestId('role_tree_modal').should('not.exist');
  88. });
  89. it('设置pda权限', function() {
  90. tableBtnClick(TABLE_NAME, 3);
  91. cy.get('.ant-transfer-list').eq(0).find('.ant-transfer-list-content')
  92. .children('.ant-transfer-list-content-item').should('have.length', 4);
  93. cy.get('.ant-transfer-list').eq(1).find('.ant-transfer-list-content')
  94. .children('.ant-transfer-list-content-item').should('have.length', 2);
  95. cy.getTestId('role_pda_menu_modal').find('form').submit();
  96. validateModalBtnGroup('role_pda_menu_modal');
  97. cy.get('.ant-message-notice-content').should('include.text', '设置成功');
  98. cy.getTestId('role_tree_modal').should('not.exist');
  99. });
  100. it('导出', function() {
  101. validateExport();
  102. });
  103. });