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

const basicData = {
  id: '8',
  supplierId: 'EC00276',
  supplierName: '西安特来电智能充电科技有限公司',
  orderId: null,
  orderNumber: null,
  materialName: '六角螺母\\\\M16;4;彩锌;粗;GB/T41-2000\\\\',
  materialId: null,
  measurementId: null,
  purchaseNum: '60',
  arrivalNum: '60',
  arrivalTime: '2023-04-12',
  type: '0',
  qualifiedNum: '60',
  disqualificationNum: '0',
  orderCode: '6202023040301356',
  companyNumber: '8400',
  compName: '青岛特来电智能充电设备有限公司',
  wbs: '2',
  orderType: null,
  sourceType: null,
  entryNumber: null,
  moveType: null,
  page: 0,
  limit: 0,
  startTime: null,
  endTime: null,
  warehousingNum: null,
  wllbCode: '3415100010390008',
};

describe('质检单列表', function () {
  beforeEach(function () {
    beforeSetup();
    intoMenu('入库管理', '质检单列表');
  });

  beforeEach(function () {
    intercept('/receiveGoods/getReceiveGoods', function ({search, reply}) {
      generateNetworkResult({search, reply, basicData, title: 'orderCode'});
    });

    successIntercept('/receiveGoods/delReceiveGoods');
  });

  it('table', function () {
    selectAllFilters('quality_filter', 6);
    validateTableList('receive_table');

    validateTableSearch(
      'receive_table',
      [
        'orderCode',
        'materialCode',
        'materialName',
        'wbs',
        {id: 'companyNumber', type: 'select', value: '8130'},
        {id: 'supplierId', type: 'select', value: 'EC92255'},
      ],
      {toolId: 'quality_filter', url: '/receiveGoods/getReceiveGoods'},
    );
  });

  it('operation', function () {
    const {validateAdd} = validatePut('quality_modal', 'receive_table', {
      label: '质检单',
    });

    validateAdd([
      'poId',
      'poNo',
      {id: 'materialId', type: 'keySelect'},
      {id: 'measUnitId', type: 'keySelect'},
      {id: 'purchaseCount', type: 'field', value: '10'},
      {id: 'curOkCount', type: 'field', value: '10'},
      {id: 'curNgCount', type: 'field', value: '10'},
      {id: 'receiveCount', type: 'field', value: '10'},
      {id: 'supplierNo', type: 'keySelect'},
      {id: 'companyNo', type: 'keySelect'},
      {id: 'poType', type: 'select'},
      'entryNumber',
      'WBS',
    ]);

    validateDelete('receive_table', '质检单', {eq: 0, title: 'page-1'});
  });
});
