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

const basicData = {
  id: '84874',
  code: 'test_3015040242',
  name: '稳压二极管',
  tldId: '00000000000000000104',
  specificationAndModel:
    '瞬态抑制二极管-双向，CAN数据端口专用-26.2V-44V-350W-8.00A-SOT-23-/-',
  unitOfMeasurement: '00000000000000000001',
  materialId: null,
  num: null,
  type: '0',
  tableName: null,
  size: '10',
  materialType: null,
  wllbClass: '危化品',
  isNotDisable: '1',
  isRecommend: '1',
  partType: '产成品',
  page: 0,
  limit: 0,
  amount: null,
  minNum: '6',
  maxNum: '12',
  modifyUser: 'admin',
  modifyTime: '2023-04-12 17:05:01',
  typeVal: null,
  companyNumber: '0',
  warehouseType: null,
  nameOrCode: null,
};

describe('物料管理', function () {
  beforeEach(function () {
    beforeSetup();
    intoMenu('基础资料', '物料管理');
  });

  beforeEach(function () {
    intercept('/dictionary/getDictionaryPage', function ({search, reply}) {
      generateNetworkResult({
        search,
        reply,
        basicData,
        title: 'code',
        skipCondition(name) {
          return name === 'type';
        },
      });
    });

    successIntercept('/materialClass/updateMaterial');
  });

  it('table', function () {
    selectAllFilters('material_filter', 7);
    validateTableSearch(
      'goods_table',
      [
        'code',
        'name',
        'materialType',
        {id: 'wllbClass', type: 'select', value: '危化品'},
        {id: 'isNotDisable', type: 'select', eq: 1, value: '0'},
        {id: 'isRecommend', type: 'select', eq: 1, value: '0'},
        'modifyUser',
      ],
      {toolId: 'material_filter', url: '/dictionary/getDictionaryPage'},
    );
  });

  it('operation', function () {
    const {validateEdit} = validatePut('goods_modal', 'goods_table', {
      label: '物料',
    });

    validateEdit([
      {id: 'goodsPartType', type: 'field', value: '产成品'},
      {id: 'goodsType', type: 'select', value: '危化品'},
      {id: 'goodsSize', type: 'field', value: '10'},
      {id: 'goodsMaxNum', type: 'field', value: '12'},
      {id: 'goodsMinNum', type: 'field', value: '6'},
      {id: 'goodsMixin', type: 'select', value: '是'},
      {id: 'goodsRecommend', type: 'select', value: '是'},
    ]);
  });
});
