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

const basicData = {
  id: '115',
  deliveryId: 'sdf2132141',
  deliveryCode: 'eq123123',
  companyNumber: '8130',
  companyName: '青岛特来电智能设备有限公司',
  customerCode: null,
  customerName: '青岛海洲市政环境工程有限公司',
  billsTime: '2023-03-27',
  deliveryType: '1234',
  sourceType: null,
  moveType: '123123',
  entryNumber: '4123',
  materialId: '00000000000000012072',
  materialName:
    '交流路灯充电单桩包装纸箱\\\\单层瓦楞纸板（双面瓦楞纸板）\\附图纸\\\\',
  materialCode: '2205010010010023',
  wbs: '12',
  measurementId: null,
  gsDeliveryNum: '12',
  gsCancelNum: '1',
  outNum: '0',
  userId: null,
  storageCode: null,
  storageLocationCode: null,
  startTime: null,
  endTime: null,
  uniqueCode: null,
  page: 0,
  limit: 0,
  attribute: null,
  partType: null,
  amount: '0',
};

describe('销售单明细', function () {
  beforeEach(function () {
    beforeSetup();
    intoMenu('出库管理', '销售单明细');
  });

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

    successIntercept('/delivery/delDelivery');
    exportIntercept('/queryList/getDeliveryExcel');
  });

  it('table', function () {
    selectAllFilters('sell_order_filter', 11);
    validateTableList('sell_order_table');
    validateTableSearch(
      'sell_order_table',
      [
        'deliveryCode',
        'materialCode',
        'materialName',
        {id: 'customerCode', type: 'select', value: 'EC92255'},
        {id: 'companyNumber', type: 'select', value: '8130'},
        {id: 'startTime', type: 'date'},
        'wbs',
        'sourceType',
        'moveType',
        'deliveryType',
        'entryNumber',
      ],
      {
        toolId: 'sell_order_filter',
        url: '/queryList/getDelivery',
      },
    );
  });

  it('operation', function () {
    const {validateAdd} = validatePut('sell_order_modal', 'sell_order_table', {
      label: '销售单',
    });

    validateAdd([
      'deliveryOrderId',
      'deliveryOrderNo',
      {id: 'materialId', type: 'keySelect'},
      {id: 'measUnitId', type: 'select'},
      {id: 'gsDeliveryCount', type: 'field', value: '10'},
      {id: 'gsCancelDeliveryCount', type: 'field', value: '10'},
      {id: 'customerNo', type: 'keySelect'},
      {id: 'companyNumber', type: 'select'},
      {id: 'deloveryGoodsType', type: 'select'},
      'entryNumber',
      'WBS',
    ]);

    validateDelete('sell_order_table', '销售单', {title: 'page-1', eq: 0});
    validateExport('sell_order_table');
  });
});
