goods.cy.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import {loginIntercept, menuIntercept, loginSetup, NETWORK_URL, 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(2, 1);
  10. });
  11. beforeEach(function() {
  12. cy.intercept(`${NETWORK_URL}/goods/getGoods*`, function({url: reqUrl, reply}) {
  13. const url = new URL(reqUrl);
  14. const search = new URLSearchParams(url.search);
  15. if (search.has('itemNumber') && search.get('itemNumber').length)
  16. return reply({fixture: 'goods/search'});
  17. const page = search.get('page');
  18. reply({fixture: page === '1' ? 'goods/list1' : 'goods/list2'});
  19. });
  20. cy.intercept(`${NETWORK_URL}/goods/addGoods*`, {fixture: 'success', delay: 100});
  21. cy.intercept(`${NETWORK_URL}/goods/delGoods*`, {fixture: 'success', delay: 100});
  22. cy.intercept(`${NETWORK_URL}/goods/updateGoods*`, {fixture: 'success', delay: 100});
  23. });
  24. it('表格', function() {
  25. cy.getTestId('goods_table').find('table').find('.ant-table-tbody')
  26. .children('.ant-table-row').should('have.length', 3);
  27. cy.get('.ant-pagination').find('li[title="2"]').click();
  28. cy.getTestId('goods_table').find('table').find('.ant-table-tbody')
  29. .children('.ant-table-row').should('have.length', 2);
  30. });
  31. it('搜索', function() {
  32. cy.get('.ant-pagination').find('li[title="2"]').click();
  33. cy.get('#filter_goodsCode').type('P00012');
  34. cy.getTestId('search_btn').trigger('click');
  35. cy.getTestId('goods_table').find('table').find('.ant-table-tbody')
  36. .children('.ant-table-row').children('td').first()
  37. .should('have.text', 'searchCode');
  38. });
  39. it('新增', function() {
  40. cy.getTestId('add_btn').click();
  41. cy.getTestId('goods_modal').should('exist').and('be.visible');
  42. cy.getTestId('goods_modal').find('h3').should('have.text', '新增货品');
  43. cy.getTestId('field_goodsItemNumber').type('品号');
  44. cy.getTestId('field_goodsName').type('goodsName');
  45. cy.getTestId('field_goodsType').type('goodsType');
  46. cy.getTestId('field_goodsMinAccommodate').clear().type('1');
  47. cy.getTestId('field_goodsAccommodateNum').clear().type('1');
  48. cy.getTestId('field_goodsMaxAccommodate').clear().type('1');
  49. cy.getTestId('field_goodsSupplier').type('goodsSupplier');
  50. cy.getTestId('field_goodsInputType').type('goodsInputType');
  51. cy.getTestId('field_goodsLowReserves').clear().type('1');
  52. cy.getTestId('field_goodsHighReserves').clear().type('1');
  53. cy.getTestId('field_goodsGrade').clear().type('1');
  54. cy.getTestId('field_goosdPackingType').type('goosdPackingType');
  55. cy.getTestId('field_goodsUnit').type('goodsUnit');
  56. selectClick('select_goodsStorageLocation');
  57. selectClick('select_goodsUserDepartment');
  58. cy.getTestId('goods_modal').find('form').submit();
  59. cy.getTestId('modal_btn_group').find('.ant-btn').first()
  60. .should('have.class', 'ant-btn-loading');
  61. cy.getTestId('modal_btn_group').find('.ant-btn').last()
  62. .should('have.attr', 'disabled');
  63. cy.get('.ant-message-notice-content').should('include.text', '新增成功');
  64. cy.getTestId('goods_modal').should('not.exist');
  65. });
  66. it('修改', function() {
  67. cy.getTestId('goods_table').find('table').find('.ant-table-tbody')
  68. .children('.ant-table-row').children('td').last().children().first().click();
  69. cy.getTestId('goods_modal').should('exist').and('be.visible')
  70. .find('h3').should('have.text', '修改货品');
  71. cy.getTestId('field_goodsItemNumber').should('have.value', 'P00012');
  72. cy.getTestId('field_goodsName').should('have.value', '测试货品');
  73. cy.getTestId('field_goodsType').should('have.value', '类型1');
  74. cy.getTestId('field_goodsMinAccommodate').should('have.value', '2');
  75. cy.getTestId('field_goodsAccommodateNum').should('have.value', '1');
  76. cy.getTestId('field_goodsMaxAccommodate').should('have.value', '4');
  77. cy.getTestId('field_goodsSupplier').should('have.value', '测试1');
  78. cy.getTestId('field_goodsInputType').should('have.value', '随便');
  79. cy.getTestId('field_goodsLowReserves').should('have.value', '1');
  80. cy.getTestId('field_goodsHighReserves').should('have.value', '3');
  81. cy.getTestId('field_goodsGrade').should('have.value', '等级2');
  82. cy.getTestId('field_goosdPackingType').should('have.value', '无');
  83. cy.getTestId('field_goodsUnit').should('have.value', '公斤');
  84. selectGetValue('select_goodsStorageLocation', '1号库位');
  85. selectGetValue('select_goodsUserDepartment', '物流部门');
  86. cy.getTestId('goods_modal').find('form').submit();
  87. cy.getTestId('modal_btn_group').find('.ant-btn').first()
  88. .should('have.class', 'ant-btn-loading');
  89. cy.getTestId('modal_btn_group').find('.ant-btn').last()
  90. .should('have.attr', 'disabled');
  91. cy.get('.ant-message-notice-content').should('include.text', '修改成功');
  92. cy.getTestId('goods_modal').should('not.exist');
  93. });
  94. it('删除', function() {
  95. cy.getTestId('goods_table').find('table').find('.ant-table-tbody')
  96. .children('.ant-table-row').first().find('td').last().children().last()
  97. .trigger('click');
  98. cy.get('.ant-modal-content').should('be.visible');
  99. cy.get('.ant-modal-confirm-btns').children().last().trigger('click');
  100. cy.getTestId('goods_table').find('table').find('.ant-table-tbody')
  101. .children('.ant-table-row').first().find('td').last().children().last()
  102. .should('have.class', 'ant-btn-loading');
  103. cy.getTestId('goods_table').find('table').find('.ant-table-tbody')
  104. .children('.ant-table-row').first().find('td').last().children().first()
  105. .should('have.attr', 'disabled');
  106. cy.get('.ant-message-notice-content').should('include.text', '删除成功');
  107. });
  108. });