@isTest
private class LexSummonsCreatControllerTest {
  @isTest
  static void testInit() {
    System.Test.startTest();
    Account accountItem1;
    Account accountItem2;
    User userTest;
    User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
    System.runAs(thisUser) {
      List<RecordType> rectCo = [
        SELECT Id
        FROM RecordType
        WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '販売店'
      ];
      if (rectCo.size() == 0) {
        return;
      }
      List<RecordType> rectHp = [
        SELECT Id
        FROM RecordType
        WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '病院'
      ];
      if (rectHp.size() == 0) {
        return;
      }
      List<RecordType> rectHos = [
        SELECT Id
        FROM RecordType
        WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '病院'
      ];
      if (rectHos.size() == 0) {
        return;
      }

      Profile prof = [
        SELECT Id
        FROM Profile
        WHERE Name = '901_经销商社区普通权限_2重验证(ET)'
      ];
      accountItem1 = new Account(
        Name = 'Testaccount001',
        RecordTypeId = rectCo[0].Id,
        AgentCode_Ext__c = '9999900'
      );
      insert accountItem1;
      accountItem2 = new Account(
        Name = 'Testaccount002',
        RecordTypeId = rectHp[0].Id,
        AgentCode_Ext__c = '9999999'
      );
      insert accountItem2;
      Contact core = new Contact(
        email = 'jplumber@salesforce.com',
        firstname = 'Joe',
        lastname = 'Plumber',
        accountId = accountItem1.Id
      );
      insert core;
      userTest = new User(
        ContactId = core.id,
        Alias = 'newUser',
        Email = 'newuser@testorg.com',
        EmailEncodingKey = 'UTF-8',
        LastName = 'TestUser',
        LanguageLocaleKey = 'zh_CN',
        LocaleSidKey = 'zh_CN',
        ProfileId = prof.Id,
        TimeZoneSidKey = 'Asia/Shanghai',
        UserName = 'testUser@testorg.com',
        UserPro_Type__c = 'ENG',
        Work_Location__c = '北京'
      );
      insert userTest;
    }
    System.runAs(userTest) {
      String userId = UserInfo.getUserId();
      User thisUserInfo = [
        SELECT
          accountid,
          UserPro_Type__c,
          ContactId,
          Contact.AccountId,
          Work_Location__c
        FROM User
        WHERE id = :userId
      ];
      String accountId = thisUserInfo.accountid;
      String agencyProType = thisUserInfo.UserPro_Type__c;
      String userWorkLocation = thisUserInfo.Work_Location__c;
      thisUserInfo.UserPro_Type__c = '';
      update thisUserInfo;
      if (String.isBlank(thisUserInfo.UserPro_Type__c)) {
        agencyProType = 'ET';
      }
      String accountName;
      Account[] accountInfo = [
        SELECT Name
        FROM account
        WHERE id = :accountId
        LIMIT 1
      ];
      if (accountInfo.size() > 0) {
        accountName = accountInfo[0].Name;
      }
      Product2 prod07 = new Product2(
        Name = 'Test07',
        ProductCode = 'Test07',
        Asset_Model_No__c = 'Test07',
        Category3__c = 'Test7',
        Category4__c = 'Test77',
        Category5__c = 'Test777',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Packing_list_manual__c = 1,
        Manual_Entry__c = false
      );
      Product2 prod08 = new Product2(
        Name = 'Test08',
        ProductCode = 'Test08',
        Asset_Model_No__c = 'Test08',
        Category3__c = 'Test8',
        Category4__c = 'Test88',
        Category5__c = 'Test888',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Packing_list_manual__c = 1,
        Manual_Entry__c = false
      );
      Product2 prod09 = new Product2(
        Name = 'Test09',
        ProductCode = 'Test09',
        Asset_Model_No__c = 'Test09',
        Category3__c = 'Test9',
        Category4__c = 'Test99',
        Category5__c = 'Test999',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Packing_list_manual__c = 1,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod07, prod08, prod09 };

      Product2__c pro1 = new Product2__c(
        Name = 'MH-155:白平衡帽',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod07.Id,
        Category3_text__c = 'test123',
        Category4_text__c = 'test123',
        Category5_text__c = 'test123'
      );
      insert pro1;
      Product2__c proH = new Product2__c(
        Name = 'MB-677:BNC电缆',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod08.Id,
        Category3_text__c = 'test123',
        Category4_text__c = 'test123',
        Category5_text__c = 'test123'
      );
      insert proH;
      //发货
      Consumable_order__c createIdSend = new Consumable_order__c();
      createIdSend.Name = 'testMing1';
      createIdSend.Order_status__c = '批准';
      createIdSend.Deliver_date__c = Date.today();
      createIdSend.RecordTypeid = System.Label.RT_ConOrder_Delivery;
      createIdSend.Order_type__c = '订单';
      createIdSend.Order_ProType__c = 'ENG';
      createIdSend.Dealer_Info__c = accountItem1.Id;
      createIdSend.Delivery_detail_count__c = 5;
      insert createIdSend;

      //发票信息
      Consumable_order__c invoiceorder = new Consumable_order__c(
        Name = 'invoice01',
        Order_type__c = '发票',
        Invoice_status__c = '已完成',
        Invoice_Date__c = Date.today(),
        RecordTypeid = System.Label.RT_ConOrder_Invoice,
        SummonsForDirction__c = '直接销售给医院',
        Order_status__c = '草案中',
        Dealer_info__c = accountItem1.Id
      );
      insert invoiceorder;

      //到货
      Consumable_order__c createIdArrived = new Consumable_order__c();
      createIdArrived.Name = 'testMing2';
      createIdArrived.Order_status__c = '批准';
      createIdArrived.Deliver_date__c = Date.today();
      createIdArrived.RecordTypeid = System.Label.RT_ConOrder_Arrive;
      createIdArrived.Order_type__c = '订单';
      createIdArrived.Order_ProType__c = 'ENG';
      createIdArrived.Arrive_Order__c = createIdSend.Id;
      createIdArrived.Dealer_Info__c = accountItem1.Id;
      createIdArrived.Delivery_detail_count__c = 5;
      insert createIdArrived;

      List<Consumable_orderdetails__c> orderdetails = new List<Consumable_orderdetails__c>();
      Consumable_orderdetails__c coc = new Consumable_orderdetails__c(
        Name = 'Too001',
        Dealer_Custom_Price__c = 999.00,
        Consumable_count__c = 3,
        Consumable_product__c = pro1.Id,
        Box_Piece__c = '盒',
        isOutPattern__c = true,
        Consumable_order__c = createIdArrived.Id,
        Unitprice_To_agency__c = 999.00,
        Delivery_List_RMB__c = 999.00,
        Shipment_Count__c = 999.00,
        RecordTypeid = System.Label.RT_ConOrderDetail1_Order
      );
      orderdetails.add(coc);
      insert orderdetails;

      Consumable_order_details2__c conOrderDetail1 = new Consumable_order_details2__c();
      conOrderDetail1.Name = 'OCM_01_001001';
      conOrderDetail1.Consumable_ZS_order__c = createIdArrived.Id;
      conOrderDetail1.Consumable_Product__c = pro1.Id;
      conOrderDetail1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
      conOrderDetail1.Bar_Code__c = '11111';
      conOrderDetail1.Arrive_date__c = Date.today().addDays(1);
      conOrderDetail1.Send_Date__c = null;
      conOrderDetail1.Used_date__c = null;
      conOrderDetail1.Return_date__c = null;
      conOrderDetail1.Consumable_order_minor__c = createIdArrived.Id;
      conOrderDetail1.Lose_Flag__c = false;
      conOrderDetail1.Box_Piece__c = '盒';
      insert conOrderDetail1;

      Integer size = Integer.valueOf(System.Label.orderdetLimitsize);
      String ESetId = null;
      String statusEdit = null;
      String arrive = null;
      LexSummonsCreatController.firstInit(ESetId);
      LexSummonsCreatController.init(ESetId, statusEdit, 1, 100, arrive);
      List<LexSummonsCreatController.ConsumableorderdetailsInfo> inList = LexSummonsCreatController.consumableorderdetailsRecords;
      List<LexSummonsCreatController.ConsumableorderdetailsInfo> inList1 = new List<LexSummonsCreatController.ConsumableorderdetailsInfo>();
      for (LexSummonsCreatController.ConsumableorderdetailsInfo ass : inList) {
        ass.orderdetails2 = conOrderDetail1;
        inList1.add(ass);
      }
      LexSummonsCreatController.ConsumableorderdetailsInfo c0 = new LexSummonsCreatController.ConsumableorderdetailsInfo();
      LexSummonsCreatController.ConsumableorderdetailsInfo c1 = new LexSummonsCreatController.ConsumableorderdetailsInfo(
        coc
      );
      c1.check = true;
      c1.oldCheck = true;
      c1.orderdetails1 = coc;
      c1.orderdetails2 = null;
      c1.Prod = coc.Consumable_Product__r;
      c1.oldConsumableCount = coc.Shipment_Count__c;
      c1.canSelect = true;
      c1.allnumber = 0;
      c1.Boxnumber = 0;
      c1.Piecenumber = 0;
      c1.BoxPiece = coc.Box_Piece__c;
      c1.hospitalSpecialOffer = false;
      c1.hosPro = false;
      List<SelectOption> boxorpiece = new List<SelectOption>();
      boxorpiece.add(new SelectOption('盒', '盒'));
      boxorpiece.add(new SelectOption('个', '个'));
      Map<String, String> boxorpieceMap = new Map<String, String>();
      boxorpieceMap.put('盒', '盒');
      boxorpieceMap.put('个', '个');
      LexSummonsCreatController.ConsumableorderdetailsInfo c2 = new LexSummonsCreatController.ConsumableorderdetailsInfo(
        proH
      );
      c2.sortBy = true;
      c2.Boxnumber = 20;
      c1.compareTo(c2);
      c1.Boxnumber = 20;
      c2.Boxnumber = 10;
      c1.compareTo(c2);
      c1.Boxnumber = 10;
      c2.Boxnumber = 20;
      c2.compareTo(c1);
      c1.Boxnumber = 20;
      c2.Boxnumber = 10;
      c2.compareTo(c1);
      LexSummonsCreatController.ConsumableorderdetailsInfoLwc c3 = new LexSummonsCreatController.ConsumableorderdetailsInfoLwc();
    }
    System.Test.stopTest();
  }
  static testMethod void testInnerClass() {
    System.Test.startTest();
    List<LexSummonsCreatController.ConsumableorderdetailsInfo> cro = new List<LexSummonsCreatController.ConsumableorderdetailsInfo>();
    cro.sort();
    System.Test.stopTest();
  }
}
