@isTest public with sharing class ConsumFixtureSetSelectControllerTest { static ConsumTestDataFactory factory; @testSetup static void makeData(){ TestDataUtility.CreatePIPolicyConfiguration('Consum_Apply_Equipment_Set__c'); } static void setupTestData(){ FixtureUtil.SkipTrigger = true; StaticParameter.EscapeVMCTrigger = true; factory = new ConsumTestDataFactory(); factory.setupTestData(); } static testMethod void testSave() { setupTestData(); Consum_Apply__c ca = [SELECT Id FROM Consum_Apply__c LIMIT 1]; List caesdList = [SELECT Id FROM Consum_Apply_Equipment_Set_Detail__c WHERE Consum_Apply__c =: ca.Id]; //System.assertEquals(0, caesdList.size()); PageReference ref = new PageReference('/apex/ConsumFixtureSetSelect?pt_recid=' + ca.Id ); Test.setCurrentPage(ref); ConsumFixtureSetSelectController controller = new ConsumFixtureSetSelectController(); CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl(); cmp.pageController = controller; controller.myComponentController.init(); Test.startTest(); // 检索 controller.init(); List assList1 = [SELECT Id,Fixture_Model_No_F__c,Consumable_Guaranteen_end__c,You_Xiao_Ku_Cun__c FROM Asset]; controller.setViewList(assList1); controller.keyword = 'MH-241'; controller.searchOpp(); //System.assertEquals(1, controller.viewlist.size()); // 保存 controller.viewlist[0].check = true; Consum_Apply_Equipment_Set__c caes =(Consum_Apply_Equipment_Set__c) controller.viewlist[0].sobj; caes.Consum_Num__c = 1; ref = controller.save(); //System.assertEquals(null,ref.getParameters()); //ref.getParameters().put('reset','YES'); System.assertNotEquals(caes.Consum_Start_Date__c,null); Consum_Apply__c ca1 = [SELECT Id,demo_purpose2__c FROM Consum_Apply__c]; System.assertEquals(ca1.demo_purpose2__c,'其他'); controller.save(); List caesList = [SELECT Id, Model_No__c FROM Consum_Apply_Equipment_Set__c WHERE Consum_Apply__c =: ca.Id]; System.assertEquals(1, caesList.size()); //System.assertEquals('MH-241', caesList[0].Model_No__c); caesdList = [SELECT Id , Asset__c , Fixture_Model_No__c , Provisional_Select_Time__c , Internal_asset_location__c , Salesdepartment__c , SerialNumber__c , RAESD_Status__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].Provisional_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); Consum_Apply_Equipment_Set_Detail__c tempCase = new Consum_Apply_Equipment_Set_Detail__c(); tempCase.Id = caesdList[0].Id; tempCase.Asset__c = assList1[0].Id; update caes; controller.save(); ConsumTestDataFactory factory = new ConsumTestDataFactory(); try { factory.approve(); } catch (Exception e) { } caesdList = [SELECT Id , Asset__c , Fixture_Model_No__c , Provisional_Select_Time__c , Internal_asset_location__c , Salesdepartment__c , SerialNumber__c , RAESD_Status__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].Provisional_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); ConsumFixtureSetSelectController.testCheck(); Test.stopTest(); } static testMethod void testReset() { setupTestData(); // Consum_Apply_Equipment_Set_Detail__c caesd = TestDataUtility.CreateConsumApplyEquipmentSetDetail(1)[0]; factory = new ConsumTestDataFactory(); try { factory.selectDetails(); } catch (Exception e) { } Consum_Apply__c ca = [SELECT Id FROM Consum_Apply__c LIMIT 1]; PageReference ref = new PageReference('/apex/ConsumFixtureSetSelect'); ref.getParameters().put('pt_recid',ca.Id); ref.getParameters().put('message','保存成功'); ref.getParameters().put('level','info'); ref.getParameters().put('saveType','true'); // ref.getParameters().put('pt_recid',ca.Id); // ref.getParameters().put('raesid',caesd.Id); // ref.getParameters().put('level',ca.Id); // ref.getParameters().put('message',caesd.Id); Test.setCurrentPage(ref); ConsumFixtureSetSelectController controller = new ConsumFixtureSetSelectController(); CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl(); cmp.pageController = controller; controller.myComponentController.init(); // 检索 Test.startTest(); controller.init(); List assList1 = [SELECT Id,Fixture_Model_No_F__c,Consumable_Guaranteen_end__c,You_Xiao_Ku_Cun__c FROM Asset]; //System.assertEquals(1,assList1.size()); controller.setViewList(assList1); controller.keyword = 'MH-241'; controller.searchOpp(); //System.assertEquals(1, controller.viewlist.size()); // 适用 controller.reSetYouXiaoKuCun(); Test.stopTest(); List caesList = [SELECT Id FROM Consum_Apply_Equipment_Set__c WHERE Consum_Apply__c =: ca.Id]; System.assertEquals(0, caesList.size()); List caesdList = [SELECT Id FROM Consum_Apply_Equipment_Set_Detail__c WHERE Consum_Apply__c =: ca.Id]; System.assertEquals(0, caesdList.size()); ref.getParameters().put('level','warning'); ref.getParameters().put('message','test'); controller.showMessage(); ref.getParameters().put('level','error'); controller.showMessage(); controller.cancel(); ref.getParameters().put('reset','YES'); } }