import {loginIntercept, menuIntercept, loginSetup, NETWORK_URL} from './utils/setup'; import {menuTrigger} from './utils/utils'; describe('角色管理', function() { beforeEach(function() { loginIntercept(); menuIntercept(); loginSetup(); menuTrigger(1, 1); }); beforeEach(function() { cy.intercept(`${NETWORK_URL}/role/getRole*`, function({url: reqUrl, reply}) { const url = new URL(reqUrl); const search = new URLSearchParams(url.search); if (search.has('roleName') && search.get('roleName').length) return reply({fixture: 'role/search'}); const page = search.get('page'); reply({fixture: page === '1' ? 'role/list1' : 'role/list2'}); }); cy.intercept(`${NETWORK_URL}/role/addRole*`, {fixture: 'success', delay: 100}); cy.intercept(`${NETWORK_URL}/role/updateRole*`, {fixture: 'success', delay: 100}); cy.intercept(`${NETWORK_URL}/role/delRole*`, {fixture: 'success', delay: 100}); cy.intercept(`${NETWORK_URL}/role/updateRole*`, {fixture: 'success', delay: 100}); cy.intercept(`${NETWORK_URL}/menu/getMenu*`, {fixture: 'menu/all'}); }); it('角色列表', function() { cy.getTestId('role_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('role_table').find('table').find('.ant-table-tbody') .children('.ant-table-row').should('have.length', 2); cy.get('#filter_roleName').type('roleName'); cy.getTestId('search_btn').trigger('click'); cy.getTestId('role_table').find('table').find('.ant-table-tbody') .children('.ant-table-row').should('have.length', 1); }); it('新增操作', function() { cy.getTestId('add_btn').trigger('click'); cy.getTestId('role_modal').should('exist').and('be.visible'); cy.getTestId('role_modal').find('h3').should('include.html', '新增角色'); cy.get('#operation_roleName').type('roleName'); cy.get('#operation_roleRemarks').type('roleRemarks'); cy.getTestId('role_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('role_modal').should('not.exist'); }); it('修改操作', function() { cy.getTestId('role_table').find('table').find('.ant-table-tbody') .children('.ant-table-row').first().find('td').last().children().first() .trigger('click'); cy.getTestId('role_modal').should('exist').and('be.visible'); cy.getTestId('role_modal').find('h3').should('include.html', '修改角色'); cy.get('#operation_roleName').should('have.value', '仓库管理员'); cy.get('#operation_roleRemarks').should('have.value', 'cangk'); cy.getTestId('role_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('role_modal').should('not.exist'); }); it('删除操作', function() { cy.getTestId('role_table').find('table').find('.ant-table-tbody') .children('.ant-table-row').first().find('td').last().children().eq(1) .trigger('click'); cy.get('.ant-modal-content').should('be.visible'); cy.get('.ant-modal-confirm-btns').children().last().trigger('click'); cy.getTestId('role_table').find('table').find('.ant-table-tbody') .children('.ant-table-row').first().find('td').last().children().eq(1) .should('have.class', 'ant-btn-loading'); cy.getTestId('role_table').find('table').find('.ant-table-tbody') .children('.ant-table-row').first().find('td').last().children().first() .should('have.attr', 'disabled'); cy.getTestId('role_table').find('table').find('.ant-table-tbody') .children('.ant-table-row').first().find('td').last().children().last() .should('have.attr', 'disabled'); cy.get('.ant-message-notice-content').should('include.text', '删除成功'); }); it('设置菜单权限', function() { cy.getTestId('role_table').find('table').find('.ant-table-tbody') .children('.ant-table-row').first().find('td').last().children().last() .trigger('click'); cy.getTestId('role_tree_modal').find('h3') .should('include.html', '菜单权限'); cy.getTestId('role_tree_modal').should('exist').and('be.visible'); cy.getTestId('role_tree').find('.ant-tree-list-holder-inner') .find('.ant-tree-treenode').each(function(res, idx) { idx <= 3 ? expect(res.hasClass('ant-tree-treenode-checkbox-checked')).to.true : expect(res.hasClass('ant-tree-treenode-checkbox-checked')).to.false; }).should('have.length', 9); cy.getTestId('role_tree_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('role_tree_modal').should('not.exist'); }); });