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

const basicData = {
  id: '5010',
  storageLocationCode: 'D6-3-51',
  wllbCode: '3599020010010141',
  wllbClass: null,
  wllbName: '科密EP-9000 一二维码有线USB扫描枪;科密EP-9000 收银农资',
  storageLocationName: 'D6-3-51',
  size: null,
  tldId: null,
  materialType: null,
  isNotDisable: null,
  isRecommend: null,
  partType: null,
  warehouseWhere: 'e7f6bff1-e6ab-49e7-9',
  minNum: null,
  maxNum: null,
  page: 0,
  limit: 0,
  modifyUser: 'admin',
  modifyTime: '2023-03-30 09:27:44',
  code: null,
};

const TABLE_NAME = 'matter_table';

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

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

    exportIntercept('/materialClass/Export');
    successIntercept([
      '/materialClass/addMaterialClass',
      '/materialClass/updateMaterialClass',
      '/materialClass/delMaterialClass',
    ]);
  });

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

    validateTableSearch(
      TABLE_NAME,
      [
        'wllbCode',
        'wllbName',
        'storageLocationCode',
        'storageLocationName',
        'modifyUser',
      ],
      {
        toolId: 'matter_filter',
        url: '/materialClass/getMaterialClass',
      },
    );

    validateExport(TABLE_NAME);
  });

  it('operation', function () {
    const {validateAdd, validateEdit} = validatePut(
      'matter_modal',
      TABLE_NAME,
      {
        label: '库位绑定',
      },
    );

    validateAdd([
      {id: 'wllbCode', type: 'keySelect'},
      {id: 'warehouseId', type: 'select'},
      {id: 'storageLocationCode', type: 'select'},
    ]);

    validateEdit([
      {id: 'wllbCode', type: 'select', value: basicData.wllbName},
      {id: 'warehouseId', type: 'select', value: '充电设备事业部原材料库'},
      {
        id: 'storageLocationCode',
        type: 'select',
        value: basicData.storageLocationName,
      },
    ]);

    validateDelete(TABLE_NAME, '库位绑定', {title: 'page-1'});
  });
});
