user.cy.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import {NETWORK_URL, loginIntercept, loginSetup, menuIntercept, optionsIntercept} from './utils/setup';
  2. import {menuTrigger, selectClick, selectGetValue} from './utils/utils';
  3. describe('用户管理', function() {
  4. beforeEach(function() {
  5. loginIntercept();
  6. menuIntercept();
  7. loginSetup();
  8. optionsIntercept();
  9. menuTrigger(1, 0);
  10. });
  11. beforeEach(function() {
  12. cy.intercept(
  13. `${NETWORK_URL}/user/getAllUser*`,
  14. function({reply, url: reqUrl}) {
  15. const url = new URL(reqUrl);
  16. const search = new URLSearchParams(url.search);
  17. if (search.has('userName') && search.get('userName').length)
  18. return reply({fixture: 'user/nameSearch'});
  19. if (search.has('code') && search.get('code').length)
  20. return reply({fixture: 'user/codeSearch'});
  21. if (search.has('id') && search.get('id').length)
  22. return reply({fixture: 'user/userInfo'});
  23. const page = search.get('page');
  24. reply({fixture: page === '1' ? 'user/userList1' : 'user/userList2'});
  25. },
  26. );
  27. cy.intercept(
  28. `${NETWORK_URL}/user/delUser*`,
  29. function({reply}) {
  30. reply({fixture: 'success', delay: 100});
  31. },
  32. );
  33. cy.intercept(
  34. `${NETWORK_URL}/user/addUser`,
  35. function({reply}) {
  36. reply({fixture: 'success', delay: 100});
  37. },
  38. );
  39. cy.intercept(
  40. `${NETWORK_URL}/user/updateUser`,
  41. function({reply}) {
  42. reply({fixture: 'success', delay: 100});
  43. },
  44. );
  45. });
  46. it('用户列表', function() {
  47. cy.getTestId('user_table').find('table').find('.ant-table-tbody')
  48. .children('.ant-table-row').should('have.length', 3);
  49. cy.get('.ant-pagination').find('li[title="2"]').click();
  50. cy.getTestId('user_table').find('table').find('.ant-table-tbody')
  51. .children('.ant-table-row').first().find('td').first()
  52. .should('include.text', 'TLD0004');
  53. });
  54. it('搜索', function() {
  55. cy.get('.ant-pagination').find('li[title="2"]').click();
  56. cy.get('input[name="useName"]').type('admin');
  57. cy.get('input[name="useCode"]').clear();
  58. cy.getTestId('search_btn').trigger('click');
  59. cy.getTestId('user_table').find('table').find('.ant-table-tbody')
  60. .children('.ant-table-row').first().find('td').first()
  61. .should('include.text', 'searchName');
  62. cy.get('.ant-pagination').find('li[title="1"]')
  63. .should('have.class', 'ant-pagination-item-active');
  64. cy.get('input[name="useName"]').clear();
  65. cy.get('input[name="useCode"]').type('1234');
  66. cy.getTestId('search_btn').trigger('click');
  67. cy.getTestId('user_table').find('table').find('.ant-table-tbody')
  68. .children('.ant-table-row').first().find('td').first()
  69. .should('include.text', 'searchCode');
  70. });
  71. it('删除操作', function() {
  72. cy.getTestId('user_table').find('table').find('.ant-table-tbody')
  73. .children('.ant-table-row').first().find('td').last().children().last()
  74. .trigger('click');
  75. cy.get('.ant-modal-content').should('be.visible');
  76. cy.get('.ant-modal-confirm-btns').children().last().trigger('click');
  77. cy.getTestId('user_table').find('table').find('.ant-table-tbody')
  78. .children('.ant-table-row').first().find('td').last().children().last()
  79. .should('have.class', 'ant-btn-loading');
  80. cy.getTestId('user_table').find('table').find('.ant-table-tbody')
  81. .children('.ant-table-row').first().find('td').last().children().first()
  82. .should('have.attr', 'disabled');
  83. cy.get('.ant-message-notice-content').should('include.text', '删除成功');
  84. });
  85. it('新增操作', function() {
  86. cy.getTestId('add_btn').trigger('click');
  87. cy.getTestId('user_add_modal').should('exist').and('be.visible');
  88. cy.getTestId('user_add_modal').find('h3').should('include.html', '新增用户');
  89. cy.get('input[name="userName"]').type('name');
  90. cy.get('input[name="userPassword"]').type('password');
  91. cy.get('input[name="userRealName"]').type('realname');
  92. cy.get('input[name="userEmail"]').type('email');
  93. cy.get('input[name="userLandline"]').type('userLandline');
  94. cy.get('input[name="userPhone"]').type('userPhone');
  95. selectClick('select_userDepartment', 0);
  96. selectClick('select_userRole', 0);
  97. cy.getTestId('user_add_modal').find('form').submit();
  98. cy.getTestId('modal_btn_group').find('.ant-btn').first()
  99. .should('have.class', 'ant-btn-loading');
  100. cy.getTestId('modal_btn_group').find('.ant-btn').last()
  101. .should('have.attr', 'disabled');
  102. cy.get('.ant-message-notice-content').should('include.text', '新增成功');
  103. cy.getTestId('user_add_modal').should('not.exist');
  104. });
  105. it('修改操作', function() {
  106. cy.getTestId('user_table').find('table').find('.ant-table-tbody')
  107. .children('.ant-table-row').first().find('td').last().children().first()
  108. .trigger('click');
  109. cy.get('input[name="userName"]').should('have.value', '123412');
  110. cy.get('input[name="userPassword"]').should(
  111. 'have.value',
  112. '44349BD19046F3D527D67A5D0D414B09');
  113. cy.get('input[name="userRealName"]').should('have.value', '测试');
  114. cy.get('input[name="userEmail"]').should('have.value', '123@adfa.com');
  115. cy.get('input[name="userLandline"]').should('have.value', '1231123');
  116. cy.get('input[name="userPhone"]').should('have.value', '1532');
  117. selectGetValue('select_userDepartment', '物流部门');
  118. selectGetValue('select_userRole', '物流管理员');
  119. cy.getTestId('user_add_modal').find('form').submit();
  120. cy.getTestId('modal_btn_group').find('.ant-btn').first()
  121. .should('have.class', 'ant-btn-loading');
  122. cy.getTestId('modal_btn_group').find('.ant-btn').last()
  123. .should('have.attr', 'disabled');
  124. cy.get('.ant-message-notice-content').should('include.text', '修改成功');
  125. cy.getTestId('user_add_modal').should('not.exist');
  126. });
  127. });