role.cy.ts 2.8 KB

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