高章伟
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
@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<LostBrand> LostBrands { get; set; }
        public LostReport(){
            lostReport = new Lost_cancel_report__c();
            LostBrands = new list<LostBrand> {new LostBrand(0)};
        }
        public LostReport(Lost_cancel_report__c lostReport){
            this.lostReport = lostReport;
            LostBrands = new list<LostBrand> {new LostBrand(0)};
        }
        public LostReport(Lost_cancel_report__c lostReport,  list<LostBrand> LostBrands){
            this.lostReport = lostReport;
            this.LostBrands = LostBrands;
        }
    }
 
    public class LostBrand {
        public PCLLostBrand__c lostBrand { get; set; }
        public Integer lineNo { get; set; }
        public list<PCLLostProducts> LostProducts { get; set; }
        public Integer ProductSize {get; set;}
        public LostBrand( integer lineNo ){
            lostBrand = new PCLLostBrand__c();
            this.lineNo = lineNo;
            LostProducts = new list<PCLLostProducts> {new PCLLostProducts()};
            ProductSize = 1;
            lostBrand = new PCLLostBrand__c();
        }
        public LostBrand( integer lineNo, list<PCLLostProducts> LostProducts ){
            lostBrand = new PCLLostBrand__c();
            this.lineNo = lineNo;
            this.LostProducts = LostProducts;
            ProductSize = LostProducts.size();
        }
        public LostBrand( integer lineNo, list<PCLLostProducts> 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<PCLLostProducts> plpList=new List<PCLLostProducts>();
        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<Product2> {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<RecordType> 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<RecordType> 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<Account> 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<RecordType> 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<RecordType> 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<Account> 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<Id> IdSet=new Set<Id> {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
}