@isTest
private class ConsumDefaultSelectControllerTest {
    // 造出已批准的数据
    @testSetup static void setupTestData(){
        FixtureUtil.SkipTrigger = true;
        StaticParameter.EscapeVMCTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        Oly_TriggerHandler.bypass(ContactTriggerHandler.class.getName());
        Oly_TriggerHandler.bypass(AgencyHospitalHandler.class.getName());
        Oly_TriggerHandler.bypass('AssetHandler');
        Oly_TriggerHandler.bypass('AgencyHospitalHandler');
        Oly_TriggerHandler.bypass('FixtureSetHandler');
        Oly_TriggerHandler.bypass('ConsumApplyTriggerHandler');
        Oly_TriggerHandler.bypass('ConsumApplyEquipmentSetDetailHandler');
        Oly_TriggerHandler.bypass('ConsumApplyEquipmentSetHandler');
        ConsumTestDataFactory factory = new ConsumTestDataFactory();
        factory.setupTestData();
        factory.selectDetails();
        factory.approve();
    }
    /**
    @description 初始化时默认分配
    */
    static testMethod void testInit() {
        Consum_Apply__c ca = [SELECT Id FROM Consum_Apply__c LIMIT 1];
        List<Consum_Apply_Equipment_Set_Detail__c> caesdList = [SELECT RAESD_Status__c
                                                                     , Consum_Assign_Person__c
                                                                     , Select_Time__c
                                                                  FROM Consum_Apply_Equipment_Set_Detail__c
                                                                  WHERE Consum_Apply__c=:ca.Id];
        //System.assertEquals(null, caesdList[0].Consum_Assign_Person__c);
        //System.assertEquals(null, caesdList[0].Select_Time__c);
        //System.assertEquals('暂定分配',caesdList[0].RAESD_Status__c);

        PageReference ref = new PageReference('/apex/ConsumDefaultSelectController?pt_recid=' + ca.Id);
        Test.setCurrentPage(ref);
        ConsumDefaultSelectController controller = new ConsumDefaultSelectController();
        CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl();

        Test.startTest();
        cmp.pageController = controller;
        controller.myComponentController.init();
        // 检索
        controller.init();
        controller.searchOpp();
        controller.save();
        Test.stopTest();
        //System.assertEquals(1, controller.viewlist.size());

        caesdList = [SELECT Id
                          , Asset__c
                          , Fixture_Model_No__c
                          , Internal_asset_location__c
                          , Salesdepartment__c
                          , SerialNumber__c
                          , RAESD_Status__c
                          , Consum_Assign_Person__c
                          , Select_Time__c
                      FROM Consum_Apply_Equipment_Set_Detail__c
                      WHERE Consum_Apply__c =: ca.Id];

        // System.assertEquals(1, caesdList.size());
        // System.assertNotEquals(null, caesdList[0].Asset__c);
        // System.assertNotEquals(null, caesdList[0].Consum_Assign_Person__c);
        // System.assertNotEquals(null, caesdList[0].Select_Time__c);
        // System.assertEquals('上海 备品中心', caesdList[0].Internal_asset_location__c);
        // System.assertEquals('0.备品中心', caesdList[0].Salesdepartment__c);
        // System.assertEquals('sn01', caesdList[0].SerialNumber__c);
        // System.assertEquals('已分配',caesdList[0].RAESD_Status__c);
    }
    static testMethod void updaue() {
        FixtureUtil.SkipTrigger = true;
        StaticParameter.EscapeVMCTrigger = true;
        Oly_TriggerHandler.bypass('ConsumApplyTriggerHandler');
        Oly_TriggerHandler.bypass('ConsumApplyEquipmentSetDetailHandler');
        Oly_TriggerHandler.bypass('ConsumApplyEquipmentSetHandler');
       ConsumDefaultSelectController.test();//先调用这个，然后继续补充测试类
       ConsumDefaultSelectController.test2();

    }  
    /**
    @description 出库指示
    */
     /**
    static testMethod void testShipmentRequest() {
        // 数据调整到已分配
        ConsumTestDataFactory factory = new ConsumTestDataFactory();
        factory.defaultAssign();

        Consum_Apply__c ca = factory.ca;
        List<Consum_Apply_Equipment_Set_Detail__c> caesdList = null;
        caesdList = [SELECT Shipment_request__c
                          , RAESD_Status__c
                          , Shipment_request_time2__c
                        FROM Consum_Apply_Equipment_Set_Detail__c
                        WHERE Consum_Apply__c=:ca.Id];
        System.assertEquals(false, caesdList[0].Shipment_request__c);
        System.assertEquals(null, caesdList[0].Shipment_request_time2__c);
        System.assertEquals('已分配',caesdList[0].RAESD_Status__c);

        PageReference ref = new PageReference('/apex/ConsumDefaultSelectController?pt_recid=' + ca.Id);
        Test.setCurrentPage(ref);
        Test.startTest(); // 20220309 ljh  SFDC-CC73U5 132 动物实验&ET展箱 锁定已过期库存 add
        ConsumDefaultSelectController controller = new ConsumDefaultSelectController();
        CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl();
        cmp.pageController = controller;
        controller.myComponentController.init();
        controller.init();
        //controller.searchOpp();
        //System.assertEquals(1, controller.viewlist.size());

        // Test.startTest();// 20220309 ljh  SFDC-CC73U5 132 动物实验&ET展箱 锁定已过期库存 
        controller.setShipment_request();
        Test.stopTest();
       
        caesdList = [SELECT Shipment_request__c
                          , RAESD_Status__c
                          , Shipment_request_time2__c
                        FROM Consum_Apply_Equipment_Set_Detail__c
                        WHERE Consum_Apply__c=:ca.Id];
        System.assertEquals(true, caesdList[0].Shipment_request__c);
        System.assertNotEquals(null, caesdList[0].Shipment_request_time2__c);
        System.assertEquals('已出库指示',caesdList[0].RAESD_Status__c);
        
    }**/
    
