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

const basicData = {
  id: '65',
  warehouseTransferId: 'YK004',
  warehouseTransferCode: 'YK004',
  askGoodsWarehouseId: 'd7f30912-8d52-47e3-b',
  askGoodsWarehouseName: '充电设备事业部电气半成品库',
  documentTime: '2023-02-10',
  warehouseTransferType: '移库',
  entryNumber: '1',
  supplyWarehouseId: '6062e900-b3f0-4a5a-b',
  supplyWarehouseName: '充电设备事业部借件库',
  materialId: '00000000000000012034',
  materialName: '酒精纸\\',
  materialCode: '2205010010020003',
  companyName: '青岛特来电智能设备有限公司',
  companyCode: null,
  wbs: '1',
  measurementId: null,
  num: '100',
  outNum: '100',
  type: '0',
  warehouseWhere: null,
  startTime: null,
  endTime: null,
  page: 0,
  limit: 0,
  uniqueCode: null,
  accountSleeve: '8130',
  partType: null,
  askType: null,
  suppType: null,
  isRecommend: null,
};

describe('移库单明细', function () {
  beforeEach(function () {
    beforeSetup();
    intoMenu('库内管理', '移库单明细');
  });

  beforeEach(function () {
    intercept('/queryList/getWarehouseTransfer', function ({reply, search}) {
      generateNetworkResult({
        search,
        reply,
        basicData,
        title: 'warehouseTransferCode',
      });
    });

    exportIntercept('/queryList/getWarehouseTransferExcel');
    successIntercept('/warehouseTransfer/delWarehouseTransfer');
  });

  it('table', function () {
    selectAllFilters('relocation_filter', 10);
    validateTableList('relocation_table');
    validateTableSearch(
      'relocation_table',
      [
        'warehouseTransferCode',
        'materialCode',
        'materialName',
        {
          id: 'askGoodsWarehouseId',
          type: 'select',
          value: '2bdf33b8-4326-47e8-b',
        },
        {
          id: 'supplyWarehouseId',
          type: 'select',
          value: '2bdf33b8-4326-47e8-b',
        },
        {
          id: 'companyCode',
          type: 'select',
          value: '8130',
        },
        'warehouseTransferType',
        'wbs',
        'entryNumber',
        {id: 'startTime', type: 'date'},
      ],
      {
        toolId: 'relocation_filter',
        url: '/queryList/getWarehouseTransfer',
      },
    );
  });

  it('operation', function () {
    const {validateAdd} = validatePut('relocation_modal', 'relocation_table', {
      label: '移库单',
    });

    validateAdd([
      'transferNoticeOrderId',
      'transferNoticeOrderNo',
      {type: 'keySelect', id: 'materialId'},
      {type: 'field', id: 'orderCount', value: '10'},
      {type: 'keySelect', id: 'measUnitId'},
      {type: 'keySelect', id: 'requestWarehouseId'},
      {type: 'keySelect', id: 'supplyWarehouseId'},
      {type: 'keySelect', id: 'accountSleeve'},
      'entryNo',
      'WBS',
    ]);

    validateExport('relocation_table');
    validateDelete('relocation_table', '移库单', {eq: 0, title: 'page-1'});
  });
});
