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

const basicData = {
    id: '15',
    deliveryOrder: '1029',
    deliveryTime: '2020-02-09',
    deliveryType: '标准销售订单',
    deliveryCode: '810202304110038',
    subsidiaryName: '广州特来电新能源有限公司',
    deliveryCompany: '7760',
    deliveryDepartment: '供应链中心（公共）',
    customerName: '广州特来电新能源有限公司',
    commercialOpportunityCode: '2207004380',
    commercialOpportunityName: '广州花都花山小镇充电站',
    powerStationName: '广州花都花山小镇充电站',
    materialCode: '3907060140330080',
    materialName: '百兆PoE交换机;DH-S1500C-16;接入电口16个;电喵;二层管理型',
    wbs: 'T221200125-20230410-01-001',
    num: '1',
    outNum: '0',
    province: '广西壮族自治区',
    city: '柳州市',
    address: '梁延欣18275888023城中区学院路柳州奇石馆停车场',
    trackId: null,
    snCode: null,
    startTime: null,
    endTime: null,
    page: 0,
    limit: 0,
  },
  basicData2 = {
    id: '3',
    deliveryOrder: '1002',
    deliveryTime: null,
    deliveryType: null,
    deliveryCode: '810202304110038',
    subsidiaryName: null,
    deliveryCompany: '7760',
    deliveryDepartment: null,
    customerName: null,
    commercialOpportunityCode: null,
    commercialOpportunityName: null,
    powerStationName: null,
    materialCode: null,
    materialName: null,
    wbs: null,
    num: null,
    outNum: null,
    province: null,
    city: null,
    address: null,
    trackId: null,
    snCode: '123456789',
    startTime: null,
    endTime: null,
    page: 0,
    limit: 0,
  };

describe('发货追溯', function () {
  beforeEach(function () {
    beforeSetup();
    intoMenu('出库管理', '发货追溯');
  });

  beforeEach(function () {
    intercept('/traceBack/getTraceBack', function ({search, reply}) {
      generateNetworkResult({search, basicData, reply, title: 'deliveryOrder'});
    });
    intercept('/traceBack/getTraceBackSn', function ({search, reply}) {
      generateNetworkResult({
        search,
        reply,
        basicData: basicData2,
        title: 'snCode',
        skipCondition: name => name === 'trackId',
      });
    });

    exportIntercept(['/traceBack/export', '/traceBack/TraceBackSnExport']);
    successIntercept('/traceBack/delTraceBack');
  });

  it('table', function () {
    selectAllFilters('deliver_trace_search_tool', 17);
    validateTableList('deliver_trace_table');
    validateTableSearch(
      'deliver_trace_table',
      [
        'deliveryOrder',
        {id: 'startTime', type: 'date'},
        'deliveryType',
        'deliveryCode',
        'subsidiaryName',
        'deliveryCompany',
        'deliveryDepartment',
        'customerName',
        'commercialOpportunityCode',
        'powerStationName',
        'materialCode',
        'materialName',
        'wbs',
        'province',
        'city',
        'address',
        'commercialOpportunityName',
      ],
      {
        toolId: 'deliver_trace_search_tool',
        url: '/traceBack/getTraceBack',
      },
    );
    validateExport('deliver_trace_table');
    validateDelete('deliver_trace_table', '发货计划', {eq: 1, title: 'page-1'});
  });

  it('detail', function () {
    tableBtnClick('deliver_trace_table', 0);
    validateTableList('deliver_trace_sn_table');
    validateExport('deliver_trace_sn_table');
  });
});
