@isTest public class PCLLostReportControllerTest { @testSetup private static void testSetup(){ PCLLostProduct2AssetHandlerTest.setUp(); } @isTest private static void TestInit_Create(){ // create Test Opportunity opp1 = [select id from Opportunity limit 1]; PageReference page =new PageReference('/apex/PCLLostReportPage?oppId='+opp1.Id+ '&pageStatus=Create' + +'&lostType=失单'); page.setRedirect(true); System.Test.setCurrentPage(page); Lost_cancel_report__c lcr1 = new Lost_cancel_report__c(); PCLLostReportController conTest =new PCLLostReportController(new ApexPages.StandardController(lcr1)); conTest.init(); } @isTest private static void TestInit_Edit(){ EditLoad(); } // 页面的数据结构 public class LostReport { public Lost_cancel_report__c lostReport { get; set; } public list LostBrands { get; set; } public LostReport(){ lostReport = new Lost_cancel_report__c(); LostBrands = new list {new LostBrand(0)}; } public LostReport(Lost_cancel_report__c lostReport){ this.lostReport = lostReport; LostBrands = new list {new LostBrand(0)}; } public LostReport(Lost_cancel_report__c lostReport, list LostBrands){ this.lostReport = lostReport; this.LostBrands = LostBrands; } } public class LostBrand { public PCLLostBrand__c lostBrand { get; set; } public Integer lineNo { get; set; } public list LostProducts { get; set; } public Integer ProductSize {get; set;} public LostBrand( integer lineNo ){ lostBrand = new PCLLostBrand__c(); this.lineNo = lineNo; LostProducts = new list {new PCLLostProducts()}; ProductSize = 1; lostBrand = new PCLLostBrand__c(); } public LostBrand( integer lineNo, list LostProducts ){ lostBrand = new PCLLostBrand__c(); this.lineNo = lineNo; this.LostProducts = LostProducts; ProductSize = LostProducts.size(); } public LostBrand( integer lineNo, list LostProducts, PCLLostBrand__c lostBrand){ this.lostBrand = lostBrand; this.lineNo = lineNo; this.LostProducts = LostProducts; ProductSize = LostProducts.size(); } } public class PCLLostProducts { public Integer lineNo2 { get; set; } public PCLLostProduct__c LostProductss { get; set; } public PCLLostProducts() { this.lineNo2 = 0; this.LostProductss=new PCLLostProduct__c(); } public PCLLostProducts(Integer lineNo2) { this.lineNo2 = lineNo2; this.LostProductss=new PCLLostProduct__c(); } public PCLLostProducts(Integer lineNo2,PCLLostProduct__c LostProductss) { this.lineNo2 = lineNo2; this.LostProductss=LostProductss; } } @isTest private static void TestInit_Other(){ Lost_cancel_report__c lcr =[select id from Lost_cancel_report__c where LostType__c = '部分失单' limit 1]; PageReference page2 =new PageReference('/apex/PCLLostReportPage?Id='+lcr.Id+ '&pageStatus=Edit'); page2.setRedirect(true); System.Test.setCurrentPage(page2); PCLLostReportController conTest2 =new PCLLostReportController(new ApexPages.StandardController(lcr)); conTest2.init(); page2 =new PageReference('/apex/PCLLostReportPage?pageStatus=Create'); page2.setRedirect(true); System.Test.setCurrentPage(page2); conTest2 =new PCLLostReportController(new ApexPages.StandardController(lcr)); conTest2.init(); page2 =new PageReference('/apex/PCLLostReportPage?oppId='+lcr.Id+ '&pageStatus=Create'); page2.setRedirect(true); System.Test.setCurrentPage(page2); conTest2 =new PCLLostReportController(new ApexPages.StandardController(lcr)); conTest2.init(); page2 =new PageReference('/apex/PCLLostReportPage?pageStatus=Edit'); page2.setRedirect(true); System.Test.setCurrentPage(page2); conTest2 =new PCLLostReportController(new ApexPages.StandardController(lcr)); conTest2.init(); page2 =new PageReference('/apex/PCLLostReportPage'); page2.setRedirect(true); System.Test.setCurrentPage(page2); conTest2 =new PCLLostReportController(new ApexPages.StandardController(lcr)); conTest2.init(); List plpList=new List(); for (PCLLostProducts variable : plpList) { PCLLostProducts plp=new PCLLostProducts(); plp.lineNo2=0; plp.LostProductss=new PCLLostProduct__c(); plpList.add(plp); } PCLLostReportController.LostReport a =new PCLLostReportController.LostReport(); // PCLLostReportController.LostBrand ab =new PCLLostReportController.LostBrand(0,plpList); } public static PCLLostReportController EditLoad(){ // View Edit Test Lost_cancel_report__c lcr2 =[select id from Lost_cancel_report__c where LostType__c = '失单' limit 1]; PageReference page2 =new PageReference('/apex/PCLLostReportPage?Id='+lcr2.Id + '&pageStatus=Edit'); page2.setRedirect(true); System.Test.setCurrentPage(page2); PCLLostReportController conTest2 =new PCLLostReportController(new ApexPages.StandardController(lcr2)); conTest2.init(); return conTest2; } @isTest private static void TestaddBrandAndProduct(){ PCLLostReportController conTest2 = EditLoad(); conTest2.addBrand(); conTest2.addProduct(); conTest2.RemoveBrandNo = 1; conTest2.Remove(); } @isTest private static void TestCancel(){ PCLLostReportController conTest2 = EditLoad(); conTest2.cancel(); } @isTest private static void TestSave(){ PCLLostReportController conTest2 = EditLoad(); conTest2.save(); } @isTest private static void TestSearch(){ Product2 prdone = new Product2(); prdone.ProductCode_Ext__c= 'HistoryPrdone'; prdone.ProductCode= 'HistoryPrdone'; prdone.Repair_Product_Code__c = 'HistoryPrdone_RP'; prdone.Name= 'HistoryPrdone'; prdone.Manual_Entry__c= true; prdone.Category5__c = '竞争对手'; // prdone.Lost_By_Company__c = 'STORZ'; // tcm start Product2 prdtwo =prdone.clone(); prdtwo.ProductClass__c='主机'; prdtwo.ProductCategory__c='4K'; prdtwo.Name= 'HistoryPrdtwo'; prdtwo.ProductCode_Ext__c= 'HistoryPrdtwo'; prdtwo.ProductCode= 'HistoryPrdtwo'; // prdtwo.Lost_By_Company__c='STORZ'; insert new List {prdone,prdtwo}; PCLLostReportController conTest2 = EditLoad(); conTest2.LostReport.LostBrands[0].LostProducts[0].LostProductss.LostProduct__c=null; conTest2.topNum=0; conTest2.secondNum=0; conTest2.search(); conTest2.LostReport.LostBrands[0].LostProducts[0].LostProductss.LostProduct__c=prdtwo.Id; conTest2.topNum=0; conTest2.secondNum=0; conTest2.search(); // tcm end conTest2.LostReport.LostBrands[0].LostProducts[0].LostProductss.LostProduct__c=prdone.Id; conTest2.topNum=0; conTest2.secondNum=0; conTest2.search(); } @isTest private static void DataCheck(){ PCLLostReportController conTest2 = EditLoad(); conTest2.LostReport.LostReport.LostType__c = null; conTest2.LostReport.LostBrands[0].lostBrand.LostPrice__c = null; conTest2.LostReport.LostBrands[0].lostBrand.Lost_reason_main__c = null; conTest2.LostReport.LostBrands[0].LostProducts[0].LostProductss.Quantity__c =null; conTest2.LostReport.LostBrands[0].lostBrand.Agency__c = null; conTest2.DataCheck(); conTest2.LostReport.LostBrands[0].lostBrand.Lost_By_Company__c = null; conTest2.DataCheck(); conTest2.LostReport.LostBrands[0].LostProducts[0].lineNo2 = 1; conTest2.LostReport.LostBrands[0].LostProducts[0].LostProductss = new PCLLostProduct__c(Quantity__c = 0); conTest2.DataCheck(); } @isTest private static void TestEdit2(){ PCLLostReportController conTest2 = EditLoad(); conTest2.edit2(); } @isTest private static void TestSubmit(){ PCLLostReportController conTest2 = EditLoad(); conTest2.submit(); } // add tcm 20211213 start @isTest private static void TestMeth1(){ PCLLostReportController conTest2 = EditLoad(); conTest2.LostReport.LostReport.LostType__c = 'test1'; conTest2.LostReport.LostBrands[0].lostBrand.LostPrice__c = 12; conTest2.LostReport.LostBrands[0].lostBrand.Lost_reason_main__c = 'test2'; conTest2.LostReport.LostBrands[0].LostProducts[0].LostProductss.Quantity__c =11; conTest2.LostReport.LostBrands[0].lostBrand.Agency__c = null; conTest2.LostReport.LostBrands[0].lostBrand.Lost_By_Company__c = 'STORZ'; conTest2.setBrandNo = 0; conTest2.setBrand(); conTest2.LostReport.LostBrands[0].LostProducts[0].lineNo2 = 0; conTest2.LostReport.LostBrands[0].LostProducts[0].LostProductss = new PCLLostProduct__c(Quantity__c = 0); conTest2.LostReport.LostBrands[0].LostProducts[0].LostProductss.LostProductMannual__c = 'test_lost_prod'; conTest2.brandcopy(); conTest2.dataEntry(); conTest2.save(); } @isTest private static void TestMeth2(){ // recode type を取得 List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; if (rectCo.size() == 0) { throw new ControllerUtil.myException('not found 病院 recodetype'); } List rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc]; if (rectDpt.size() == 0) { throw new ControllerUtil.myException('not found 診療科 recodetype'); } // insert Account company1 = new Account(); company1.RecordTypeId = rectCo[0].Id; company1.Name = '病院テスト1'; insert company1; List dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = : company1.Id order by Department_Class_Label__c]; Account depart1 = new Account(); depart1.RecordTypeId = rectDpt[0].Id; depart1.Name = '*'; depart1.Department_Name__c = '診療科1'; depart1.ParentId= dc1s[0].Id; depart1.Department_Class__c = dc1s[0].Id; depart1.Hospital__c= company1.Id; insert depart1; PCLLostReportController conTest2 = EditLoad(); conTest2.LostReport.LostReport.LostType__c = '失单'; conTest2.LostReport.LostBrands[0].lostBrand.LostPrice__c = 12; conTest2.LostReport.LostBrands[0].lostBrand.Lost_reason_main__c = '价格'; conTest2.LostReport.LostBrands[0].LostProducts[0].LostProductss.Quantity__c =3; conTest2.LostReport.LostBrands[0].lostBrand.Agency__c = depart1.Id; conTest2.LostReport.LostBrands[0].lostBrand.Lost_By_Company__c = '其他'; conTest2.LostReport.LostBrands[0].lostBrand.Lost_By_Company_Mannual__c = 'dddddd'; conTest2.setBrandNo = 0; conTest2.setbrandmannual(); conTest2.LostReport.LostBrands[0].LostProducts[0].lineNo2 = 0; conTest2.LostReport.LostBrands[0].LostProducts[0].LostProductss = new PCLLostProduct__c(Quantity__c = 3); // conTest2.setBrand(); conTest2.dataEntry(); } //@isTest // private static void TestMeth3(){ // // recode type を取得 // List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; // if (rectCo.size() == 0) { // throw new ControllerUtil.myException('not found 病院 recodetype'); // } // List rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc]; // if (rectDpt.size() == 0) { // throw new ControllerUtil.myException('not found 診療科 recodetype'); // } // // insert // Account company1 = new Account(); // company1.RecordTypeId = rectCo[0].Id; // company1.Name = '病院テスト1'; // insert company1; // List dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = : company1.Id order by Department_Class_Label__c]; // Account depart1 = new Account(); // depart1.RecordTypeId = rectDpt[0].Id; // depart1.Name = '*'; // depart1.Department_Name__c = '診療科1'; // depart1.ParentId= dc1s[0].Id; // depart1.Department_Class__c = dc1s[0].Id; // depart1.Hospital__c= company1.Id; // insert depart1; // PCLLostReportController conTest2 = EditLoad(); // Set IdSet=new Set {depart1.Id}; // conTest2.deleteBrandIDSet=IdSet; // conTest2.LostReport.LostReport.LostType__c = '部分失单'; // conTest2.LostReport.LostBrands[0].lostBrand.LostPrice__c = 12; // conTest2.LostReport.LostBrands[0].lostBrand.Lost_reason_main__c = '价格'; // conTest2.LostReport.LostBrands[0].LostProducts[0].LostProductss.Quantity__c =0; // conTest2.LostReport.LostBrands[0].lostBrand.Agency__c = depart1.Id; // conTest2.LostReport.LostBrands[0].lostBrand.Lost_By_Company__c = 'STORZ'; // conTest2.LostReport.LostBrands[0].LostProducts[0].lineNo2 = 0; // conTest2.LostReport.LostBrands[0].LostProducts[0].LostProductss = new PCLLostProduct__c(Quantity__c = 0); // // conTest2.setBrand(); // conTest2.dataEntry(); // } // add tcm 20211213 end }