@isTest
private class ConsumEquipmentSetReceivedControllerTest {
  static testMethod void testCoverUp() {
        ConsumEquipmentSetReceivedController.test();
    }
    //System.LimitException: Too many SOQL queries: 101  

   
    // 造出出库指示完成数据
    // @testSetup 
    static void setupTestData(){
        Oly_TriggerHandler.bypass('ConsumApplyTriggerHandler');
       ConsumTestDataFactory factory = new ConsumTestDataFactory();
       factory.setupTestData();
       factory.selectDetails();
       factory.approve();
       factory.defaultAssign();
       factory.shippmentRequest();
    }

    static ConsumTestDataFactory factory;
    // 造出选择完明细的申请
    @testSetup 
    static void setupTestDataNew(){
        Consum_Apply__c ca = new Consum_Apply__c();
        ca.DataMigration_Flag__c = true;
        insert ca;
        Consum_Apply_Equipment_Set__c caes = new Consum_Apply_Equipment_Set__c();
        caes.Consum_Apply__c = ca.Id;
        caes.Consum_Start_Date__c = Date.today().addDays(20);
        caes.DataMigration_Flag__c = true;

        insert caes;


        FixtureDeliverySlip__c fds = new FixtureDeliverySlip__c();
        fds.Name = 'TEST';
        fds.Distributor_method__c = '空运';
        fds.DeliveryCompany__c = '顺丰';
        fds.Wh_Staff__c = Userinfo.getUserId();
        fds.DeliveryType__c = '回寄';
        insert fds;





        Address_Level__c al = new Address_Level__c();
        al.Name = '東京';
        al.Level1_Code__c = 'CN-99';
        al.Level1_Sys_No__c = '999999';
        insert al;
        // 市
        Address_Level2__c al2 = new Address_Level2__c();
        al2.Level1_Code__c = 'CN-99';
        al2.Level1_Sys_No__c = '999999';
        al2.Level1_Name__c = '東京';
        al2.Name = '渋谷区';
        al2.Level2_Code__c = 'CN-9999';
        al2.Level2_Sys_No__c = '9999999';
        al2.Address_Level__c = al.id;
        insert al2;

        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.Is_Active__c = '有効';
        hospital.Attribute_Type__c = '卫生部';
        hospital.Speciality_Type__c = '综合医院';
        hospital.Grade__c = '一级';
        hospital.OCM_Category__c = 'SLTV';
        hospital.Is_Medical__c = '医疗机构';
        hospital.State_Master__c = al.id;
        hospital.City_Master__c = al2.id;
        hospital.Town__c = '东京';
        insert hospital;

        Account account1 =new Account();
        account1.Name = 'test1医院';
        account1.RecordTypeId = '01210000000QemG';
        insert account1;
        Asset assetC1 = new Asset(Asset_Owner__c = 'Olympus');
        assetC1.RecordTypeId = System.Label.Asset_RecordType;
        assetC1.SerialNumber = 'assetC1';
        assetC1.Name = 'assetC1';
        assetC1.AccountId = account1.Id;
        assetC1.Quantity = 1;
        assetC1.Status = '有库存';
        assetC1.Manage_type__c = '个体管理';
        assetC1.Internal_asset_location__c = '北京 备品中心';
        assetC1.Loaner_accsessary__c = true;
        assetC1.Delete_Flag__c = false;
        assetC1.Freeze_sign__c = false;
        Date n=System.today();
        assetC1.Consumable_Guaranteen_end__c=n;
        insert assetC1;

        Consum_Apply_Equipment_Set_Detail__c caesd = new Consum_Apply_Equipment_Set_Detail__c();
        caesd.DataMigration_Flag__c = true;
        caesd.Consum_Apply__c = ca.Id;
        caesd.Consum_Apply_Equipment_Set__c = caes.Id;
        caesd.Consum_Start_Date__c = caes.Consum_Start_Date__c;
        caesd.Trial_User__c = '我';
        caesd.Follower_User__c = UserInfo.getUserId();
        caesd.Return_DeliverySlip__c =  fds.Id;
        caesd.Received_Confirm__c = 'OK';
        caesd.Asset_Center_Confirm__c = 'OK';
        caesd.Dao_Huo_OK_Jia__c = 1;
        caesd.Dao_Huo_NG_Jia__c = 0;
        caesd.Hui_Ji_Jia__c = 0;
        caesd.Yi_Zhi_Bao_Fei_Jia__c=null;
        caesd.Yi_Zhi_Guo_Qi_Jia__c=null;
        caesd.Shang_Jia_Jia__c=null;
        caesd.Fixture_Model_No_text__c ='dd';
        caesd.Asset__c=assetC1.Id;
        insert caesd; // 草案中

        Consum_Apply_Equipment_Set_Detail__c caesd2 = new Consum_Apply_Equipment_Set_Detail__c();
        caesd2.DataMigration_Flag__c = true;
        caesd2.Consum_Apply__c = ca.Id;
        caesd2.Consum_Apply_Equipment_Set__c = caes.Id;
        caesd2.Consum_Start_Date__c = caes.Consum_Start_Date__c;
        caesd2.Trial_User__c = '我';
        caesd2.Follower_User__c = UserInfo.getUserId();
        caesd2.Return_DeliverySlip__c = fds.Id;
        caesd2.Received_Confirm__c = 'OK';
        caesd2.Asset_Center_Confirm__c = 'OK';
        caesd2.Dao_Huo_OK_Jia__c = 1;
        caesd2.Dao_Huo_NG_Jia__c = 0;
        caesd2.Hui_Ji_Jia__c = 0;
        caesd2.Yi_Zhi_Bao_Fei_Jia__c=null;
        caesd2.Yi_Zhi_Guo_Qi_Jia__c=null;
        caesd2.Shang_Jia_Jia__c=null;
        caesd2.Asset__c=assetC1.Id;
        insert caesd2; // 草案中
    }
    static testMethod void testSave() {
        Oly_TriggerHandler.bypass('ConsumApplyTriggerHandler');
       Consum_Apply__c ca = [SELECT Id, Shipment_Slip_tmp__c FROM Consum_Apply__c LIMIT 1];
       Consum_Apply_Equipment_Set__c caes = [SELECT Id, Consum_Apply__c FROM Consum_Apply_Equipment_Set__c LIMIT 1];
       System.assertEquals(null, ca.Shipment_Slip_tmp__c);
        List<Consum_Apply_Equipment_Set_Detail__c> caeSet = [SELECT Id,Return_DeliverySlip__c,Check_lost_Item__c,Check_lost_Item_Final__c,Asset_Center_Confirm__c,Received_Confirm__c,Yi_Fa_Huo_Jia__c,
                                                                    Dao_Huo_OK_Jia__c,Dao_Huo_NG_Jia__c,Wei_Dao_Huo_Jia__c,Dao_Huo_NG_Confirm_Jia__c,Dao_Huo_NG_UnConfirm_Jia__c,Yi_Xiao_Hao_Jia__c,Hui_Ji_Jia__c,Dai_Xiao_Hao_Jia__c,
                                                                    Shippment_loaner_time2__c from Consum_Apply_Equipment_Set_Detail__c where Consum_Apply__c = :ca.Id];

       List<Consum_Apply_Equipment_Set_Detail__c> caesdList = null;
       caesdList = [SELECT Id
                         , Shippment_loaner_time__c
                         , DeliverySlip__c
                         , RAESD_Status__c
                      FROM Consum_Apply_Equipment_Set_Detail__c
                      WHERE Consum_Apply__c=:ca.Id
               ];
       System.assertEquals(null, caesdList[0].Shippment_loaner_time__c);
       System.assertEquals(null, caesdList[0].DeliverySlip__c);
    //    System.assertEquals('已出库指示', caesdList[0].RAESD_Status__c);

       PageReference ref = new PageReference('/apex/ConsumEquipmentSetReceived?Id=' + caes.Id);
       Test.setCurrentPage(ref);
       ConsumEquipmentSetReceivedController controller = new ConsumEquipmentSetReceivedController();
       CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl();
       cmp.pageController = controller;
       controller.init();
       controller.myComponentController.init();
       controller.searchOpp();
       List<Consum_Apply_Equipment_Set_Detail__c> selectedData=[SELECT Arrival_in_wh__c,Return_wh_chenk_staff__c,Arrival_wh_time__c,Inspection_result_after__c,Inspection_result_after_NG__c,
                                        EquipmentManagementCode_OldData__c,Shang_Jia_Jia__c,Yi_Zhi_Guo_Qi_Jia__c,Yi_Zhi_Bao_Fei_Jia__c,Hui_Ji_Jia__c,Barcode_F__c,id,Asset__c,Product_Serial_No_F__c,WH_location__c,Return_DeliverySlip__c,EquipmentManagementCode__c,ManagementCode__c from Consum_Apply_Equipment_Set_Detail__c limit 10];
       for(Consum_Apply_Equipment_Set_Detail__c item:selectedData){
            item.Asset__r=null;
       }
       selectedData.get(0).EquipmentManagementCode__c=null;
       controller.selectedData=selectedData;
       Test.startTest();
       controller.keywordDate='dad';
       controller.keyword='W';
        controller.getSearchNumMax();
        controller.getSelectedDataSql();
        controller.getOriginObjName();
        controller.getOriginObjColumns();
        controller.getObjName();
        controller.getColumnLeftFieldSetName();
        controller.getColumnRightFieldSetName();
        controller.getColumnFieldList();
        controller.getHiddenFieldList();
        controller.getFKColumnField();
        controller.getRecordTypeId();
        controller.getSqlWhereStr();
        controller.getOrderbyStr();
        controller.getIsNeedRunSearch();
        controller.setViewList(caeSet);
        controller.save();
        controller.cancel();
        controller.init();

       Test.stopTest();
       ca = [SELECT Id, Shipment_Slip_tmp__c FROM Consum_Apply__c LIMIT 1];

    }
    static testMethod void testSave2() {
        Oly_TriggerHandler.bypass('ConsumApplyTriggerHandler');
       Consum_Apply__c ca = [SELECT Id, Shipment_Slip_tmp__c FROM Consum_Apply__c LIMIT 1];
       Consum_Apply_Equipment_Set__c caes = [SELECT Id, Consum_Apply__c FROM Consum_Apply_Equipment_Set__c LIMIT 1];
       System.assertEquals(null, ca.Shipment_Slip_tmp__c);
        List<Consum_Apply_Equipment_Set_Detail__c> caeSet = new List<Consum_Apply_Equipment_Set_Detail__c>();
       List<Consum_Apply_Equipment_Set_Detail__c> caesdList = null;
       caesdList = [SELECT Id
                         , Shippment_loaner_time__c
                         , DeliverySlip__c
                         , RAESD_Status__c
                      FROM Consum_Apply_Equipment_Set_Detail__c
                      WHERE Consum_Apply__c=:ca.Id
               ];
       System.assertEquals(null, caesdList[0].Shippment_loaner_time__c);
       System.assertEquals(null, caesdList[0].DeliverySlip__c);
    //    System.assertEquals('已出库指示', caesdList[0].RAESD_Status__c);

       PageReference ref = new PageReference('/apex/ConsumEquipmentSetReceived?Id=' + caes.Id);
       Test.setCurrentPage(ref);
       ConsumEquipmentSetReceivedController controller = new ConsumEquipmentSetReceivedController();
       CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl();
       cmp.pageController = controller;
       controller.init();
       controller.myComponentController.init();
       controller.searchOpp();
       List<Consum_Apply_Equipment_Set_Detail__c> selectedData=[SELECT Arrival_in_wh__c,Return_wh_chenk_staff__c,Arrival_wh_time__c,Inspection_result_after__c,Inspection_result_after_NG__c,
                                        EquipmentManagementCode_OldData__c,Shang_Jia_Jia__c,Yi_Zhi_Guo_Qi_Jia__c,Yi_Zhi_Bao_Fei_Jia__c,Hui_Ji_Jia__c,Barcode_F__c,id,Asset__c,Product_Serial_No_F__c,WH_location__c,Return_DeliverySlip__c,EquipmentManagementCode__c,ManagementCode__c from Consum_Apply_Equipment_Set_Detail__c
                                         limit 100];
       for(Consum_Apply_Equipment_Set_Detail__c item:selectedData){
            item.Asset__r=null;
       }
       selectedData.get(0).EquipmentManagementCode__c='dasd';
       selectedData.get(0).Hui_Ji_Jia__c=123;
       selectedData.get(0).Yi_Zhi_Bao_Fei_Jia__c=123;
       selectedData.get(0).Yi_Zhi_Guo_Qi_Jia__c=123;
       selectedData.get(0).Shang_Jia_Jia__c=123;
       controller.selectedData=selectedData;
       Test.startTest();
       controller.keywordDate='dad';
       controller.keyword='W';
        controller.getSearchNumMax();
        controller.getSelectedDataSql();
        controller.getOriginObjName();
        controller.getOriginObjColumns();
        controller.getObjName();
        controller.getColumnLeftFieldSetName();
        controller.getColumnRightFieldSetName();
        controller.getColumnFieldList();
        controller.getHiddenFieldList();
        controller.getFKColumnField();
        controller.getRecordTypeId();
        controller.getSqlWhereStr();
        controller.getOrderbyStr();
        controller.getIsNeedRunSearch();
        controller.setViewList(caeSet);
        controller.save();
        controller.cancel();
        controller.init();

       Test.stopTest();
       ca = [SELECT Id, Shipment_Slip_tmp__c FROM Consum_Apply__c LIMIT 1];

    }

