import {loginIntercept, menuIntercept, loginSetup, NETWORK_URL} from './utils/setup'; import {menuTrigger} from './utils/utils'; describe('部门管理', function() { beforeEach(function() { loginIntercept(); menuIntercept(); loginSetup(); menuTrigger(1, 2); }); beforeEach(function() { cy.intercept( `${NETWORK_URL}/department/getDepartment*`, function({url: reqUrl, reply}) { const url = new URL(reqUrl); const search = new URLSearchParams(url.search); if (search.has('departmentName') && search.get('departmentName').length) return reply({fixture: 'department/nameSearch'}); if (search.has('code') && search.get('code').length) return reply({fixture: 'department/codeSearch'}); const page = search.get('page'); reply({fixture: page === '1' ? 'department/list1' : 'department/list2'}); }, ); cy.intercept(`${NETWORK_URL}/department/addDepartment*`, {fixture: 'success', delay: 100}); cy.intercept(`${NETWORK_URL}/department/updateDepartment*`, {fixture: 'success', delay: 100}); cy.intercept(`${NETWORK_URL}/department/delDepartment*`, {fixture: 'success', delay: 100}); }); it('部门列表', function() { cy.getTestId('department_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('department_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_departmentCode').type('TLD0004'); cy.get('#filter_departmentName').clear(); cy.getTestId('search_btn').trigger('click'); cy.getTestId('department_table').find('table').find('.ant-table-tbody') .children('.ant-table-row').first().find('td').first() .should('include.text', 'searchCode'); cy.get('.ant-pagination').find('li[title="1"]') .should('have.class', 'ant-pagination-item-active'); cy.get('#filter_departmentName').type('name'); cy.get('#filter_departmentCode').clear(); cy.getTestId('search_btn').trigger('click'); cy.getTestId('department_table').find('table').find('.ant-table-tbody') .children('.ant-table-row').first().find('td').first() .should('include.text', 'searchName'); }); it('新增部门', function() { cy.getTestId('add_btn').trigger('click'); cy.getTestId('department_modal').should('exist').and('be.visible'); cy.getTestId('department_modal').find('h3') .should('include.text', '新增部门'); cy.getTestId('field_departmentName').type('测试部门名称'); cy.getTestId('department_modal').find('form').submit(); cy.getTestId('modal_btn_group').find('.ant-btn-loading').should('exist'); cy.get('.ant-message-notice-content').should('include.text', '新增成功'); cy.getTestId('department_modal').should('not.exist'); }); it('修改部门', function() { cy.getTestId('department_table').find('table').find('.ant-table-tbody') .children('.ant-table-row').first().find('td').last().children().first() .trigger('click'); cy.getTestId('department_modal').should('exist').and('be.visible'); cy.getTestId('department_modal').find('h3') .should('include.text', '修改部门'); cy.getTestId('field_departmentName').should('have.value', '包装部门'); cy.getTestId('department_modal').find('form').submit(); cy.getTestId('modal_btn_group').find('.ant-btn-loading').should('exist'); cy.get('.ant-message-notice-content').should('include.text', '修改成功'); cy.getTestId('department_modal').should('not.exist'); }); it('删除部门', function() { cy.getTestId('department_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('department_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('department_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', '删除成功'); }); });