@isTest
|
private class SpecialDiscountControllerTest
|
{
|
static Account keiyaku;
|
static final String RC_HANBAOITEN = '販売店';
|
static final String RC_KEIYAKU = '契約';
|
static void initAcData() {
|
Product2 prod01 = new Product2(Name='Test01');
|
prod01.ProductCode='Test01';
|
prod01.Asset_Model_No__c = 'Test01';
|
prod01.SFDA_Status__c = '有効';
|
prod01.Dealer_special_Object__c = true;
|
prod01.Family = 'GI';
|
prod01.Category2__c = '耗材';
|
prod01.Category3__c = '其他';
|
prod01.Category4__c = '其他';
|
prod01.Category5__c = '其他';
|
Product2 prod02 = new Product2(Name='Test02');
|
prod02.ProductCode='Test02';
|
prod02.Asset_Model_No__c = 'Test02';
|
prod02.SFDA_Status__c = '有効';
|
prod02.Dealer_special_Object__c = true;
|
prod02.Family = 'GI';
|
prod02.Category2__c = '本体';
|
prod02.Category3__c = '其他';
|
prod02.Category4__c = '其他';
|
prod02.Category5__c = '其他';
|
Product2 prod03 = new Product2(Name='Test03');
|
prod03.ProductCode='Test03';
|
prod03.Asset_Model_No__c = 'Test03';
|
prod03.SFDA_Status__c = '有効';
|
prod03.Dealer_special_Object__c = true;
|
prod03.Family = 'SP';
|
prod03.Category2__c = '附属品';
|
prod03.Category3__c = '其他';
|
prod03.Category4__c = '其他';
|
prod03.Category5__c = '其他';
|
insert new Product2[]{prod01,prod02,prod03};
|
Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
|
Product2__c pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id);
|
Product2__c pro3 = new Product2__c(Name='Pro003',OT_CODE_Text__c='Test003',Product2__c = prod03.Id);
|
insert new Product2__c[] {pro1, pro2,pro3};
|
//販売店
|
RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_HANBAOITEN limit 1];
|
Account sellerA = new Account(Name = '販売店');
|
sellerA.RecordTypeId = recHanbaiten.id;
|
sellerA.Delete_Flag__c = false;
|
insert sellerA;
|
//契約
|
RecordType recKeiyaku = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_KEIYAKU limit 1];
|
keiyaku = new Account(Name = '*');
|
keiyaku.RecordTypeId = recKeiyaku.id;
|
keiyaku.Agent_Ref__c = sellerA.id;
|
keiyaku.ParentId = sellerA.id;
|
keiyaku.Delete_Flag__c = false;
|
insert keiyaku;
|
keiyaku = [select Id from Account where Id = :keiyaku.Id];
|
|
Dealer_Product__c dp1 = new Dealer_Product__c();
|
//dp1.Name='A';
|
dp1.Dealer_Product2__c = pro1.Id;
|
dp1.Dealer_Contact__c = keiyaku.Id;
|
dp1.Special_Discount__c =60;
|
dp1.Special_Campaign_Price__c = 200;
|
dp1.Campaign_StartDate__c = Date.today().addDays(-1);
|
dp1.Campaign_EndDate__c = Date.today().addDays(1);
|
Dealer_Product__c dp2 = new Dealer_Product__c();
|
dp2.Dealer_Product2__c = pro2.Id;
|
dp2.Special_Discount__c =0;
|
dp2.Dealer_Contact__c = keiyaku.Id;
|
dp2.Special_Campaign_Price__c = 200;
|
dp2.Campaign_StartDate__c = Date.today().addDays(-1);
|
dp2.Campaign_EndDate__c = Date.today().addDays(1);
|
Dealer_Product__c dp3 = new Dealer_Product__c();
|
dp3.Dealer_Product2__c = pro3.Id;
|
dp3.Dealer_Contact__c = keiyaku.Id;
|
dp3.Special_Campaign_Price__c = 200;
|
dp3.Campaign_StartDate__c = Date.today().addDays(-1);
|
dp3.Campaign_EndDate__c = Date.today().addDays(1);
|
dp3.Special_Discount__c =null;
|
Dealer_Product__c dp4 = new Dealer_Product__c();
|
dp4.Dealer_Product2__c = pro3.Id;
|
dp4.Dealer_Contact__c = keiyaku.Id;
|
dp4.Special_Campaign_Price__c = 200;
|
dp4.Campaign_StartDate__c = Date.today().addDays(1);
|
dp4.Campaign_EndDate__c = Date.today().addDays(-1);
|
dp4.Special_Discount__c =0;
|
dp4 = new Dealer_Product__c();
|
dp4.Dealer_Product2__c = pro2.Id;
|
dp4.Dealer_Contact__c = keiyaku.Id;
|
dp4.Special_Campaign_Price__c = 200;
|
dp4.Campaign_StartDate__c = Date.today().addDays(1);
|
dp4.Campaign_EndDate__c = null;
|
dp4.Special_Discount__c =60;
|
dp4 = new Dealer_Product__c();
|
dp4.Dealer_Product2__c = pro1.Id;
|
dp4.Dealer_Contact__c = keiyaku.Id;
|
dp4.Special_Campaign_Price__c = 200;
|
dp4.Campaign_StartDate__c = null;
|
dp4.Campaign_EndDate__c = Date.today().addDays(-1);
|
insert new Dealer_Product__c[] {dp1, dp2,dp3,dp4};
|
|
}
|
|
@isTest
|
static void init_test()
|
{
|
initAcData();
|
|
PageReference page = new PageReference('/apex/SpecialDiscount?userid='+keiyaku.id);
|
System.Test.setCurrentPage(page);
|
SpecialDiscountController conTest = new SpecialDiscountController();
|
conTest.init();
|
//System.assertEquals(3, conTest.productInfoRecordsview[0].size());
|
conTest.keyword = 'Test01';
|
conTest.searchProduct();
|
//System.assertEquals(1, conTest.productInfoRecordsview[0].size());
|
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.Pro2DealerFlag = true;
|
conTest.searchProduct();
|
conTest.productInfoListview.sort();
|
// System.assertEquals(1, conTest.productInfoRecordsview[0].size());
|
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.productInfoListview.sort();
|
conTest.save();
|
conTest.productInfoListview[0].check = false;
|
conTest.productInfoListview[0].dealerPro.Special_discount__c=null;
|
conTest.save();
|
|
|
conTest.refreshPageSize();
|
List<Dealer_Product__c> dPList = [select Id, Special_Discount__c,Dealer_Product2__c
|
FROM Dealer_Product__c
|
WHERE Dealer_Contact__c = :keiyaku.id];
|
List<Product2__c> prodList = [select Id, Name,Name__c,
|
Asset_Model_No__c,Category1__c,
|
Category2__c,Category3__c,Category4__c,
|
Category5__c,SFDA_Status__c
|
FROM Product2__c
|
WHERE Pro2_Dealer_Object__c = true];
|
//System.assertEquals(1, dPList.size());
|
//conTest.ToPage();
|
}
|
|
@isTest
|
static void selectfill()
|
{
|
initAcData();
|
PageReference page = new PageReference('/apex/SpecialDiscount?userid='+keiyaku.id);
|
System.Test.setCurrentPage(page);
|
SpecialDiscountController conTest = new SpecialDiscountController();
|
conTest.init();
|
//System.assertEquals(3, conTest.productInfoRecordsview[0].size());
|
conTest.keyword = 'Test01';
|
conTest.searchProduct();
|
conTest.pagecount=10;
|
conTest.currentpage=1;
|
conTest.moveToNext();
|
conTest.currentpage=2;
|
conTest.moveToPrevious();
|
conTest.moveToLast();
|
//System.assertEquals(1, conTest.productInfoRecordsview[0].size());
|
conTest.category1 = 'GI';
|
conTest.category2 = '耗材';
|
conTest.category3 = '其他';
|
conTest.category4 = '其他';
|
conTest.category5 = '其他';
|
conTest.showcategory2();
|
conTest.refreshPageSize();
|
//System.assertEquals(3, conTest.category2OptionList.size());
|
}
|
}
|