import {
  beforeSetup,
  exportIntercept,
  generateNetworkResult,
  intercept,
  intoMenu,
  successIntercept,
  validateDelete,
  validateExport,
  validatePut,
  validateTableList,
  validateTableSearch,
} from './utils';

const basicData = {
  id: '5020',
  userId: '83',
  materialId: '3599020010010141',
  scrq: '2023-04-11 14:59:10',
  userName: 'admin2',
  materialName: '科密EP-9000 一二维码有线USB扫描枪;科密EP-9000 收银农资',
  wllbCode: '3599020010010141',
  realName: '测试2',
  page: 0,
  limit: 0,
  modifyUser: 'admin',
  modifyTime: '2023-04-11 14:59:10',
};

describe('物料绑定管理', function () {
  beforeEach(function () {
    beforeSetup();
    intoMenu('基础资料', '物料绑定管理');
  });

  beforeEach(function () {
    intercept('/userMaterial/getUserMaterial', function ({search, reply}) {
      generateNetworkResult({search, reply, basicData, title: 'wllbCode'});
    });

    successIntercept([
      '/userMaterial/addUserMaterial',
      '/userMaterial/updateUserMaterial',
      '/userMaterial/delUserMaterial',
    ]);

    exportIntercept('/userMaterial/Export');
  });

  it('table', function () {
    validateTableList('material_bind_table');

    validateTableSearch(
      'material_bind_table',
      ['wllbCode', 'materialName', 'userName', 'realName', 'modifyUser'],
      {toolId: 'material_bind_filter', url: '/userMaterial/getUserMaterial'},
    );
  });

  it('operation', function () {
    validateExport('material_bind_table');

    const {validateAdd, validateEdit} = validatePut(
      'material_bind_modal',
      'material_bind_table',
      {
        label: '物料绑定信息',
      },
    );

    validateAdd([
      {id: 'userId', type: 'select'},
      {id: 'materialId', type: 'keySelect'},
    ]);

    validateEdit([
      {id: 'userId', type: 'select', value: basicData.realName},
      {id: 'materialId', type: 'select', value: basicData.materialName},
    ]);

    validateDelete('material_bind_table', '物料绑定', {title: 'page-1'});
  });
});
