storage.cy.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import {NETWORK_URL, loginIntercept, loginSetup, menuIntercept} from './utils/setup';
  2. import {menuTrigger, selectClick, selectGetValue} from './utils/utils';
  3. describe('库位管理', function() {
  4. beforeEach(function() {
  5. loginIntercept();
  6. menuIntercept();
  7. loginSetup();
  8. menuTrigger(2, 0);
  9. });
  10. beforeEach(function() {
  11. cy.intercept(
  12. `${NETWORK_URL}/storage/getStorage*`,
  13. function({url: reqUrl, reply}) {
  14. const url = new URL(reqUrl);
  15. const search = new URLSearchParams(url.search);
  16. if (search.has('storageLocationName') && search.get('storageLocationName').length)
  17. return reply({fixture: 'storage/nameSearch'});
  18. if (search.has('storageLocationCode') && search.get('storageLocationCode').length)
  19. return reply({fixture: 'storage/codeSearch'});
  20. if (search.has('storageLocationType') && search.get('storageLocationType').length)
  21. return reply({fixture: 'storage/typeSearch'});
  22. if (search.has('isNotDisable') && search.get('isNotDisable').length)
  23. return reply({fixture: 'storage/disabledSearch'});
  24. if (search.has('id') && search.get('id').length)
  25. return reply({fixture: 'storage/info'});
  26. const page = search.get('page');
  27. reply({fixture: page === '1' ? 'storage/list1' : 'storage/list2'});
  28. },
  29. );
  30. cy.intercept(`${NETWORK_URL}/storage/addStorage*`, {fixture: 'success', delay: 100});
  31. cy.intercept(`${NETWORK_URL}/storage/updateStorage*`, {fixture: 'success', delay: 100});
  32. cy.intercept(`${NETWORK_URL}/storage/delStorage*`, {fixture: 'success', delay: 100});
  33. });
  34. it('表格', function() {
  35. cy.getTestId('storage_table').find('table').find('.ant-table-tbody')
  36. .children('.ant-table-row').should('have.length', 3);
  37. cy.get('.ant-pagination').find('li[title="2"]').click();
  38. cy.getTestId('storage_table').find('table').find('.ant-table-tbody')
  39. .children('.ant-table-row').should('have.length', 2);
  40. });
  41. it('搜索', function() {
  42. cy.get('.ant-pagination').find('li[title="2"]').click();
  43. cy.get('#filter_storageName').type('库位');
  44. cy.getTestId('search_btn').click();
  45. cy.get('.ant-pagination').find('li[title="1"]')
  46. .should('have.class', 'ant-pagination-item-active');
  47. cy.getTestId('storage_table').find('table').find('.ant-table-tbody')
  48. .children('.ant-table-row').first().find('td').first()
  49. .should('include.html', 'searchName');
  50. cy.get('#filter_storageName').clear();
  51. cy.get('#filter_storageCode').type('code');
  52. cy.getTestId('search_btn').click();
  53. cy.getTestId('storage_table').find('table').find('.ant-table-tbody')
  54. .children('.ant-table-row').first().find('td').first()
  55. .should('include.html', 'searchCode');
  56. cy.get('#filter_storageCode').clear();
  57. cy.get('#filter_storageType').type('type');
  58. cy.getTestId('search_btn').click();
  59. cy.getTestId('storage_table').find('table').find('.ant-table-tbody')
  60. .children('.ant-table-row').first().find('td').first()
  61. .should('include.html', 'searchType');
  62. cy.get('#filter_storageType').clear();
  63. selectClick('filter_storageState', 1);
  64. cy.getTestId('search_btn').click();
  65. cy.getTestId('storage_table').find('table').find('.ant-table-tbody')
  66. .children('.ant-table-row').first().find('td').first()
  67. .should('include.html', 'searchDisabled');
  68. });
  69. it('删除', function() {
  70. cy.getTestId('storage_table').find('table').find('.ant-table-tbody')
  71. .children('.ant-table-row').first().find('td').last().find('.ant-btn')
  72. .last().click();
  73. cy.get('.ant-modal-content').should('be.visible');
  74. cy.get('.ant-modal-confirm-btns').children().last().trigger('click');
  75. cy.getTestId('storage_table').find('table').find('.ant-table-tbody')
  76. .children('.ant-table-row').first().find('td').last().children().last()
  77. .should('have.class', 'ant-btn-loading');
  78. cy.getTestId('storage_table').find('table').find('.ant-table-tbody')
  79. .children('.ant-table-row').first().find('td').last().children().first()
  80. .should('have.attr', 'disabled');
  81. cy.get('.ant-message-notice-content').should('include.text', '删除成功');
  82. });
  83. it('新增', function() {
  84. cy.getTestId('add_btn').click();
  85. cy.getTestId('storage_modal').should('exist').and('be.visible');
  86. cy.getTestId('storage_modal').find('h3').should('include.text', '新增库位');
  87. cy.getTestId('field_storageLocationCode').type('0001');
  88. cy.getTestId('field_storageLocationName').type('名称');
  89. cy.getTestId('field_storageLocationType').type('类型');
  90. cy.getTestId('field_storageWarehouseWhere').type('1号仓库');
  91. selectClick('select_storageIsNotDisable', 1);
  92. cy.getTestId('storage_modal').find('form').submit();
  93. cy.getTestId('modal_btn_group').find('.ant-btn').first()
  94. .should('have.class', 'ant-btn-loading');
  95. cy.getTestId('modal_btn_group').find('.ant-btn').last()
  96. .should('have.attr', 'disabled');
  97. cy.get('.ant-message-notice-content').should('include.text', '新增成功');
  98. cy.getTestId('storage_modal').should('not.exist');
  99. });
  100. it('修改', function() {
  101. cy.getTestId('storage_table').find('table').find('.ant-table-tbody')
  102. .children('.ant-table-row').first().find('td').last().find('.ant-btn')
  103. .first().click();
  104. cy.getTestId('storage_modal').should('exist').and('be.visible');
  105. cy.getTestId('storage_modal').find('h3').should('include.text', '修改库位');
  106. cy.getTestId('field_storageLocationCode').should('have.value', '0001');
  107. cy.getTestId('field_storageLocationName').should('have.value', '1号库位');
  108. cy.getTestId('field_storageLocationType').should('have.value', '原材料库位');
  109. cy.getTestId('field_storageWarehouseWhere').should('have.value', '1号仓库');
  110. selectGetValue('select_storageIsNotDisable', '启用');
  111. cy.getTestId('storage_modal').find('form').submit();
  112. cy.getTestId('modal_btn_group').find('.ant-btn').first()
  113. .should('have.class', 'ant-btn-loading');
  114. cy.getTestId('modal_btn_group').find('.ant-btn').last()
  115. .should('have.attr', 'disabled');
  116. cy.get('.ant-message-notice-content').should('include.text', '修改成功');
  117. cy.getTestId('storage_modal').should('not.exist');
  118. });
  119. });