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

const basicData = {
  id: '26',
  noticeId: 'TGD01202303230001',
  noticeCode: 'TGD01202303230001',
  companyNumber: '8130',
  noticeTime: '2023-04-12',
  sourceType: 'G',
  moveType: '104',
  entryNumber: '1',
  productionCode: 'DD01',
  materialId: '00000000000000012034',
  wbs: '',
  measurementId: '00000000000000000001',
  num: '20',
  type: '0',
  warehousingNum: '0',
  page: 0,
  limit: 0,
  startTime: null,
  endTime: null,
  materialName: '酒精纸\\',
  companyName: '青岛特来电智能设备有限公司',
  wllbClass: null,
  materialCode: null,
  userId: null,
  askGoodsId: null,
  wllbCode: '2205010010020003',
  serial: null,
  producBatch: null,
  attribute: null,
  storageLocationCode: null,
  storageLocationName: null,
  storageCode: null,
  seq: null,
  userName: null,
  realName: null,
  scrq: null,
  uniqueCode: null,
  partType: null,
  supplierId: null,
  capacity: null,
  accountName: null,
  wmsItemId: null,
  wmsId: null,
  code: null,
  name: null,
  warehouseWhere: null,
};

describe('半成品报工单管理', function () {
  beforeEach(function () {
    beforeSetup();
    intoMenu('入库管理', '半成品报工单管理');
  });

  beforeEach(function () {
    intercept('/warehousing/getNotice', function ({search, reply}) {
      generateNetworkResult({
        search,
        reply,
        basicData,
        title: 'productionCode',
        skipCondition: name => name === 'partType',
      });
    });

    successIntercept([
      '/warehousing/addInventoryNotice',
      '/warehousing/delInventoryNotice',
    ]);
  });

  it('table', function () {
    selectAllFilters('semi_report_filter', 10);
    validateTableList('semi_report_table');

    validateTableSearch(
      'semi_report_table',
      [
        'productionCode',
        'noticeCode',
        'materialName',
        'wllbCode',
        {id: 'endTime', type: 'date'},
        'entryNumber',
        {id: 'companyNumber', type: 'select', value: '8130'},
        'moveType',
        'sourceType',
        {id: 'type', type: 'select', value: '0'},
      ],
      {toolId: 'semi_report_filter', url: '/warehousing/getNotice'},
    );
  });

  it('operation', function () {
    const {validateAdd} = validatePut(
      'semi_report_modal',
      'semi_report_table',
      {label: '报工单'},
    );

    validateAdd([
      'stockInNoticeId',
      'stockInNoticeNo',
      'prodOrderNo',
      {id: 'materialId', type: 'keySelect'},
      'notificationTypeName',
      'notificationTypeNumber',
      {id: 'measUnitId', type: 'keySelect'},
      {id: 'orderCount', type: 'field', value: '10'},
      {id: 'companyNo', type: 'keySelect'},
      'entryNumber',
      'WBS',
    ]);

    validateDelete('semi_report_table', '半成品报工单', {
      title: basicData.noticeCode,
    });

    // 入库操作
    tableBtnClick('semi_report_table', 0);

    cy.getTestId('semi_report_modal')
      .find('h3')
      .should('have.text', '选择库位信息');

    selectClick('field_warehouse');
    selectClick('field_location');

    validateModalOperation('semi_report_modal', '入库完成');
  });
});
