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

const basicData = {
  id: '734',
  storageLocationCode: 'D6-3-51',
  storageLocationName: 'D6-3-51',
  warehouseWhere: 'e7f6bff1-e6ab-49e7-9',
  storageLocationType: '包装类',
  materialName: '包装类',
  materialId: null,
  storageLocationCapacity: null,
  isNotDisable: '1',
  isProduct: '1',
  wareHouseName: '充电设备事业部原材料库',
  tldId: 'e7f6bff1-e6ab-49e7-9',
  createTime: '2023-04-11 14:32:59',
  modifyUser: 'admin',
  modifyTime: '2023-04-11 14:32:59',
  materialTypeId: null,
  page: 0,
  limit: 0,
};

const TABLE_NAME = 'storage_table';

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

  beforeEach(function () {
    intercept('/storage/getStorage', function ({search, reply}) {
      generateNetworkResult({
        search,
        reply,
        basicData,
        title: 'storageLocationCode',
      });
    });

    exportIntercept('/storage/export');
    successIntercept([
      '/storage/addStorage',
      '/storage/updateStorage',
      '/storage/delStorage',
    ]);
  });

  it('table', function () {
    selectAllFilters('storage_filter', 7);
    validateTableList(TABLE_NAME);

    validateTableSearch(
      TABLE_NAME,
      [
        'storageLocationName',
        'storageLocationCode',
        {id: 'warehouseWhere', type: 'select', value: '2bdf33b8-4326-47e8-b'},
        {
          id: 'storageLocationType',
          type: 'select',
          value: '危化品',
        },
        {
          id: 'isNotDisable',
          type: 'select',
          value: '0',
          eq: 1,
        },
        {
          id: 'isProduct',
          type: 'select',
          value: '0',
          eq: 1,
        },
        'modifyUser',
      ],
      {toolId: 'storage_filter', url: '/storage/getStorage'},
    );
  });

  it('operation', function () {
    validateExport(TABLE_NAME);

    const {validateAdd, validateEdit} = validatePut(
      'storage_modal',
      TABLE_NAME,
      {
        label: '库位',
      },
    );

    validateAdd([
      'storageLocationCode',
      'storageLocationName',
      {id: 'storageWarehouse', type: 'select'},
      {id: 'storageIsNotDisable', type: 'select'},
      {id: 'storageIsProduct', type: 'select'},
      {id: 'storageMaterialType', type: 'select'},
    ]);

    validateEdit([
      {
        id: 'storageLocationCode',
        value: basicData.storageLocationCode,
        type: 'field',
      },
      {
        id: 'storageLocationName',
        value: basicData.storageLocationName,
        type: 'field',
      },
      {
        id: 'storageWarehouse',
        value: basicData.wareHouseName,
        type: 'select',
      },
      {
        id: 'storageIsNotDisable',
        value: '是',
        type: 'select',
      },
      {
        id: 'storageIsProduct',
        value: '是',
        type: 'select',
      },
    ]);

    validateDelete(TABLE_NAME, '库位', {title: 'D6-3-51'});
  });
});