    static testMethod void testSave3() {
        Oly_TriggerHandler.bypass('ConsumApplyTriggerHandler');
       Consum_Apply__c ca = [SELECT Id, Shipment_Slip_tmp__c FROM Consum_Apply__c LIMIT 1];
       Consum_Apply_Equipment_Set__c caes = [SELECT Id, Consum_Apply__c FROM Consum_Apply_Equipment_Set__c LIMIT 1];
       System.assertEquals(null, ca.Shipment_Slip_tmp__c);

       List<Consum_Apply_Equipment_Set_Detail__c> caesdList = null;
       caesdList = [SELECT Id
                         , Shippment_loaner_time__c
                         , DeliverySlip__c
                         , RAESD_Status__c
                      FROM Consum_Apply_Equipment_Set_Detail__c
                      WHERE Consum_Apply__c=:ca.Id
               ];

       PageReference ref = new PageReference('/apex/ConsumEquipmentSetShipment?Id=' + caes.Id);
       Test.setCurrentPage(ref);
       ConsumEquipmentSetShipmentController controller = new ConsumEquipmentSetShipmentController();
       CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl();
       cmp.pageController = controller;
       controller.init();
       controller.myComponentController.init();
       controller.searchOpp();
       Test.startTest();
       controller.slip.Name = '运输单号';
       controller.slip.DeliveryType__c = '发货';
       controller.slip.Distributor_method__c = '陆运';
       controller.slip.DeliveryCompany__c = 'Fedex';
       controller.slip.Wh_Staff__c = Userinfo.getUserId();
       controller.slip.Combine_Pack__c = '123';
       controller.save();
       Test.stopTest();
       ca = [SELECT Id, Shipment_Slip_tmp__c FROM Consum_Apply__c LIMIT 1];
       System.assertNotEquals(null, ca.Shipment_Slip_tmp__c);
    }

    
    static testMethod void testSave4() {
        Oly_TriggerHandler.bypass('ConsumApplyTriggerHandler');
       Consum_Apply__c ca = [SELECT Id, Shipment_Slip_tmp__c FROM Consum_Apply__c LIMIT 1];
       Consum_Apply_Equipment_Set__c caes = [SELECT Id, Consum_Apply__c FROM Consum_Apply_Equipment_Set__c LIMIT 1];
       System.assertEquals(null, ca.Shipment_Slip_tmp__c);
        List<Consum_Apply_Equipment_Set_Detail__c> caeSet = new List<Consum_Apply_Equipment_Set_Detail__c>();
       List<Consum_Apply_Equipment_Set_Detail__c> caesdList = null;
       caesdList = [SELECT Id
                         , Shippment_loaner_time__c
                         , DeliverySlip__c
                         , RAESD_Status__c
                      FROM Consum_Apply_Equipment_Set_Detail__c
                      WHERE Consum_Apply__c=:ca.Id
               ];
       PageReference ref = new PageReference('/apex/ConsumEquipmentSetReceived?Id=' + caes.Id);
       Test.setCurrentPage(ref);
       ConsumEquipmentSetReceivedController controller = new ConsumEquipmentSetReceivedController();
       CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl();
       cmp.pageController = controller;
       controller.init();
       controller.myComponentController.init();
       controller.searchOpp();
       List<Consum_Apply_Equipment_Set_Detail__c> selectedData=[SELECT Fixture_Model_No_text__c,Fixture_Model_No__c,Consumable_Guaranteen_end_F__c,Arrival_in_wh__c,Return_wh_chenk_staff__c,Arrival_wh_time__c,Inspection_result_after__c,Inspection_result_after_NG__c,
                                        EquipmentManagementCode_OldData__c,Shang_Jia_Jia__c,Yi_Zhi_Guo_Qi_Jia__c,Yi_Zhi_Bao_Fei_Jia__c,Hui_Ji_Jia__c,Barcode_F__c,id,Asset__c,Product_Serial_No_F__c,WH_location__c,Return_DeliverySlip__c,EquipmentManagementCode__c,ManagementCode__c from Consum_Apply_Equipment_Set_Detail__c
                                         limit 100];
       for(Consum_Apply_Equipment_Set_Detail__c item:selectedData){
            item.Asset__r=null;
       }
       selectedData.get(0).EquipmentManagementCode__c='dasd';
       
       selectedData.get(0).Hui_Ji_Jia__c=0;


       selectedData.get(0).Yi_Zhi_Bao_Fei_Jia__c=null;
       selectedData.get(0).Yi_Zhi_Guo_Qi_Jia__c=null;
       selectedData.get(0).Shang_Jia_Jia__c=null;
       update selectedData;
       controller.selectedData=selectedData;
       Test.startTest();
       controller.keywordDate='dad';
       controller.keyword='W';
        controller.getSearchNumMax();
        controller.getSelectedDataSql();
        controller.getOriginObjName();
        controller.getOriginObjColumns();
        controller.getObjName();
        controller.getColumnLeftFieldSetName();
        controller.getColumnRightFieldSetName();
        controller.getColumnFieldList();
        controller.getHiddenFieldList();
        controller.getFKColumnField();
        controller.getRecordTypeId();
        controller.getSqlWhereStr();
        controller.getOrderbyStr();
        controller.getIsNeedRunSearch();
        controller.setViewList(caeSet);
        controller.viewList[0].check = true;
        controller.save();
        controller.cancel();
        controller.init();
        Boolean b=controller.saveBtnDisabled;
        Test.stopTest(); 
        ca = [SELECT Id, Shipment_Slip_tmp__c FROM Consum_Apply__c LIMIT 1];
    }
}