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

const basicData = {
  id: '7',
  supplierId: 'PER00556',
  supplierName: '赵东林',
  orderId: null,
  orderNumber: null,
  materialName: '清洁纸;酒精擦纸,含酒精纯度≥99.5%,300x300mm',
  materialId: '00000000000000012033',
  measurementId: null,
  purchaseNum: '15',
  arrivalNum: '1',
  arrivalTime: '2023-04-10',
  type: '0',
  qualifiedNum: null,
  disqualificationNum: null,
  orderCode: 'CG62058902',
  companyNumber: null,
  compName: null,
  wbs: null,
  orderType: null,
  sourceType: null,
  entryNumber: null,
  moveType: null,
  page: 0,
  limit: 0,
  startTime: null,
  endTime: null,
  warehousingNum: null,
  wllbCode: '2205010010020004',
};

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

  beforeEach(function () {
    intercept('/receiveGoods/getPurchase', function ({search, reply}) {
      generateNetworkResult({
        search,
        reply,
        basicData,
        title: 'orderCode',
        skipCondition: name => name === 'type',
      });
    });

    intercept('/receiveGoods/timeoutPurchase', function ({search, reply}) {
      generateNetworkResult({
        search,
        reply,
        basicData,
        title: 'orderCode',
        skipCondition: name => name === 'type',
        replaceValue: 'timeout',
      });
    });
  });

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

    validateTableSearch(
      'purchase_order_table',
      [
        'orderCode',
        {
          id: 'type',
          type: 'select',
          value: 'timeout',
          eq: 1,
          defaultValue: '全部',
        },
      ],
      {
        toolId: 'purchase_filter',
        url: '/receiveGoods/getPurchase',
      },
    );
  });
});
