role.cy.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import {loginIntercept, menuIntercept, loginSetup, NETWORK_URL} from './utils/setup';
  2. import {menuTrigger} from './utils/utils';
  3. describe('角色管理', function() {
  4. beforeEach(function() {
  5. loginIntercept();
  6. menuIntercept();
  7. loginSetup();
  8. menuTrigger(1, 1);
  9. });
  10. beforeEach(function() {
  11. cy.intercept(`${NETWORK_URL}/role/getRole*`, function({url: reqUrl, reply}) {
  12. const url = new URL(reqUrl);
  13. const search = new URLSearchParams(url.search);
  14. if (search.has('roleName') && search.get('roleName').length)
  15. return reply({fixture: 'role/search'});
  16. const page = search.get('page');
  17. reply({fixture: page === '1' ? 'role/list1' : 'role/list2'});
  18. });
  19. cy.intercept(`${NETWORK_URL}/role/addRole*`, {fixture: 'success', delay: 100});
  20. cy.intercept(`${NETWORK_URL}/role/updateRole*`, {fixture: 'success', delay: 100});
  21. cy.intercept(`${NETWORK_URL}/role/delRole*`, {fixture: 'success', delay: 100});
  22. cy.intercept(`${NETWORK_URL}/role/updateRole*`, {fixture: 'success', delay: 100});
  23. cy.intercept(`${NETWORK_URL}/menu/getMenu*`, {fixture: 'menu/all'});
  24. });
  25. it('角色列表', function() {
  26. cy.getTestId('role_table').find('table').find('.ant-table-tbody')
  27. .children('.ant-table-row').should('have.length', 3);
  28. cy.get('.ant-pagination').find('li[title="2"]').click();
  29. cy.getTestId('role_table').find('table').find('.ant-table-tbody')
  30. .children('.ant-table-row').should('have.length', 2);
  31. cy.get('#filter_roleName').type('roleName');
  32. cy.getTestId('search_btn').trigger('click');
  33. cy.getTestId('role_table').find('table').find('.ant-table-tbody')
  34. .children('.ant-table-row').should('have.length', 1);
  35. });
  36. it('新增操作', function() {
  37. cy.getTestId('add_btn').trigger('click');
  38. cy.getTestId('role_modal').should('exist').and('be.visible');
  39. cy.getTestId('role_modal').find('h3').should('include.html', '新增角色');
  40. cy.get('#operation_roleName').type('roleName');
  41. cy.get('#operation_roleRemarks').type('roleRemarks');
  42. cy.getTestId('role_modal').find('form').submit();
  43. cy.getTestId('modal_btn_group').find('.ant-btn-loading').should('exist');
  44. cy.get('.ant-message-notice-content').should('include.text', '新增成功');
  45. cy.getTestId('role_modal').should('not.exist');
  46. });
  47. it('修改操作', function() {
  48. cy.getTestId('role_table').find('table').find('.ant-table-tbody')
  49. .children('.ant-table-row').first().find('td').last().children().first()
  50. .trigger('click');
  51. cy.getTestId('role_modal').should('exist').and('be.visible');
  52. cy.getTestId('role_modal').find('h3').should('include.html', '修改角色');
  53. cy.get('#operation_roleName').should('have.value', '仓库管理员');
  54. cy.get('#operation_roleRemarks').should('have.value', 'cangk');
  55. cy.getTestId('role_modal').find('form').submit();
  56. cy.getTestId('modal_btn_group').find('.ant-btn-loading').should('exist');
  57. cy.get('.ant-message-notice-content').should('include.text', '修改成功');
  58. cy.getTestId('role_modal').should('not.exist');
  59. });
  60. it('删除操作', function() {
  61. cy.getTestId('role_table').find('table').find('.ant-table-tbody')
  62. .children('.ant-table-row').first().find('td').last().children().eq(1)
  63. .trigger('click');
  64. cy.get('.ant-modal-content').should('be.visible');
  65. cy.get('.ant-modal-confirm-btns').children().last().trigger('click');
  66. cy.getTestId('role_table').find('table').find('.ant-table-tbody')
  67. .children('.ant-table-row').first().find('td').last().children().eq(1)
  68. .should('have.class', 'ant-btn-loading');
  69. cy.getTestId('role_table').find('table').find('.ant-table-tbody')
  70. .children('.ant-table-row').first().find('td').last().children().first()
  71. .should('have.attr', 'disabled');
  72. cy.getTestId('role_table').find('table').find('.ant-table-tbody')
  73. .children('.ant-table-row').first().find('td').last().children().last()
  74. .should('have.attr', 'disabled');
  75. cy.get('.ant-message-notice-content').should('include.text', '删除成功');
  76. });
  77. it('设置菜单权限', function() {
  78. cy.getTestId('role_table').find('table').find('.ant-table-tbody')
  79. .children('.ant-table-row').first().find('td').last().children().last()
  80. .trigger('click');
  81. cy.getTestId('role_tree_modal').find('h3')
  82. .should('include.html', '菜单权限');
  83. cy.getTestId('role_tree_modal').should('exist').and('be.visible');
  84. cy.getTestId('role_tree').find('.ant-tree-list-holder-inner')
  85. .find('.ant-tree-treenode').each(function(res, idx) {
  86. idx <= 3
  87. ? expect(res.hasClass('ant-tree-treenode-checkbox-checked')).to.true
  88. : expect(res.hasClass('ant-tree-treenode-checkbox-checked')).to.false;
  89. }).should('have.length', 9);
  90. cy.getTestId('role_tree_modal').find('form').submit();
  91. cy.getTestId('modal_btn_group').find('.ant-btn-loading').should('exist');
  92. cy.get('.ant-message-notice-content').should('include.text', '设置成功');
  93. cy.getTestId('role_tree_modal').should('not.exist');
  94. });
  95. });