@isTest private class SpecialPriceControllerTest { static Account myAccount2; //经销商 static Account contract; //经销商合同 static Product2__c pro1; //产品检索1 static Product2__c pro2; //产品检索2 static Product2__c pro3; //产品检索3 static Product2__c pro4; //产品检索4 static Product2__c pro5; //产品检索5 static Dealer_Product__c dp1; //经销商产品1 static Dealer_Product__c dp2; //经销商产品2 static void initData(){ List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店']; if (rectCo.size() == 0) { return; } myAccount2 = new Account(Name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,Product_Limit_Date__c = 'Test01|2|4,Test02|3|5'); insert myAccount2; List rectCo1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約']; if (rectCo1.size() == 0) { return; } contract = new Account(Name ='contractName',ParentId = myAccount2.id,Agent_Ref__c =myAccount2.id, Contract_Department_Class__c = 'ET',ET_SP_Dealer__c = true,Contract_Decide_Start_Date__c=Date.today().addDays(-2), Contract_Decide_End_Date__c = Date.today().addDays(2),Dealer_discount__c = 0.8,RecordTypeId = rectCo1[0].Id); insert contract; Product2 prod01 = new Product2(Name='Test01', ProductCode='Test01', Asset_Model_No__c = 'Test01', SFDA_Status__c = '有効', Product_Status__c = '正常销售', SFDA_Approbated_Status__c = '有效', Category3__c = 'CDS', Category4__c = 'OER', Category5__c = '其它', Dealer_special_Object__c = true, SFDA_Approbation_No__c = 'Test001', Packing_list_manual__c = 1, SFDA_Expiration_Date__c= Date.today(), Intra_Trade_List_RMB_1__c = 1000, Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1), Intra_Trade_List_RMB_Date2__c = Date.today().addDays(-1), Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1), ENG_DeaerProFlag__c = true ); Product2 prod02 = new Product2(Name='Test02', ProductCode='Test02', Asset_Model_No__c = 'Test02', SFDA_Status__c = '有効', Product_Status__c = '正常销售', SFDA_Approbated_Status__c = '有效', Category3__c = 'ENT', Category4__c = 'Celon', Category5__c = 'Celon', Dealer_special_Object__c = true, SFDA_Approbation_No__c = 'Test002', Packing_list_manual__c = 1, SFDA_Expiration_Date__c= Date.today(), Intra_Trade_List_RMB_1__c = 1000, Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1), Intra_Trade_List_RMB_Date2__c = Date.today().addDays(-1), Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1), ENG_DeaerProFlag__c = true ); Product2 prod03 = new Product2(Name='Test03', ProductCode='Test03', Asset_Model_No__c = 'Test03', SFDA_Status__c = '有効', Dealer_special_Object__c = true, Product_Status__c = '正常销售', SFDA_Approbated_Status__c = '有效', Category3__c = 'US', Category4__c = 'ALOKA', Category5__c = '体外超声', Intra_Trade_List_RMB_1__c = 1000, Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1), Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1), ENG_DeaerProFlag__c = true ); Product2 prod04 = new Product2(Name='Test04', ProductCode='Test04',Asset_Model_No__c = 'Test04', SFDA_Status__c = '有効', Dealer_special_Object__c = true, Product_Status__c = '正常销售', SFDA_Approbated_Status__c = '有效', Category3__c = 'OCS', Category4__c = '附属品', Category5__c = 'OCS', Intra_Trade_List_RMB_1__c = 1000, Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1), Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1), ENG_DeaerProFlag__c = true ); Product2 prod05 = new Product2(Name='Test05', ProductCode='Test05', Asset_Model_No__c = 'Test05', SFDA_Status__c = '有効', Dealer_special_Object__c = true, Product_Status__c = '正常销售', SFDA_Approbated_Status__c = '有效', Category3__c = '光源', Category4__c = 'CLV', Category5__c = 'S45', Intra_Trade_List_RMB_1__c = 1000, Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1), Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1), ENG_DeaerProFlag__c = true ); insert new Product2[] {prod01,prod02,prod03, prod04, prod05}; pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id); pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id); pro3 = new Product2__c(Name='Pro003',OT_CODE_Text__c='Test003',Product2__c = prod03.Id); pro4 = new Product2__c(Name='Pro004',OT_CODE_Text__c='Test004',Product2__c = prod04.Id); pro5 = new Product2__c(Name='Pro005',OT_CODE_Text__c='Test005',Product2__c = prod05.Id); insert new Product2__c[] {pro1,pro2,pro3,pro4, pro5}; dp1 = new Dealer_Product__c(); dp1.Dealer_Product2__c = pro1.Id; dp1.Dealer_Contact__c = contract.Id; dp1.Special_Discount__c =60; dp2 = new Dealer_Product__c(); dp2.Dealer_Product2__c = pro2.Id; dp2.Dealer_Contact__c = contract.Id; dp2.Special_Campaign_Price__c = 200; insert new Dealer_Product__c[] {dp1,dp2}; } @isTest static void init_test() { initData(); PageReference page = new PageReference('/apex/SpecialPrice?userid='+contract.id); System.Test.setCurrentPage(page); SpecialPriceController conTest = new SpecialPriceController(); conTest.init(); conTest.keyword = 'Test'; conTest.searchProduct(); // conTest.category1 = 'GI'; // conTest.category2 = '耗材'; // conTest.category3 = '其他'; // conTest.category4 = '其他'; // conTest.category5 = '其他'; conTest.SpecialDiscount='50'; conTest.geCategory(); conTest.showcategory2(); conTest.showcategory3(); conTest.showcategory4(); conTest.showcategory5(); conTest.searchProduct(); // conTest.productInfoListview.sort(); conTest.productInfoListview[0].check = true; conTest.productInfoListview[0].dealerPro.Special_discount__c=120; conTest.searchProduct(); conTest.save(); conTest.productInfoListview[0].check = true; conTest.productInfoListview[0].dealerPro.Special_discount__c=80; conTest.refreshPageSize(); conTest.save(); conTest.productInfoListview[0].check = true; conTest.productInfoListview[0].dealerPro.Special_discount__c=0; conTest.save(); conTest.productInfoListview[0].check = false; conTest.productInfoListview[0].dealerPro.Special_discount__c=null; conTest.save(); conTest.refreshPageSize(); //创建一个特价产品申请 DiscountProductApplication__c dpc = new DiscountProductApplication__c(); Id ProductTypeId = [select Id from RecordType where IsActive = true and DeveloperName = 'ProductDiscount'].Id; dpc.RecordTypeId = ProductTypeId; dpc.Dealer_Contact__c = contract.Id; dpc.ApplicationStatus__c = '草案中'; dpc.RecordTypeId = ProductTypeId; insert dpc; DiscountProductApplicationDetail__c dpadc1 = new DiscountProductApplicationDetail__c(); dpadc1.DiscountProductApplication__c = dpc.Id; dpadc1.ProductDiscount__c = 12345; dpadc1.Product2__c = pro1.Id; DiscountProductApplicationDetail__c dpadc2 = new DiscountProductApplicationDetail__c(); dpadc2.DiscountProductApplication__c = dpc.Id; dpadc2.ProductDiscount__c = 8888; dpadc2.Product2__c = pro2.Id; insert new DiscountProductApplicationDetail__c[] {dpadc1,dpadc2}; page = new PageReference('/apex/SpecialPrice?id='+dpc.Id+'&userid='+contract.id); System.Test.setCurrentPage(page); conTest = new SpecialPriceController(); conTest.init(); } @isTest static void selectfill() { initData(); PageReference page = new PageReference('/apex/SpecialPrice?userid='+contract.id); System.Test.setCurrentPage(page); SpecialPriceController conTest = new SpecialPriceController(); conTest.init(); conTest.keyword = 'Test01'; conTest.searchProduct(); conTest.pagecount=10; conTest.currentpage=1; conTest.moveToNext(); conTest.currentpage=2; conTest.moveToPrevious(); conTest.moveToLast(); conTest.category1 = 'GI'; conTest.category2 = '耗材'; conTest.category3 = '其他'; conTest.category4 = '其他'; conTest.category5 = '其他'; conTest.showcategory2(); conTest.refreshPageSize(); conTest.searchAllProduct(); } }