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

const basicData = {
    id: '10',
    storageLocationCode: null,
    accountSleeve: null,
    storageLocationName: null,
    amount: null,
    gsAmount: null,
    plateAmount: null,
    name: null,
    total: null,
    wllbCode: null,
    materialId: null,
    scrq: '2023-04-11 17:08:43',
    plateId: null,
    supplierId: null,
    serial: null,
    attribute: null,
    uuid: '400807081608876032',
    title: '2023',
    producBatch: null,
    wllbCodes: null,
    storageLocationCodes: null,
    accountSleeves: null,
    accountName: null,
    startTime: null,
    endTime: null,
    userId: '3',
    userName: 'admin',
    page: 0,
    limit: 0,
    modifyUser: null,
    modifyTime: null,
  },
  basicData2 = {
    id: '9430',
    storageLocationCode: null,
    accountSleeve: '8130',
    storageLocationName: null,
    amount: '0',
    gsAmount: '54.00000000',
    plateAmount: null,
    name: '分体式直流充电机;240kW;六路;偏矩阵;200-1000V;EC风机;交流电表;B型',
    total: null,
    wllbCode: '3907060140030264',
    materialId: '00000000000000070387',
    scrq: null,
    plateId: null,
    supplierId: null,
    serial: null,
    attribute: null,
    uuid: '400807081608876032',
    title: null,
    producBatch: null,
    wllbCodes: null,
    storageLocationCodes: null,
    accountSleeves: null,
    accountName: '青岛特来电智能设备有限公司',
    startTime: null,
    endTime: null,
    userId: null,
    userName: null,
    page: 0,
    limit: 0,
    modifyUser: null,
    modifyTime: null,
  },
  basicData3 = {
    id: '58',
    storageLocationCode: 'B3-10-4',
    accountSleeve: '8130',
    storageLocationName: 'B3-10-4',
    amount: '6.00',
    gsAmount: null,
    plateAmount: null,
    name: '六角螺母\\\\M16;4;彩锌;粗;GB/T41-2000\\\\',
    total: '2.00',
    wllbCode: '3415100010390008',
    materialId: null,
    scrq: '2023-04-11 17:43:17',
    plateId: '10',
    supplierId: 'EC00276',
    serial: null,
    attribute: null,
    uuid: '400807081608876032',
    title: null,
    producBatch: null,
    wllbCodes: null,
    storageLocationCodes: null,
    accountSleeves: null,
    accountName: null,
    startTime: null,
    endTime: null,
    userId: null,
    userName: null,
    page: 0,
    limit: 0,
    modifyUser: null,
    modifyTime: null,
  };

describe('盘点明细', function () {
  beforeEach(function () {
    beforeSetup();
    intoMenu('库内管理', '盘点明细');
  });

  beforeEach(function () {
    intercept('/inventory/getInventoryDataList', function ({search, reply}) {
      generateNetworkResult({search, reply, basicData, title: 'title'});
    });

    intercept('/inventory/getInventoryPlates', function ({search, reply}) {
      generateNetworkResult({
        search,
        reply,
        basicData: basicData2,
        title: 'wllbCode',
        skipCondition: name => name === 'uuid',
      });
    });

    successIntercept('/inventory/addInventoryPlate');
    exportIntercept(['/inventory/export', '/inventory/exportEntering']);
  });

  it('table', function () {
    validateTableList('inventory_table');
    validateTableSearch(
      'inventory_table',
      ['inventory', 'userName', {id: 'inventoryDates', type: 'date'}],
      {
        toolId: 'inventory_filter',
        url: '/inventory/getInventoryDataList',
      },
    );
  });

  it('detail table', function () {
    tableBtnClick('inventory_table', 0);
    validateTableList('inventory_detail_table');
    validateTableSearch(
      'inventory_detail_table',
      [
        'wllbCode',
        'name',
        {type: 'select', id: 'accountSleeves', value: '8130'},
      ],
      {
        toolId: 'inventory_detail_filter',
        url: '/inventory/getInventoryPlates',
      },
    );
    validateExport('inventory_detail_table');
  });

  it('log table', function () {
    // 会影响到其他的路由
    intercept('/inventory/getInventory', function ({search, reply}) {
      generateNetworkResult({
        search,
        reply,
        basicData: basicData3,
        title: 'wllbCode',
        skipCondition: name => name === 'uuid',
      });
    });

    tableBtnClick('inventory_table', 1);
    validateTableList('inventory_log_table');
    validateTableSearch(
      'inventory_log_table',
      ['wllbCodes', 'name', 'storageLocationCodes', 'storageLocationName'],
      {
        toolId: 'inventory_log_filter',
        url: '/inventory/getInventory',
      },
    );
    validateExport('inventory_log_table');
  });
});
