高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
@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());
    }
}