department.cy.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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, 2);
  9. });
  10. beforeEach(function() {
  11. cy.intercept(
  12. `${NETWORK_URL}/department/getDepartment*`,
  13. function({url: reqUrl, reply}) {
  14. const url = new URL(reqUrl);
  15. const search = new URLSearchParams(url.search);
  16. if (search.has('departmentName') && search.get('departmentName').length)
  17. return reply({fixture: 'department/nameSearch'});
  18. if (search.has('code') && search.get('code').length)
  19. return reply({fixture: 'department/codeSearch'});
  20. const page = search.get('page');
  21. reply({fixture: page === '1' ? 'department/list1' : 'department/list2'});
  22. },
  23. );
  24. cy.intercept(`${NETWORK_URL}/department/addDepartment*`, {fixture: 'success', delay: 100});
  25. cy.intercept(`${NETWORK_URL}/department/updateDepartment*`, {fixture: 'success', delay: 100});
  26. cy.intercept(`${NETWORK_URL}/department/delDepartment*`, {fixture: 'success', delay: 100});
  27. });
  28. it('部门列表', function() {
  29. cy.getTestId('department_table').find('table').find('.ant-table-tbody')
  30. .children('.ant-table-row').should('have.length', 3);
  31. cy.get('.ant-pagination').find('li[title="2"]').click();
  32. cy.getTestId('department_table').find('table').find('.ant-table-tbody')
  33. .children('.ant-table-row').should('have.length', 2);
  34. });
  35. it('搜索', function() {
  36. cy.get('.ant-pagination').find('li[title="2"]').click();
  37. cy.get('#filter_departmentCode').type('TLD0004');
  38. cy.get('#filter_departmentName').clear();
  39. cy.getTestId('search_btn').trigger('click');
  40. cy.getTestId('department_table').find('table').find('.ant-table-tbody')
  41. .children('.ant-table-row').first().find('td').first()
  42. .should('include.text', 'searchCode');
  43. cy.get('.ant-pagination').find('li[title="1"]')
  44. .should('have.class', 'ant-pagination-item-active');
  45. cy.get('#filter_departmentName').type('name');
  46. cy.get('#filter_departmentCode').clear();
  47. cy.getTestId('search_btn').trigger('click');
  48. cy.getTestId('department_table').find('table').find('.ant-table-tbody')
  49. .children('.ant-table-row').first().find('td').first()
  50. .should('include.text', 'searchName');
  51. });
  52. it('新增部门', function() {
  53. cy.getTestId('add_btn').trigger('click');
  54. cy.getTestId('department_modal').should('exist').and('be.visible');
  55. cy.getTestId('department_modal').find('h3')
  56. .should('include.text', '新增部门');
  57. cy.getTestId('field_departmentName').type('测试部门名称');
  58. cy.getTestId('department_modal').find('form').submit();
  59. cy.getTestId('modal_btn_group').find('.ant-btn-loading').should('exist');
  60. cy.get('.ant-message-notice-content').should('include.text', '新增成功');
  61. cy.getTestId('department_modal').should('not.exist');
  62. });
  63. it('修改部门', function() {
  64. cy.getTestId('department_table').find('table').find('.ant-table-tbody')
  65. .children('.ant-table-row').first().find('td').last().children().first()
  66. .trigger('click');
  67. cy.getTestId('department_modal').should('exist').and('be.visible');
  68. cy.getTestId('department_modal').find('h3')
  69. .should('include.text', '修改部门');
  70. cy.getTestId('field_departmentName').should('have.value', '包装部门');
  71. cy.getTestId('department_modal').find('form').submit();
  72. cy.getTestId('modal_btn_group').find('.ant-btn-loading').should('exist');
  73. cy.get('.ant-message-notice-content').should('include.text', '修改成功');
  74. cy.getTestId('department_modal').should('not.exist');
  75. });
  76. it('删除部门', function() {
  77. cy.getTestId('department_table').find('table').find('.ant-table-tbody')
  78. .children('.ant-table-row').first().find('td').last().children().last()
  79. .trigger('click');
  80. cy.get('.ant-modal-content').should('be.visible');
  81. cy.get('.ant-modal-confirm-btns').children().last().trigger('click');
  82. cy.getTestId('department_table').find('table').find('.ant-table-tbody')
  83. .children('.ant-table-row').first().find('td').last().children().last()
  84. .should('have.class', 'ant-btn-loading');
  85. cy.getTestId('department_table').find('table').find('.ant-table-tbody')
  86. .children('.ant-table-row').first().find('td').last().children().first()
  87. .should('have.attr', 'disabled');
  88. cy.get('.ant-message-notice-content').should('include.text', '删除成功');
  89. });
  90. });