    /**
    @description 取消分配
    */
     /**
    static testMethod void testAssignCancel() {
        // 数据调整到已分配
        ConsumTestDataFactory factory = new ConsumTestDataFactory();
        factory.defaultAssign();

        Consum_Apply__c ca = factory.ca;
        List<Consum_Apply_Equipment_Set_Detail__c> caesdList = null;
        caesdList = [SELECT Id
                          , Asset__c
                          , Internal_asset_location__c
                          , Salesdepartment__c
                          , SerialNumber__c
                          , RAESD_Status__c
                          , Consum_Assign_Person__c
                          , Select_Time__c
                      FROM Consum_Apply_Equipment_Set_Detail__c
                      WHERE Consum_Apply__c =: ca.Id];
        System.assertEquals(1, caesdList.size());
        System.assertNotEquals(null, caesdList[0].Asset__c);
        System.assertNotEquals(null, caesdList[0].Consum_Assign_Person__c);
        System.assertNotEquals(null, caesdList[0].Select_Time__c);
        System.assertEquals('上海 备品中心', caesdList[0].Internal_asset_location__c);
        System.assertEquals('0.备品中心', caesdList[0].Salesdepartment__c);
        System.assertEquals('sn01', caesdList[0].SerialNumber__c);
        System.assertEquals('已分配',caesdList[0].RAESD_Status__c);

        PageReference ref = new PageReference('/apex/ConsumDefaultSelectController?pt_recid=' + ca.Id);
        Test.setCurrentPage(ref);
        Test.startTest();// 20220309 ljh  SFDC-CC73U5 132 动物实验&ET展箱 锁定已过期库存 add 
        ConsumDefaultSelectController controller = new ConsumDefaultSelectController();
        CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl();
        cmp.pageController = controller;
        controller.myComponentController.init();
        
        controller.init();
        //controller.searchOpp();
        //System.assertEquals(1, controller.viewlist.size());
        // Test.startTest();// 20220309 ljh  SFDC-CC73U5 132 动物实验&ET展箱 锁定已过期库存  
        controller.copyNum();
        controller.save();
        Test.stopTest();
       
        caesdList = [SELECT Id
                          , Asset__c
                          , SerialNumber__c
                          , RAESD_Status__c
                          , Consum_Assign_Person__c
                          , Select_Time__c
                      FROM Consum_Apply_Equipment_Set_Detail__c
                      WHERE Consum_Apply__c =: ca.Id];
        System.assertEquals(1, caesdList.size());
        System.assertEquals(null, caesdList[0].Asset__c);
        System.assertEquals(null, caesdList[0].Consum_Assign_Person__c);
        System.assertEquals(null, caesdList[0].Select_Time__c);
        System.assertEquals(null, caesdList[0].SerialNumber__c);
        System.assertEquals('待分配', caesdList[0].RAESD_Status__c);
        
    }**/
    
}