role.cy.ts 2.8 KB

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