import {loginIntercept, menuIntercept, loginSetup, NETWORK_URL, optionsIntercept} from './utils/setup'; import {menuTrigger, selectClick, selectGetValue} from './utils/utils'; describe('货品管理', function() { beforeEach(function() { loginIntercept(); menuIntercept(); loginSetup(); optionsIntercept(); menuTrigger(2, 1); }); beforeEach(function() { cy.intercept(`${NETWORK_URL}/goods/getGoods*`, function({url: reqUrl, reply}) { const url = new URL(reqUrl); const search = new URLSearchParams(url.search); if (search.has('itemNumber') && search.get('itemNumber').length) return reply({fixture: 'goods/search'}); const page = search.get('page'); reply({fixture: page === '1' ? 'goods/list1' : 'goods/list2'}); }); cy.intercept(`${NETWORK_URL}/goods/addGoods*`, {fixture: 'success', delay: 100}); cy.intercept(`${NETWORK_URL}/goods/delGoods*`, {fixture: 'success', delay: 100}); cy.intercept(`${NETWORK_URL}/goods/updateGoods*`, {fixture: 'success', delay: 100}); }); it('表格', function() { cy.getTestId('goods_table').find('table').find('.ant-table-tbody') .children('.ant-table-row').should('have.length', 3); cy.get('.ant-pagination').find('li[title="2"]').click(); cy.getTestId('goods_table').find('table').find('.ant-table-tbody') .children('.ant-table-row').should('have.length', 2); }); it('搜索', function() { cy.get('.ant-pagination').find('li[title="2"]').click(); cy.get('#filter_goodsCode').type('P00012'); cy.getTestId('search_btn').trigger('click'); cy.getTestId('goods_table').find('table').find('.ant-table-tbody') .children('.ant-table-row').children('td').first() .should('have.text', 'searchCode'); }); it('新增', function() { cy.getTestId('add_btn').click(); cy.getTestId('goods_modal').should('exist').and('be.visible'); cy.getTestId('goods_modal').find('h3').should('have.text', '新增货品'); cy.getTestId('field_goodsItemNumber').type('品号'); cy.getTestId('field_goodsName').type('goodsName'); cy.getTestId('field_goodsType').type('goodsType'); cy.getTestId('field_goodsMinAccommodate').clear().type('1'); cy.getTestId('field_goodsAccommodateNum').clear().type('1'); cy.getTestId('field_goodsMaxAccommodate').clear().type('1'); cy.getTestId('field_goodsSupplier').type('goodsSupplier'); cy.getTestId('field_goodsInputType').type('goodsInputType'); cy.getTestId('field_goodsLowReserves').clear().type('1'); cy.getTestId('field_goodsHighReserves').clear().type('1'); cy.getTestId('field_goodsGrade').clear().type('1'); cy.getTestId('field_goosdPackingType').type('goosdPackingType'); cy.getTestId('field_goodsUnit').type('goodsUnit'); selectClick('select_goodsStorageLocation'); selectClick('select_goodsUserDepartment'); cy.getTestId('goods_modal').find('form').submit(); cy.getTestId('modal_btn_group').find('.ant-btn').first() .should('have.class', 'ant-btn-loading'); cy.getTestId('modal_btn_group').find('.ant-btn').last() .should('have.attr', 'disabled'); cy.get('.ant-message-notice-content').should('include.text', '新增成功'); cy.getTestId('goods_modal').should('not.exist'); }); it('修改', function() { cy.getTestId('goods_table').find('table').find('.ant-table-tbody') .children('.ant-table-row').children('td').last().children().first().click(); cy.getTestId('goods_modal').should('exist').and('be.visible') .find('h3').should('have.text', '修改货品'); cy.getTestId('field_goodsItemNumber').should('have.value', 'P00012'); cy.getTestId('field_goodsName').should('have.value', '测试货品'); cy.getTestId('field_goodsType').should('have.value', '类型1'); cy.getTestId('field_goodsMinAccommodate').should('have.value', '2'); cy.getTestId('field_goodsAccommodateNum').should('have.value', '1'); cy.getTestId('field_goodsMaxAccommodate').should('have.value', '4'); cy.getTestId('field_goodsSupplier').should('have.value', '测试1'); cy.getTestId('field_goodsInputType').should('have.value', '随便'); cy.getTestId('field_goodsLowReserves').should('have.value', '1'); cy.getTestId('field_goodsHighReserves').should('have.value', '3'); cy.getTestId('field_goodsGrade').should('have.value', '等级2'); cy.getTestId('field_goosdPackingType').should('have.value', '无'); cy.getTestId('field_goodsUnit').should('have.value', '公斤'); selectGetValue('select_goodsStorageLocation', '1号库位'); selectGetValue('select_goodsUserDepartment', '物流部门'); cy.getTestId('goods_modal').find('form').submit(); cy.getTestId('modal_btn_group').find('.ant-btn').first() .should('have.class', 'ant-btn-loading'); cy.getTestId('modal_btn_group').find('.ant-btn').last() .should('have.attr', 'disabled'); cy.get('.ant-message-notice-content').should('include.text', '修改成功'); cy.getTestId('goods_modal').should('not.exist'); }); it('删除', function() { cy.getTestId('goods_table').find('table').find('.ant-table-tbody') .children('.ant-table-row').first().find('td').last().children().last() .trigger('click'); cy.get('.ant-modal-content').should('be.visible'); cy.get('.ant-modal-confirm-btns').children().last().trigger('click'); cy.getTestId('goods_table').find('table').find('.ant-table-tbody') .children('.ant-table-row').first().find('td').last().children().last() .should('have.class', 'ant-btn-loading'); cy.getTestId('goods_table').find('table').find('.ant-table-tbody') .children('.ant-table-row').first().find('td').last().children().first() .should('have.attr', 'disabled'); cy.get('.ant-message-notice-content').should('include.text', '删除成功'); }); });