| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- import {NETWORK_URL, loginIntercept, loginSetup, menuIntercept, optionsIntercept} from './utils/setup';
- import {menuTrigger, selectClick, selectGetValue} from './utils/utils';
- describe('用户管理', function() {
- beforeEach(function() {
- loginIntercept();
- menuIntercept();
- loginSetup();
- optionsIntercept();
- menuTrigger(1, 0);
- });
- beforeEach(function() {
- cy.intercept(
- `${NETWORK_URL}/user/getAllUser*`,
- function({reply, url: reqUrl}) {
- const url = new URL(reqUrl);
- const search = new URLSearchParams(url.search);
- if (search.has('userName') && search.get('userName').length)
- return reply({fixture: 'user/nameSearch'});
- if (search.has('code') && search.get('code').length)
- return reply({fixture: 'user/codeSearch'});
- if (search.has('id') && search.get('id').length)
- return reply({fixture: 'user/userInfo'});
- const page = search.get('page');
- reply({fixture: page === '1' ? 'user/userList1' : 'user/userList2'});
- },
- );
- cy.intercept(
- `${NETWORK_URL}/user/delUser*`,
- function({reply}) {
- reply({fixture: 'success', delay: 100});
- },
- );
- cy.intercept(
- `${NETWORK_URL}/user/addUser`,
- function({reply}) {
- reply({fixture: 'success', delay: 100});
- },
- );
- cy.intercept(
- `${NETWORK_URL}/user/updateUser`,
- function({reply}) {
- reply({fixture: 'success', delay: 100});
- },
- );
- });
- it('用户列表', function() {
- cy.getTestId('user_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('user_table').find('table').find('.ant-table-tbody')
- .children('.ant-table-row').first().find('td').first()
- .should('include.text', 'TLD0004');
- });
- it('搜索', function() {
- cy.get('.ant-pagination').find('li[title="2"]').click();
- cy.get('input[name="useName"]').type('admin');
- cy.get('input[name="useCode"]').clear();
- cy.getTestId('search_btn').trigger('click');
- cy.getTestId('user_table').find('table').find('.ant-table-tbody')
- .children('.ant-table-row').first().find('td').first()
- .should('include.text', 'searchName');
- cy.get('.ant-pagination').find('li[title="1"]')
- .should('have.class', 'ant-pagination-item-active');
- cy.get('input[name="useName"]').clear();
- cy.get('input[name="useCode"]').type('1234');
- cy.getTestId('search_btn').trigger('click');
- cy.getTestId('user_table').find('table').find('.ant-table-tbody')
- .children('.ant-table-row').first().find('td').first()
- .should('include.text', 'searchCode');
- });
- it('删除操作', function() {
- cy.getTestId('user_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('user_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('user_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', '删除成功');
- });
- it('新增操作', function() {
- cy.getTestId('add_btn').trigger('click');
- cy.getTestId('user_add_modal').should('exist').and('be.visible');
- cy.getTestId('user_add_modal').find('h3').should('include.html', '新增用户');
- cy.get('input[name="userName"]').type('name');
- cy.get('input[name="userPassword"]').type('password');
- cy.get('input[name="userRealName"]').type('realname');
- cy.get('input[name="userEmail"]').type('email');
- cy.get('input[name="userLandline"]').type('userLandline');
- cy.get('input[name="userPhone"]').type('userPhone');
- selectClick('select_userDepartment', 0);
- selectClick('select_userRole', 0);
- cy.getTestId('user_add_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('user_add_modal').should('not.exist');
- });
- it('修改操作', function() {
- cy.getTestId('user_table').find('table').find('.ant-table-tbody')
- .children('.ant-table-row').first().find('td').last().children().first()
- .trigger('click');
- cy.get('input[name="userName"]').should('have.value', '123412');
- cy.get('input[name="userPassword"]').should(
- 'have.value',
- '44349BD19046F3D527D67A5D0D414B09');
- cy.get('input[name="userRealName"]').should('have.value', '测试');
- cy.get('input[name="userEmail"]').should('have.value', '123@adfa.com');
- cy.get('input[name="userLandline"]').should('have.value', '1231123');
- cy.get('input[name="userPhone"]').should('have.value', '1532');
- selectGetValue('select_userDepartment', '物流部门');
- selectGetValue('select_userRole', '物流管理员');
- cy.getTestId('user_add_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('user_add_modal').should('not.exist');
- });
- });
|